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


Python prometheus_client.CollectorRegistry方法代码示例

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


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

示例1: create_metric

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例2: setUp

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例3: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例4: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def __init__(self) -> None:
        self.registry = prometheus_client.CollectorRegistry()
        _labels = ["project", "smpp_command", "state", "response_code"]
        self.counter = prometheus_client.Counter(
            name="number_of_messages",
            documentation="number of messages processed by naz.",
            labelnames=_labels,
            registry=self.registry,
        )
        self._LOOP: typing.Union[None, asyncio.events.AbstractEventLoop] = None
        self.thread_name_prefix = "naz_benchmarks_hook_pool"

        # go to prometheus dashboard(http://localhost:9000/) & you can run queries like:
        # 1. container_memory_rss{name="naz_cli", container_label_com_docker_compose_service="naz_cli"}
        # 2. container_memory_rss{name=~"naz_cli|message_producer"}
        # 3. number_of_messages_total{project="naz_benchmarks"}
        # 4. rate(number_of_messages_total{smpp_command="submit_sm",state="request"}[30s])  # msg sending over the past 30seconds 
开发者ID:komuw,项目名称:naz,代码行数:19,代码来源:my_hook.py

示例5: get_prometheus_incidents_metrics

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例6: pushadd_to_gateway

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def pushadd_to_gateway(self, job, grouping_key=None, handler=default_handler):
        '''PushAdd metrics to the given pushgateway.
        `job` is the job label to be attached to all pushed metrics
        `registry` is an instance of CollectorRegistry
        `grouping_key` please see the pushgateway documentation for details.
                    Defaults to None
        `handler` is an optional function which can be provided to perform
                requests to the 'gateway'.
                Defaults to None, in which case an http or https request
                will be carried out by a default handler.
                See the 'prometheus_client.push_to_gateway' documentation
                for implementation requirements.
        This replaces metrics with the same name, job and grouping_key.
        This uses the POST HTTP method.'''
        prometheus_client.pushadd_to_gateway(
            gateway=self.gateway,
            job=job,
            registry=self.registry,
            grouping_key=grouping_key,
            timeout=self.timeout,
            handler=handler,
        ) 
开发者ID:dagster-io,项目名称:dagster,代码行数:24,代码来源:resources.py

示例7: setUp

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def setUp(self):
        self.statsd = StatsdFixture()
        self.useFixture(self.statsd)
        # note, use 127.0.0.1 rather than localhost to avoid getting ipv6
        # see: https://github.com/jsocol/pystatsd/issues/61
        self.useFixture(
            fixtures.EnvironmentVariable('STATSD_HOST', '127.0.0.1'))
        self.useFixture(
            fixtures.EnvironmentVariable('STATSD_PORT', str(self.statsd.port)))

        self.add_info_on_exception('statsd_content', self.statsd.stats)
        # Set up the above things before the super setup so that we have the
        # environment variables set when the Connection is created.
        super(TestStats, self).setUp()

        self._registry = prometheus_client.CollectorRegistry()
        self.cloud.config._collector_registry = self._registry
        self.addOnException(self._add_prometheus_samples) 
开发者ID:openstack,项目名称:openstacksdk,代码行数:20,代码来源:test_stats.py

示例8: setUp

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def setUp(self):
        self.registry = CollectorRegistry()

        self.data = ''

        class TCPHandler(SocketServer.BaseRequestHandler):
            def handle(s):
                self.data = s.request.recv(1024)

        server = SocketServer.TCPServer(('', 0), TCPHandler)

        class ServingThread(threading.Thread):
            def run(self):
                server.handle_request()
                server.socket.close()

        self.t = ServingThread()
        self.t.start()

        # Explicitly use localhost as the target host, since connecting to 0.0.0.0 fails on Windows
        address = ('localhost', server.server_address[1])
        self.gb = GraphiteBridge(address, self.registry, _timer=fake_timer) 
开发者ID:prometheus,项目名称:client_python,代码行数:24,代码来源:test_graphite_bridge.py

示例9: __init__

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def __init__(self):
        self.registry = CollectorRegistry()
        self.prodstack = {}
        with open(config['cache_file'], 'rb') as f:
            self.prodstack = pickle.load(f)[0]
        self.hypervisors = self.prodstack['hypervisors']
        self.tenant_map = {t['id']: t['name'] for t in self.prodstack['tenants']}
        self.flavor_map = {f['id']: {'ram': f['ram'], 'disk': f['disk'], 'vcpus': f['vcpus']}
                           for f in self.prodstack['flavors']}
        self.aggregate_map = {}
        self.services_map = {}
        for s in self.prodstack['services']:
            if s['binary'] == 'nova-compute':
                self.services_map[s['host']] = s['status']
        for agg in self.prodstack['aggregates']:
            self.aggregate_map.update({i: agg['name'] for i in agg['hosts']}) 
开发者ID:CanonicalLtd,项目名称:prometheus-openstack-exporter,代码行数:18,代码来源:prometheus_openstack_exporter.py

示例10: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例11: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例12: get_stats

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [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

示例13: test_single_machine

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def test_single_machine(enable_login):
    responses.add(
        method='GET',
        url='https://management.azure.com/subscriptions/SUBSCRIPTION_ID/providers/Microsoft.Compute/virtualMachines?api-version=2017-03-30',
        match_querystring=True,
        json={'value': [
            {
                'id': '/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP/providers/Microsoft.Compute/virtualMachines/NAME',
                'location': 'WESTEUROPE',
                'properties': {'hardwareProfile': {'vmSize': 'SIZE'}}
            }
        ]})

    registry = CollectorRegistry()
    c = AzureAllocatedVMCollector('app_id', 'app_secret', 'tenant_id', ['SUBSCRIPTION_ID'], 'SERIES_NAME')
    registry.register(c)

    result = generate_latest(registry).decode('utf8').split('\n')
    assert 'SERIES_NAME{location="WESTEUROPE",resource_group="RESOURCE_GROUP",subscription="SUBSCRIPTION_ID",vm_size="SIZE"} 1.0' in result 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:21,代码来源:test_allocated_vm_collector.py

示例14: test_extract_metrics

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def test_extract_metrics(api_url, enrollment):

    responses.add(
        method='GET',
        url=api_url,
        match_querystring=True,
        json=sample_data
    )

    registry = CollectorRegistry()
    c = AzureEABillingCollector('costs', enrollment, 'ab123xy', 10)
    registry.register(c)

    result = generate_latest(registry).decode('utf8').split('\n')
    assert len(result) == 5

    expected_0 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="virtual network",MeterName="hours",MeterSubCategory="gateway hour",ResourceGroup="",SubscriptionName="production"} 0.0'
    expected_1 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="windows azure storage",MeterName="standard io - page blob/disk (gb)",MeterSubCategory="locally redundant",ResourceGroup="my-group",SubscriptionName="production"} 1.0'

    assert result[2] == expected_0
    assert result[3] == expected_1 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:23,代码来源:test_enterprise_billing_collector.py

示例15: root

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CollectorRegistry [as 别名]
def root():
    # check access
    ip_whitelist = ip_network(current_app.config.get('PROMETHEUS_WHITELIST'))
    if ip_address(request.remote_addr) not in ip_whitelist:
        _jwt_required(current_app.config['JWT_DEFAULT_REALM'])

    MU = MetricUpdater()
    registry = CollectorRegistry()
    multiprocess.MultiProcessCollector(registry)

    data = generate_latest(registry)

    response = make_response(data)
    response.headers['Content-Type'] = CONTENT_TYPE_LATEST
    response.headers['Content-Length'] = str(len(data))
    logger.info('Kqueen metrics updating')
    MU.update_metrics()

    return response 
开发者ID:Mirantis,项目名称:kqueen,代码行数:21,代码来源:views.py


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