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


Python prometheus_client.Gauge方法代码示例

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


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

示例1: setUp

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def setUp(self):
        self.registry = prometheus_client.CollectorRegistry()
        self.some_gauge = prometheus_client.Gauge(
            "some_gauge", "Some gauge.", registry=self.registry
        )
        self.some_gauge.set(42)
        self.some_labelled_gauge = prometheus_client.Gauge(
            "some_labelled_gauge",
            "Some labelled gauge.",
            ["labelred", "labelblue"],
            registry=self.registry,
        )
        self.some_labelled_gauge.labels("pink", "indigo").set(1)
        self.some_labelled_gauge.labels("pink", "royal").set(2)
        self.some_labelled_gauge.labels("carmin", "indigo").set(3)
        self.some_labelled_gauge.labels("carmin", "royal").set(4)
        self.test_case = SomeTestCase() 
开发者ID:korfuri,项目名称:django-prometheus,代码行数:19,代码来源:test_testutils.py

示例2: create_metric

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
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() 
开发者ID:adrianyoung,项目名称:CrawlerMonitor,代码行数:26,代码来源:monitor.py

示例3: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def __init__(self, data_manager, config):
        self.config = config
        self.data_manager = data_manager
        self.http_server = prometheus_client.start_http_server(
            self.config.prometheus_port,
            addr=self.config.prometheus_addr
        )
        self.updated_containers_counter = prometheus_client.Counter(
            'containers_updated',
            'Count of containers updated',
            ['socket', 'container']
        )
        self.monitored_containers_gauge = prometheus_client.Gauge(
            'containers_being_monitored',
            'Gauge of containers being monitored',
            ['socket']
        )
        self.updated_all_containers_gauge = prometheus_client.Gauge(
            'all_containers_updated',
            'Count of total updated',
            ['socket']
        )
        self.logger = getLogger() 
开发者ID:pyouroboros,项目名称:ouroboros,代码行数:25,代码来源:dataexporters.py

示例4: gauge

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def gauge(self, name, description, labels=None, **kwargs):
        """
        Use a Gauge to track the number of invocations in progress
        for 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 Gauge
        """

        return self._track(
            Gauge,
            lambda metric, time: metric.dec(),
            kwargs, name, description, labels,
            registry=self.registry,
            before=lambda metric: metric.inc(),
            revert_when_not_tracked=lambda metric: metric.dec()
        ) 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:21,代码来源:__init__.py

示例5: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def __init__(self, name):
        self._gauge = Gauge(name, "A gauge of current ammount of active jobs per cluster",
                              ['state', 'cluster'])
        self._request_per_cluster = """
            SELECT cluster_name,
                count(id) filter(WHERE state = 'running'),
                count(id) filter(WHERE state = 'queued'),
                count(id) filter(WHERE state = 'scheduled')
            FROM job
            WHERE state in ('running', 'queued', 'scheduled')
            GROUP BY cluster_name
        """

        self._request_total = """
            SELECT count(id) filter(WHERE state = 'running'),
                   count(id) filter(WHERE state = 'queued'),
                   count(id) filter(WHERE state = 'scheduled')
            FROM job
            WHERE state in ('running', 'queued', 'scheduled')
        """ 
开发者ID:SAP,项目名称:InfraBox,代码行数:22,代码来源:server.py

示例6: get_prometheus_incidents_metrics

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def get_prometheus_incidents_metrics():
    registry = CollectorRegistry()
    g = Gauge('zentral_incidents_count', 'Zentral incidents',
              ['name', 'id', 'severity', 'status', 'opened'],
              registry=registry)
    query = (
        "select count(*), "
        "i.id, i.name, i.severity, "
        "mi.status, (CASE WHEN mi.status in ('CLOSED', 'RESOLVED') THEN FALSE ELSE TRUE END) as opened "
        "from incidents_incident as i "
        "join incidents_machineincident as mi on (mi.incident_id = i.id) "
        "group by i.name, i.id, i.severity, mi.status, opened "
        "order by i.id, mi.status;"
    )
    cursor = connection.cursor()
    cursor.execute(query)
    columns = [col[0] for col in cursor.description]
    for row in cursor.fetchall():
        d = dict(zip(columns, row))
        d["severity"] = str(SEVERITY_CHOICES_DICT.get(d.pop("severity"), "Unknown"))
        d["status"] = str(STATUS_CHOICES_DICT.get(d.pop("status"), "Unknown"))
        d["opened"] = 'Y' if d["opened"] else 'N'
        count = d.pop('count')
        g.labels(**d).set(count)
    return registry 
开发者ID:zentralopensource,项目名称:zentral,代码行数:27,代码来源:utils.py

