Python prometheus_client.Summary() Examples

The following are 7 code examples of prometheus_client.Summary(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module prometheus_client , or try the search function .
Example #1
Source File: monitor.py    From CrawlerMonitor with MIT License 7 votes vote down vote up
def create_metric(self):
        # record app conf
        self.conf_info = Info('celery_conf_info','APP_CONF')
        self.conf_info_c = CollectorRegistry()

        # monitor worker info
        self.workers_info = Info('celery_workers_info', 'WORKER_INFO')
        self.workers_info_c = CollectorRegistry()

        # monitor worker info real-time
        self.workers_state = Gauge('celery_workers_state', 'WORKER_STATE', ['worker'])
        self.workers_state_c = CollectorRegistry()
        self.workers_processed = Gauge('celery_processed_tasks_total', 'WORKER_TASKS_PROCESSED', ['worker'])
        self.workers_processed_c = CollectorRegistry()
        self.workers_active = Gauge('celery_active_tasks_total', 'WORKER_TASKS_ACTIVE', ['worker'])
        self.workers_active_c = CollectorRegistry()

        # monitor tasks info
        self.tasks_counter = Counter('celery_tasks_total', 'TASK_COUNT_INFO', ['worker','task','result'])
        self.tasks_counter_c = CollectorRegistry()
        self.tasks_runtime = Summary('celery_tasks_seconds', 'TASK_RUNTIME', ['worker', 'task'])
        self.tasks_runtime_c = CollectorRegistry()
        self.tasks_info = Info('celery_tasks_info', 'TASK_INFO')
        self.tasks_info_c = CollectorRegistry() 
Example #2
Source File: http.py    From prometheus-pve-exporter with Apache License 2.0 7 votes vote down vote up
def start_http_server(config, port, address=''):
    """
    Start a HTTP API server for Proxmox VE prometheus collector.
    """

    duration = Summary(
        'pve_collection_duration_seconds',
        'Duration of collections by the PVE exporter',
        ['module'],
    )
    errors = Counter(
        'pve_request_errors_total',
        'Errors in requests to PVE exporter',
        ['module'],
    )

    # Initialize metrics.
    for module in config.keys():
        # pylint: disable=no-member
        errors.labels(module)
        # pylint: disable=no-member
        duration.labels(module)

    app = PveExporterApplication(config, duration, errors)
    run_simple(address, port, app, threaded=True) 
Example #3
Source File: __init__.py    From prometheus_flask_exporter with MIT License 6 votes vote down vote up
def summary(self, name, description, labels=None, **kwargs):
        """
        Use a Summary to track the execution time and invocation count
        of the method.

        :param name: the name of the metric
        :param description: the description of the metric
        :param labels: a dictionary of `{labelname: callable_or_value}` for labels
        :param kwargs: additional keyword arguments for creating the Summary
        """

        return self._track(
            Summary,
            lambda metric, time: metric.observe(time),
            kwargs, name, description, labels,
            registry=self.registry
        ) 
Example #4
Source File: test_resources.py    From dagster with Apache License 2.0 6 votes vote down vote up
def test_prometheus_summary():
    @solid(required_resource_keys={'prometheus'})
    def prometheus_solid(context):
        s = Summary(
            'request_latency_seconds',
            'Description of summary',
            registry=context.resources.prometheus.registry,
        )
        s.observe(4.7)
        request_time = Summary(
            'response_latency_seconds',
            'Response latency (seconds)',
            registry=context.resources.prometheus.registry,
        )

        with request_time.time():
            time.sleep(1)

        recorded = context.resources.prometheus.registry.get_sample_value(
            'request_latency_seconds_sum'
        )
        assert abs(4.7 - recorded) < EPS

        recorded = context.resources.prometheus.registry.get_sample_value(
            'response_latency_seconds_sum'
        )
        assert abs(1.0 - recorded) < 1.0

    assert execute_solid(prometheus_solid, run_config=ENV, mode_def=MODE).success 
Example #5
Source File: metrics.py    From anchore-engine with Apache License 2.0 6 votes vote down vote up
def summary_observe(name, observation, description="", **kwargs):
    global metrics, enabled

    if not enabled:
        return True

    try:
        if name not in metrics:
            metrics[name] = Summary(name, description, list(kwargs.keys()))

        if kwargs:
            metrics[name].labels(**kwargs).observe(observation)
        else:
            metrics[name].observe(observation)

    except Exception as err:
        logger.warn("adding metric failed - exception: " + str(err))

    return True 
Example #6
Source File: prometheus.py    From hiku with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_default_metric():
    global _METRIC
    if _METRIC is None:
        _METRIC = Summary(
            'graph_field_time',
            'Graph field time (seconds)',
            ['graph', 'node', 'field'],
        )
    return _METRIC 
Example #7
Source File: metrics.py    From anchore-engine with Apache License 2.0 5 votes vote down vote up
def get_summary_obj(name, description="", **kwargs):
    global metrics, enabled

    if not enabled:
        return None

    ret = None
    try:
        if name not in metrics:
            metrics[name] = Summary(name, description, list(kwargs.keys()))
        ret = metrics[name]
    except:
        logger.warn("could not create/get named metric (" + str(name) + ")")

    return ret