question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optionally disable Process and Platform collectors

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

13reactions
valdemarpavesicommented, Aug 17, 2019

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.


$ curl localhost:9202/metrics

# HELP request_processing_seconds Time spent processing request
# TYPE request_processing_seconds summary
request_processing_seconds_count 49.0
request_processing_seconds_sum 28.376933447027113
# TYPE request_processing_seconds_created gauge
request_processing_seconds_created 1.5660669884441628e+09
$ 

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())

6reactions
pcgeek86commented, Apr 25, 2020

Thanks for the help @valdemarpavesi. This is the code I ended up with, to clean up all the built-in metrics.

    REGISTRY.unregister(PROCESS_COLLECTOR)
    REGISTRY.unregister(PLATFORM_COLLECTOR)
    REGISTRY.unregister(REGISTRY._names_to_collectors['python_gc_objects_collected_total'])
Read more comments on GitHub >

github_iconTop Results From Across the Web

IZ64862: OPTIONALLY DISABLE JOB OBJECT AND ... - IBM
This behavior is caused by MS Windows libraries that uses such cpu to enumerate the JobObjects elements. Problem occurs in systems where a...
Read more >
Collector (Java Platform SE 8 ) - Oracle Help Center
A Collector is specified by four functions that work together to accumulate entries into a mutable result container, and optionally perform a final...
Read more >
Enable/disable the xDB and the tracker
To disable data collection, set the Xdb.Enabled setting to false . Open the web.config file and in the <appSettings> section, in ...
Read more >
Create and manage an inherited process - Azure DevOps ...
To customize any project defined on a collection for TFS 2018 or earlier, ... Add a project based on a process; Enable or...
Read more >
Managing AWS Regions - AWS General Reference
Learn how to enable and disable AWS Regions. ... An AWS Region is a collection of AWS resources in a geographic area. Each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found