Skip to content

OpenMetrics support for textfile collector #957

Open
@petarmaric

Description

@petarmaric

Currently prometheus_client.exposition.write_to_textfile doesn't support the OpenMetrics text format, which I'm addressing with this (private) hack:

from prometheus_client.openmetrics.exposition import (
    generate_latest as generate_latest_openmetrics,
)
from prometheus_client.registry import CollectorRegistry

def write_openmetrics_to_textfile(path: str, registry: CollectorRegistry) -> None:
    """
    Fork of `prometheus_client.exposition.write_to_textfile`, as the project
    didn't provide an OpenMetrics variant of this helper function.
    """
    with open(path, "wb") as fp:
        fp.write(generate_latest_openmetrics(registry))

Would your project be interested in a non-hacky (as is the case above) OpenMetrics support for textfile collector?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions