-
Notifications
You must be signed in to change notification settings - Fork 801
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
Optionally disable Process and Platform collectors #414
Comments
The objects are available via public names if you wish to unregister them,
however this is not recommend.
…On Wed 22 May 2019, 20:09 Alceu Rodrigues de Freitas Junior, < ***@***.***> wrote:
Is there any way to optionally disable those collectors during usage? I
would like to be able to disable those metrics from being generated except
if they will actually be used.
A quick check on the code shows me that they are loaded from
prometheus_client/__init__.py but there aren't (that I see) many options
on that except by doing a PR with code modified.
I was able to see that trying to import resource on Microsoft Windows used
to cause <#28> an
exception, but the current version only ignores and generate constant
values for those metrics:
Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#414?email_source=notifications&email_token=ABWJG5TPAUSJZIMVP3TYYS3PWWD7BA5CNFSM4HOWXXPKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVI3OWA>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWJG5RJJ27GL64D75HDWVTPWWD7BANCNFSM4HOWXXPA>
.
|
Thanks @brian-brazil ! |
No impact, they're there for this reason. |
Can they at least be able to use a namespace? As per https://prometheus.io/docs/practices/naming/ there should be a
|
|
Sorry, I disagree. The specific python runtime for my app is what is being monitored here. The idea that an {ops-type person}* would be interested in all python runtime garbage collection across a cluster is let's say far-fetched. The metrics are labelled enough to drill down to a pod level, but not even a process/container level. Remember that it is perfectly possible to run two containers in one pod. I would say that allowing an optional namespace here gives that choice to the developer rather than enforcing your opinion on them. |
That's what it's designed for.
This is not the Prometheus way, you're looking for target labels on the Prometheus side. |
Agree with topic starter, could be nice to have something like: start_http_server(8000, enable_internal_metrics=False) Also, please advice how can I un-register those internal python metrics? My code is from prometheus_client import start_http_server, Gauge
# Create gauge
g = Gauge('current value', 'Current value')
def process_request():
g.set(api.get_total_avg_val())
time.sleep(60)
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
process_request() Thanks! |
There is probably a better way to do this but for now this will remove all metrics that are initially registered: from prometheus_client import REGISTRY, PROCESS_COLLECTOR, PLATFORM_COLLECTOR
REGISTRY.unregister(PROCESS_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
# Unlike process and platform_collector gc_collector registers itself as three different collectors that have no corresponding public named variable.
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_duration_seconds_sum'])
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_uncollectable_objects_sum'])
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_collected_objects_sum'])
# Or as throw-away line
[REGISTRY.unregister(c) for c in [PROCESS_COLLECTOR, PLATFORM_COLLECTOR, REGISTRY._names_to_collectors['python_gc_duration_seconds_sum'], REGISTRY._names_to_collectors['python_gc_uncollectable_objects_sum'], REGISTRY._names_to_collectors['python_gc_collected_objects_sum']]] |
The original issue that was reported was fixed long ago, so closing this. |
very good! unregister default metrics. there are thousands of exporter and with default metrics it could be 1000*100 it will create a big problem to time series database.
export only defined metrics: from prometheus_client import start_http_server, Summary,REGISTRY, PROCESS_COLLECTOR, PLATFORM_COLLECTOR
import random
import time
# Unregister default metrics
REGISTRY.unregister(PROCESS_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
# Unlike process and platform_collector gc_collector registers itself as three different collectors that have no corresponding public named variable.
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_duration_seconds_sum'])
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_uncollectable_objects_sum'])
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_collected_objects_sum'])
# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
"""A dummy function that takes some time."""
time.sleep(t)
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(9202)
# Generate some requests.
while True:
process_request(random.random()) |
Thanks for the help @valdemarpavesi. This is the code I ended up with, to clean up all the built-in metrics.
|
for name in list(REGISTRY._names_to_collectors.values()):
with suppress(KeyError):
REGISTRY.unregister(name) I ended up with this, which should also work even if the default generators ever change. |
I would prefer this similar approach instead:
|
@lhw , Thank you so much for the hack, Using the |
For the |
@csmarchbanks , I also saw your open PR #774 to fix the same issue. Eagerly waiting for your PR to get merged. |
Tested this on python 3.12 Updated config REGISTRY.unregister(PROCESS_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_objects_collected_total']) |
Is there any way to optionally disable those collectors during usage? I would like to be able to disable those metrics from being generated except if they will actually be used.
A quick check on the code shows me that they are loaded from
prometheus_client/__init__.py
but there aren't (that I see) many options on that except by doing a PR with code modified.I was able to see that trying to
import resource
on Microsoft Windows used to cause an exception, but the current version only ignores and generate constant values for those metrics:Thanks!
The text was updated successfully, but these errors were encountered: