本文整理汇总了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()
示例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()
示例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()
示例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()
)
示例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')
"""
示例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
示例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
示例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)
示例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])
示例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)
示例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)
示例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)
示例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)
示例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)
示例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