Skip to main content

kuhl-haus-metrics

License PyPI Downloads Build Status CodeQL codecov GitHub issues GitHub pull requests

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

  1. Clone the repository:

    git clone https://github.com/kuhl-haus/kuhl-haus-metrics.git
    cd kuhl-haus-metrics
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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


Built with ❤️ by the kuhl-haus team.

Metadata

Release files for kuhl-haus-metrics 0.2.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kuhl-haus-metrics 0.2.23
File Size Uploaded Provenance Actions
kuhl_haus_metrics-0.2.23.tar.gz 23.8 kB With provenance Details for kuhl_haus_metrics-0.2.23.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kuhl-haus-metrics 0.2.23
File Interpreter ABI Platform Actions
kuhl_haus_metrics-0.2.23-py3-none-any.whl Python 3 none any Details for kuhl_haus_metrics-0.2.23-py3-none-any.whl

Total release size: 40.1 kB

Release files / kuhl_haus_metrics-0.2.23.tar.gz

Download URL kuhl_haus_metrics-0.2.23.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7f437bbc24ed0ef091abbdcfd361efe06176df154870197f6701734baad322b9
BLAKE2b-256 checksum
How to use checksums
e189946b04a6974559368d3ab9f265919c5af8281c41ea6c2f21192c9c4d8faf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 5, 2026.

Transparency log

Release files / kuhl_haus_metrics-0.2.23-py3-none-any.whl

Download URL kuhl_haus_metrics-0.2.23-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0979ba62d8b2e832631c3cd44754b7c9f2ede69721d88fe3215eef70bc4f4a
BLAKE2b-256 checksum
How to use checksums
e3b7d8d5510d74594ba48bcb098e4ee1712a23975c955bec0d1137ca1fb2cda7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 5, 2026.

Transparency log

Security for kuhl-haus-metrics 0.2.23

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kuhl_haus_metrics-0.2.23.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page