Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMetrics support for textfile collector #957

Open
petarmaric opened this issue Sep 18, 2023 · 6 comments
Open

OpenMetrics support for textfile collector #957

petarmaric opened this issue Sep 18, 2023 · 6 comments

Comments

@petarmaric
Copy link

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?

@csmarchbanks
Copy link
Member

Hello, I am not opposed to adding a function to prometheus_client.openmetrics for textfile if it doesn't add confusion, but I am curious what your use case is? As far as I know the node exporter textfile collector only supports the Prometheus format, but I could have missed an update.

@petarmaric
Copy link
Author

petarmaric commented Sep 20, 2023

Thank you for the interest :) Honestly, can't give too many specifics right now, as I'm waiting for approval from the company I work for to actually Open Source the tool I'm building.

What I can say right now is that it's a console app and Python API for converting reports outputted by "a tool" into the OpenMetrics text format. Such metrics are then meant to be pushed into Grafana (data source), via VictoriaMetrics API.

@petarmaric
Copy link
Author

Once it's Open Sourced I'll be sure to provide a link here, so you can see the use-case more clearly - there are a few reasons I've opted in for OpenMetrics in lieu of Prometheus text format...

@petarmaric
Copy link
Author

As promised, https://pypi.org/project/locust_csv2openmetrics/ has (finally) hit 1.0.0 today.

We use this tool to convert locust’s load test CSV formatted reports into the OpenMetrics text format, pushing the obtained metrics into Grafana (data source), via VictoriaMetrics API.

@petarmaric
Copy link
Author

Because these load tests are run non-continuously and at irregular time intervals we need to push their metrics into Grafana (data source), as opposed to the much more common way of Prometheus pulling data from a load-tests-like service to collect the metrics. I hope this clarifies our use case.

@csmarchbanks
Copy link
Member

That use case makes sense to me, it is also the format you need to backfill data into Prometheus using promtool. That said, it looks like what you did is the correct thing to do, call generate_latest and save to a file. The reason write_to_textfile exists is that atomic writes are necessary in order to use the textfile exporter, but backfilling data does not require an atomic write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants