Application logging and instrumentation
Project description
kuhl-haus-metrics
Overview
kuhl-haus-metrics is a Python library for application logging and instrumentation. It provides tools and utilities to help developers track application performance, collect metrics, and monitor system behavior in real-time.
Features
- Comprehensive application logging
- Performance metrics collection
- Instrumentation for monitoring application behavior
- Extensible architecture for custom metrics
Installation
You can install kuhl-haus-metrics via pip:
pip install kuhl-haus-metrics
Quick Start
Here's a simple example to get you started:
import ssl
import time
from datetime import datetime
from logging import Logger
import OpenSSL
from kuhl_haus.metrics.data.metrics import Metrics
from kuhl_haus.metrics.factories.logs import get_logger
from kuhl_haus.metrics.clients.carbon_poster import CarbonPoster
def get_tls_cert_expiration_days(hostname: str, port: int) -> int:
raw_cert = ssl.get_server_certificate((hostname, port))
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, raw_cert.encode())
expiration_time = time.mktime(datetime.strptime(cert.get_notAfter().decode(), '%Y%m%d%H%M%S%fZ').timetuple())
current_time = time.mktime(datetime.now().timetuple())
return int(expiration_time - current_time) // 60 // 60 // 24
logger: Logger = get_logger(log_level='INFO')
carbon_poster: CarbonPoster = CarbonPoster(server_ip="127.0.0.1", pickle_port=2004)
# hostname and port to check
host_name = "foo.com"
host_port = 443
# Initialize metrics
metrics: Metrics = Metrics(
mnemonic="mnemonic",
namespace="namespace",
hostname=host_name,
counters={
'exceptions': 0,
'requests': 0,
'responses': 0,
},
attributes={
"hostport": host_port
}
)
try:
metrics.set_counter('requests', 1)
days_until_expiration = get_tls_cert_expiration_days(host_name, host_port)
metrics.set_counter('responses', 1)
metrics.attributes["days_until_expiration"] = days_until_expiration
metrics.attributes["expires_today"] = days_until_expiration <= 1
metrics.attributes["is_valid"] = days_until_expiration > 0
except Exception as e:
metrics.set_counter('exceptions', 1)
metrics.attributes['exception'] = repr(e)
logger.exception(msg=f"unhandled exception processing {host_name}:{host_port}", exc_info=e)
carbon_poster.post_metrics(metrics=metrics.carbon)
Documentation
For detailed documentation and API reference, please visit our documentation site.
Requirements
- Python 3.12+
Development
Setting Up Development Environment
-
Clone the repository:
git clone https://github.com/kuhl-haus/kuhl-haus-metrics.git cd kuhl-haus-metrics
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install development dependencies:
pip install -r requirements.txt pdm install
Running Tests
Tests are managed with pytest:
pdm run pytest tests -v
For test coverage:
pdm run pytest --cov=kuhl_haus.metrics --cov-report=html --cov-report=xml tests -v
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the project's coding standards.
License
This project is licensed under the terms of the license file included in the repository. See LICENSE.txt for details.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Acknowledgements
- This project was generated with PyScaffold 4.6
Built with ❤️ by the kuhl-haus team.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kuhl_haus_metrics-0.2.18.tar.gz.
File metadata
- Download URL: kuhl_haus_metrics-0.2.18.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee767db5580b912a62db1a6c8d350d81a15efd545c9ffba63ec2af1299b6aa44
|
|
| MD5 |
c8fddf9f5375711c04395c78f8c85dfe
|
|
| BLAKE2b-256 |
10eb784c6f2d6db684427153790bbb1629da7bad24f09d7ad3995bc86d3cbd67
|
Provenance
The following attestation bundles were made for kuhl_haus_metrics-0.2.18.tar.gz:
Publisher:
publish-to-pypi.yml on kuhl-haus/kuhl-haus-metrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kuhl_haus_metrics-0.2.18.tar.gz -
Subject digest:
ee767db5580b912a62db1a6c8d350d81a15efd545c9ffba63ec2af1299b6aa44 - Sigstore transparency entry: 208750540
- Sigstore integration time:
-
Permalink:
kuhl-haus/kuhl-haus-metrics@fd78c68ee946483e55e17c196c95c05e969a100d -
Branch / Tag:
refs/tags/v0.2.18 - Owner: https://github.com/kuhl-haus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@fd78c68ee946483e55e17c196c95c05e969a100d -
Trigger Event:
push
-
Statement type:
File details
Details for the file kuhl_haus_metrics-0.2.18-py3-none-any.whl.
File metadata
- Download URL: kuhl_haus_metrics-0.2.18-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd6a65b3a0fea698f1cd7407121c4f4780bd7e689090fdff7563adb75c203b34
|
|
| MD5 |
8b0d8a824a60dcb28cbdfc62cbabd6ff
|
|
| BLAKE2b-256 |
bb33918dba0d987887462efed93b78a3ffc103fa76f7d56270832884004a670a
|
Provenance
The following attestation bundles were made for kuhl_haus_metrics-0.2.18-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on kuhl-haus/kuhl-haus-metrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kuhl_haus_metrics-0.2.18-py3-none-any.whl -
Subject digest:
dd6a65b3a0fea698f1cd7407121c4f4780bd7e689090fdff7563adb75c203b34 - Sigstore transparency entry: 208750543
- Sigstore integration time:
-
Permalink:
kuhl-haus/kuhl-haus-metrics@fd78c68ee946483e55e17c196c95c05e969a100d -
Branch / Tag:
refs/tags/v0.2.18 - Owner: https://github.com/kuhl-haus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@fd78c68ee946483e55e17c196c95c05e969a100d -
Trigger Event:
push
-
Statement type: