Skip to main content

logs-based prometheus metrics tool

Project description

Logging prometheus

Poetry plugin to set package version based on git tag.

PyPI PyPI - Python Version GitLab last commit Docs

Test coverage Downloads GitLab stars

Functionality

  • Logs handler, creating metrics
  • Setup labels

example

Quick start

install:

pip install logs-prometheus

usage:

import logging

from logging_prometheus.handlers import PrometheusHandler

logger = logging.getLogger()
logger.addHandler(PrometheusHandler('python_logging_', ['name', 'levelname', 'module']))
# or
# from logging_prometheus import setup_prometheus_handler_for_root
# setup_prometheus_handler_for_root()

logger = logging.getLogger('app')

logger.debug('debug')
logger.info('info')
logger.warning('warning')
logger.error('error')

Django setup

LOGGING = {
    ...
    "handlers": {
        "prometheus": {
            "class": "logging_prometheus.PrometheusHandler",
            "prefix": "python_logging_",
            "labels": ["name", "levelname", "module"],
        },
        ...
    },
    "loggers": {
        "django": {
            "handlers": ["prometheus", ...],
            "level": "DEBUG",
            "propagate": True,
        },
        ...
    },
    ...
}

Labels

The handler supports all values that are in the log object. more details: https://docs.python.org/3/library/logging.html#logging.LogRecord

Contribute

Issue Tracker: https://gitlab.com/rocshers/python/logs-prometheus/-/issues
Source Code: https://gitlab.com/rocshers/python/logs-prometheus

Before adding changes:

make install-dev

After changes:

make format test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logs_prometheus-1.1.2.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

logs_prometheus-1.1.2-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page