当前位置: 首页>>代码示例>>Python>>正文


Python prometheus_client.Histogram方法代码示例

本文整理汇总了Python中prometheus_client.Histogram方法的典型用法代码示例。如果您正苦于以下问题:Python prometheus_client.Histogram方法的具体用法?Python prometheus_client.Histogram怎么用?Python prometheus_client.Histogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prometheus_client的用法示例。


在下文中一共展示了prometheus_client.Histogram方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: histogram

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def histogram(self, name, description, labels=None, **kwargs):
        """
        Use a Histogram 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 Histogram
        """

        return self._track(
            Histogram,
            lambda metric, time: metric.observe(time),
            kwargs, name, description, labels,
            registry=self.registry
        ) 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:19,代码来源:__init__.py

示例2: get_prometheus_histogram

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def get_prometheus_histogram(self):
        registry = self.get_prometheus_registry()
        if not registry or not prometheus_client:
            return
        # We have to hide a reference to the histogram on the registry
        # object, because it's collectors must be singletons for a given
        # registry but register at creation time.
        hist = getattr(registry, '_openstacksdk_histogram', None)
        if not hist:
            hist = prometheus_client.Histogram(
                'openstack_http_response_time',
                'Time taken for an http response to an OpenStack service',
                labelnames=[
                    'method', 'endpoint', 'service_type', 'status_code'
                ],
                registry=registry,
            )
            registry._openstacksdk_histogram = hist
        return hist 
开发者ID:openstack,项目名称:openstacksdk,代码行数:21,代码来源:cloud_region.py