示例7: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def __init__(self,
                 name,
                 documentation,
                 labelnames=(),
                 namespace='',
                 subsystem='',
                 unit='',
                 registry=REGISTRY,
                 labelvalues=None,
                 multiprocess_mode='all',
                 ):
        self._multiprocess_mode = multiprocess_mode
        if multiprocess_mode not in self._MULTIPROC_MODES:
            raise ValueError('Invalid multiprocess mode: ' + multiprocess_mode)
        super(Gauge, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['multiprocess_mode'] = self._multiprocess_mode 
开发者ID:prometheus,项目名称:client_python,代码行数:27,代码来源:metrics.py

示例8: gen_subnet_size

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def gen_subnet_size(self):
        labels = ['cloud', 'network_name']
        net_size = Gauge('neutron_net_size',
                         'Neutron networks size',
                         labels, registry=self.registry)
        for n in self.prodstack['networks']:
            size = 0
            for subnet in n['subnets']:
                for pool in self.subnet_map[subnet]['pool']:
                    if ':' in pool['start']:
                        # Skip IPv6 address pools; they are big enough to
                        # drown the IPv4 numbers we might care about.
                        continue
                    size += IPRange(pool['start'], pool['end']).size
            label_values = [config['cloud'], self.network_map[n['id']]]
            net_size.labels(*label_values).set(size) 
开发者ID:CanonicalLtd,项目名称:prometheus-openstack-exporter,代码行数:18,代码来源:prometheus_openstack_exporter.py

示例9: gen_volume_quota_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def gen_volume_quota_stats(self):
        gbs = Gauge('cinder_quota_volume_disk_gigabytes',
                    'Cinder volume metric (GB)',
                    ['cloud', 'tenant', 'type'], registry=self.registry)
        vol = Gauge('cinder_quota_volume_disks',
                    'Cinder volume metric (number of volumes)',
                    ['cloud', 'tenant', 'type'], registry=self.registry)
        if not self.use_nova_volumes:
            return
        for t, q in self.prodstack['volume_quotas'].items():
            if t in self.tenant_map:
                tenant = self.tenant_map[t]
            else:
                tenant = 'orphaned'
            for tt in ['limit', 'in_use', 'reserved']:
                gbs.labels(config['cloud'], tenant, tt).inc(q['gigabytes'][tt])
                vol.labels(config['cloud'], tenant, tt).inc(q['volumes'][tt]) 
开发者ID:CanonicalLtd,项目名称:prometheus-openstack-exporter,代码行数:19,代码来源:prometheus_openstack_exporter.py

示例10: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def __init__(self, reg=None):
        super(GaugePrometheusClient, self).__init__(reg=reg)
        self.table_tags = collections.defaultdict(set)
        self.metrics = {}
        self.dp_status = Gauge( # pylint: disable=unexpected-keyword-arg
            'dp_status',
            'status of datapaths',
            self.REQUIRED_LABELS,
            registry=self._reg)
        for prom_var in PROM_PORT_VARS + PROM_PORT_STATE_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_PORT_PREFIX, prom_var))
            self.metrics[exported_prom_var] = Gauge(  # pylint: disable=unexpected-keyword-arg
                exported_prom_var, '',
                self.REQUIRED_LABELS + ['port', 'port_description'],
                registry=self._reg)
        for prom_var in PROM_METER_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_METER_PREFIX, prom_var))
            self.metrics[exported_prom_var] = Gauge(  # pylint: disable=unexpected-keyword-arg
                exported_prom_var, '',
                self.REQUIRED_LABELS + ['meter_id'],
                registry=self._reg) 
开发者ID:faucetsdn,项目名称:faucet,代码行数:25,代码来源:gauge_prom.py

示例11: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        services_stats_cache = self.get_cache_data()
        for services_stat in services_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    services_stat['stat_name']),
                'Openstack Nova Service statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            services_stat.get('host', ''),
                            services_stat.get('service', ''),
                            services_stat.get('state', '')]
            stat_gauge.labels(*label_values).set(services_stat['stat_value'])
        return generate_latest(registry) 
开发者ID:att-comdev,项目名称:prometheus-openstack-exporter,代码行数:19,代码来源:nova_services.py

示例12: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        cinder_services_stats_cache = self.get_cache_data()
        for cinder_services_stat in cinder_services_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    cinder_services_stat['stat_name']),
                'Openstack Cinder Service statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            cinder_services_stat.get('host', ''),
                            cinder_services_stat.get('service', ''),
                            cinder_services_stat.get('state', '')]
            stat_gauge.labels(
                *
                label_values).set(
                cinder_services_stat['stat_value'])
        return generate_latest(registry) 
开发者ID:att-comdev,项目名称:prometheus-openstack-exporter,代码行数:22,代码来源:cinder_services.py

示例13: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'url', 'service']
        check_api_data_cache = self.get_cache_data()
        for check_api_data in check_api_data_cache:
            label_values = [
                check_api_data['region'],
                check_api_data['url'],
                check_api_data['service']]
            gague_name = self.gauge_name_sanitize(
                "check_{}_api".format(check_api_data['service']))
            check_gauge = Gauge(
                gague_name,
                'Openstack API check. fail = 0, ok = 1 and unknown = 2',
                labels,
                registry=registry)
            check_gauge.labels(*label_values).set(check_api_data['status'])
        return generate_latest(registry) 
开发者ID:att-comdev,项目名称:prometheus-openstack-exporter,代码行数:20,代码来源:check_os_api.py

示例14: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        neutron_agent_stats_cache = self.get_cache_data()
        for neutron_agent_stat in neutron_agent_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    neutron_agent_stat['stat_name']),
                'Openstack Neutron agent statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            neutron_agent_stat.get('host', ''),
                            neutron_agent_stat.get('service', ''),
                            neutron_agent_stat.get('state', '')]
            stat_gauge.labels(
                *
                label_values).set(
                neutron_agent_stat['stat_value'])
        return generate_latest(registry) 
开发者ID:att-comdev,项目名称:prometheus-openstack-exporter,代码行数:22,代码来源:neutron_agents.py

示例15: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import Gauge [as 别名]
def __init__(self,
        name,
        documentation,
        labelnames=(),
        namespace='',
        subsystem='',
        unit='',
        registry=REGISTRY,
        labelvalues=None,
        multiprocess_mode='all',
    ):
        self._multiprocess_mode = multiprocess_mode
        if multiprocess_mode not in self._MULTIPROC_MODES:
            raise ValueError('Invalid multiprocess mode: ' + multiprocess_mode)
        super(Gauge, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['multiprocess_mode'] = self._multiprocess_mode 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:metrics.py


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