Instrumentation with Prometheus in Practice
70%
Additional Custom Metric Types
Some Prometheus client libraries may not fully support all metric types but others may provide additional custom metric types or extensions. For example, the Python library provides an Info type for exposing static information about the application and Enum for tracking states or statuses.
Here is an example of how to use both:
cat <<EOF > /prometheus-python-example/custom_metrics.py
from flask import Flask, Response
import requests
from prometheus_client import (
Info,
Enum,
generate_latest,
CONTENT_TYPE_LATEST
)
# Create a Flask application
app = Flask(__name__)
# Define an Info metric to expose static information
info = Info(
'application_info',
'Application information',
# ['version', 'author']
)
# Set the static information
info.info(
{
'version': '1.0',
'author': 'John Doe'
}
)
# Define an Enum metric to track states or statuses
state = Enum(
'application_state',
'Application state',
states=['loading', 'missing', 'running', 'stopped']
)
# Set the state to 'running'
state.state(Observability with Prometheus and Grafana
A Complete Hands-On Guide to Operational Clarity in Cloud-Native SystemsEnroll now to unlock all content and receive all future updates for free.