示例3: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def __init__(self,
                 name,
                 documentation,
                 labelnames=(),
                 namespace='',
                 subsystem='',
                 unit='',
                 registry=REGISTRY,
                 labelvalues=None,
                 buckets=DEFAULT_BUCKETS,
                 ):
        self._prepare_buckets(buckets)
        super(Histogram, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['buckets'] = buckets 
开发者ID:prometheus,项目名称:client_python,代码行数:25,代码来源:metrics.py

示例4: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def __init__(self,
        name,
        documentation,
        labelnames=(),
        namespace='',
        subsystem='',
        unit='',
        registry=REGISTRY,
        labelvalues=None,
        buckets=DEFAULT_BUCKETS,
    ):
        self._prepare_buckets(buckets)
        super(Histogram, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['buckets'] = buckets 
开发者ID:holzschu,项目名称:Carnets,代码行数:25,代码来源:metrics.py

示例5: histogram_observe

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def histogram_observe(name, observation, description="", buckets=None, **kwargs):
    global metrics, enabled

    if not enabled:
        return True

    try:
        if name not in metrics:
            if buckets:
                buckets.append(float("inf"))
                metrics[name] = Histogram(name, description, list(kwargs.keys()), buckets=buckets)
            else:
                metrics[name] = Histogram(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 
开发者ID:anchore,项目名称:anchore-engine,代码行数:24,代码来源:metrics.py

示例6: init

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def init(app, latency_buckets=None, multiprocess_mode='all',
         memcollect_enabled=True, metrics_list=None):
    app.metrics['RQS_COUNT'] = Counter(
        'sanic_request_count',
        'Sanic Request Count',
        ['method', 'endpoint', 'http_status']
    )

    hist_kwargs = {}
    if latency_buckets is not None:
        hist_kwargs = {'buckets': latency_buckets}
    app.metrics['RQS_LATENCY'] = Histogram(
        'sanic_request_latency_sec',
        'Sanic Request Latency Histogram',
        ['method', 'endpoint', 'http_status'],
        **hist_kwargs
    )

    if memcollect_enabled:
        app.metrics['PROC_RSS_MEM_BYTES'] = Gauge(
            'sanic_mem_rss_bytes',
            'Resident memory used by process running Sanic',
            multiprocess_mode=multiprocess_mode
        )
        app.metrics['PROC_RSS_MEM_PERC'] = Gauge(
            'sanic_mem_rss_perc',
            'A per cent of total physical memory used by ' +
            'the process running Sanic',
            multiprocess_mode=multiprocess_mode
        )

    if metrics_list:
        for name, pm_metric in metrics_list:
            app.metrics[name] = pm_metric 
开发者ID:dkruchinin,项目名称:sanic-prometheus,代码行数:36,代码来源:metrics.py

示例7: set_histogram

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def set_histogram(name, *args, **kwargs):
    metrics[name] = Histogram(name, *args, **kwargs)


#models.py metrics 
开发者ID:desec-io,项目名称:desec-stack,代码行数:7,代码来源:metrics.py

示例8: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def __init__(self, prefix, description, labels):
        """
        :param prefix: prefix to use for each metric name
        :param description: description of action to use in metric description
        :param labels: label names to define for each metric
        """
        self.full_prefix = '{}_{}'.format(self.__class__._PREFIX, prefix)
        self.progress = prometheus_client.Gauge(
            '{}_attempt_inprogress'.format(self.full_prefix),
            'In progress attempts to {}'.format(description),
            labels,
            registry=REGISTRY,
            multiprocess_mode='livesum')
        self.attempt_total = prometheus_client.Counter(
            '{}_attempt_total'.format(self.full_prefix),
            'Total attempts to {}'.format(description),
            labels,
            registry=REGISTRY)
        self.failure_total = prometheus_client.Counter(
            '{}_failure_total'.format(self.full_prefix),
            'Total failures to {}'.format(description),
            labels,
            registry=REGISTRY)
        self.duration = prometheus_client.Histogram(
            '{}_duration_seconds'.format(self.full_prefix),
            'Seconds to {}'.format(description),
            labels,
            registry=REGISTRY) 
开发者ID:airshipit,项目名称:armada,代码行数:30,代码来源:metrics.py

示例9: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def __init__(self, app, bento_service):
        self.app = app
        self.bento_service = bento_service

        from prometheus_client import Histogram, Counter, Gauge, CollectorRegistry

        service_name = self.bento_service.name
        namespace = config('instrument').get('default_namespace')
        # Use local registry instead of the global one to avoid duplicated metrics
        # register
        self.collector_registry = CollectorRegistry()

        self.metrics_request_duration = Histogram(
            name=service_name + '_request_duration_seconds',
            documentation=service_name + " API HTTP request duration in seconds",
            namespace=namespace,
            labelnames=['endpoint', 'service_version', 'http_response_code'],
            registry=self.collector_registry,
        )
        self.metrics_request_total = Counter(
            name=service_name + "_request_total",
            documentation='Totoal number of HTTP requests',
            namespace=namespace,
            labelnames=['endpoint', 'service_version', 'http_response_code'],
            registry=self.collector_registry,
        )
        self.metrics_request_in_progress = Gauge(
            name=service_name + "_request_in_progress",
            documentation='Totoal number of HTTP requests in progress now',
            namespace=namespace,
            labelnames=['endpoint', 'service_version'],
            registry=self.collector_registry,
        ) 
开发者ID:bentoml,项目名称:BentoML,代码行数:35,代码来源:instruments.py

示例10: test_prometheus_histogram

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def test_prometheus_histogram():
    @solid(required_resource_keys={'prometheus'})
    def prometheus_solid(context):
        h = Histogram(
            'pipeline_runtime_seconds',
            'Description of histogram',
            registry=context.resources.prometheus.registry,
        )
        h.observe(4.7)
        recorded = context.resources.prometheus.registry.get_sample_value(
            'pipeline_runtime_seconds_sum'
        )
        assert abs(4.7 - recorded) < EPS

    assert execute_solid(prometheus_solid, run_config=ENV, mode_def=MODE).success 
开发者ID:dagster-io,项目名称:dagster,代码行数:17,代码来源:test_resources.py

示例11: get_histogram_buckets_from_evn

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def get_histogram_buckets_from_evn(env_name):
    if env_name in os.environ:
        buckets = decode_buckets(os.environ.get(env_name))
    else:
        if hasattr(prometheus_client.Histogram, 'DEFAULT_BUCKETS'): # pragma: no cover
            buckets = prometheus_client.Histogram.DEFAULT_BUCKETS
        else: # pragma: no cover
            # For prometheus-client < 0.3.0 we cannot easily access
            # the default buckets:
            buckets = (.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 5.0, 7.5, 10.0, float('inf'))
    return buckets 
开发者ID:zerok,项目名称:celery-prometheus-exporter,代码行数:13,代码来源:celery_prometheus_exporter.py

示例12: _histogram

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def _histogram(self, var, var_help, labels, buckets):
        return Histogram(var, var_help, labels, buckets=buckets, registry=self._reg) # pylint: disable=unexpected-keyword-arg 
开发者ID:faucetsdn,项目名称:faucet,代码行数:4,代码来源:faucet_metrics.py

示例13: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def __init__(self):
        super(ProtonPrometheus, self).__init__()
        self.registry = CollectorRegistry()
        self.requests = Counter(
            'http_total_request',
            'Counter of total HTTP requests',
            ['method', 'path', 'status'],
            registry=self.registry)

        self.request_historygram = Histogram(
            'request_latency_seconds',
            'Histogram of request latency',
            ['method', 'path', 'status'],
            registry=self.registry) 
开发者ID:PruthviKumarBK,项目名称:PROTON,代码行数:16,代码来源:proton_prometheus.py

示例14: setup_metrics

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Histogram [as 别名]
def setup_metrics(app, app_name):
    app['REQUEST_COUNT'] = Counter(
      'requests_total', 'Total Request Count',
      ['app_name', 'method', 'endpoint', 'http_status']
    )
    app['REQUEST_LATENCY'] = Histogram(
        'request_latency_seconds', 'Request latency',
        ['app_name', 'endpoint']
    )

    app['REQUEST_IN_PROGRESS'] = Gauge(
        'requests_in_progress_total', 'Requests in progress',
        ['app_name', 'endpoint', 'method']
    )

    app.middlewares.insert(0, prom_middleware(app_name))
    app.router.add_get("/metrics", metrics) 
开发者ID:amitsaha,项目名称:python-prometheus-demo,代码行数:19,代码来源:middleware.py


注:本文中的prometheus_client.Histogram方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。