當前位置: 首頁>>代碼示例>>Python>>正文


Python core.CounterMetricFamily方法代碼示例

本文整理匯總了Python中prometheus_client.core.CounterMetricFamily方法的典型用法代碼示例。如果您正苦於以下問題:Python core.CounterMetricFamily方法的具體用法?Python core.CounterMetricFamily怎麽用?Python core.CounterMetricFamily使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在prometheus_client.core的用法示例。


在下文中一共展示了core.CounterMetricFamily方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: counter_generator

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def counter_generator(metrics):
    metric_dict = group_metrics(metrics)

    for metric_name, (metric_doc, label_keys, value_dict) in metric_dict.items():
        # If we have label keys we may have multiple different values,
        # each with their own label values.
        if label_keys:
            counter = CounterMetricFamily(metric_name, metric_doc, labels=label_keys)

            for label_values in sorted(value_dict.keys()):
                value = value_dict[label_values]
                counter.add_metric(tuple(str(v) for v in label_values), value)

        # No label keys, so we must have only a single value.
        else:
            counter = CounterMetricFamily(metric_name, metric_doc, value=list(value_dict.values())[0])

        yield counter 
開發者ID:braedon,項目名稱:prometheus-kafka-consumer-group-exporter,代碼行數:20,代碼來源:collectors.py

示例2: collect

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def collect(self):
    out = urlopen("http://localhost:8500/v1/agent/metrics").read()
    metrics = json.loads(out.decode("utf-8"))

    for g in metrics["Gauges"]:
      yield GaugeMetricFamily(sanitise_name(g["Name"]),
          "Consul metric " + g["Name"], g["Value"])

    for c in metrics["Counters"]:
      yield CounterMetricFamily(sanitise_name(c["Name"]) + "_total",
          "Consul metric " + c["Name"], c["Count"])

    for s in metrics["Samples"]:
      yield SummaryMetricFamily(sanitise_name(s["Name"]) + "_seconds",
          "Consul metric " + s["Name"],
          count_value=c["Count"], sum_value=s["Sum"] / 1000) 
開發者ID:prometheus-up-and-running,項目名稱:examples,代碼行數:18,代碼來源:12-3-consul_metrics.py

示例3: collect

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def collect(self):
    response = requests.get(args.uri)
    json = response.json()

    metrics   = json['metrics']

    # iterate over all metrics
    for k in metrics:
      underscores = re.sub('\.|-|\s', '_', k).lower()

      if metrics[k]['type'] == 'timer':
        # we have a timer, expose as a Prometheus Summary
        underscores = underscores + '_' + metrics[k]['duration_unit']
        summary = SummaryMetricFamily(underscores, 'libmedida metric type: ' + metrics[k]['type'], count_value=metrics[k]['count'], sum_value=(metrics[k]['mean'] * metrics[k]['count']))
        # add stellar-core calculated quantiles to our summary
        summary.add_sample(underscores, labels={'quantile':'0.75'}, value=metrics[k]['75%'])
        summary.add_sample(underscores, labels={'quantile':'0.95'}, value=metrics[k]['95%'])
        summary.add_sample(underscores, labels={'quantile':'0.99'}, value=metrics[k]['99%'])
        yield summary
      elif metrics[k]['type'] == 'counter':
        # we have a counter, this is a Prometheus Gauge
        yield GaugeMetricFamily(underscores, 'libmedida metric type: ' + metrics[k]['type'], value=metrics[k]['count'])
      elif metrics[k]['type'] == 'meter':
        # we have a meter, this is a Prometheus Counter
        yield CounterMetricFamily(underscores, 'libmedida metric type: ' + metrics[k]['type'], value=metrics[k]['count']) 
開發者ID:kinecosystem,項目名稱:blockchain-ops,代碼行數:27,代碼來源:stellar-core-prometheus-exporter.py

示例4: test_submit_counter

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def test_submit_counter(
    aggregator,
    mocked_prometheus_check,
    mocked_prometheus_scraper_config,
    config,
    counter_metric_monotonic,
    counter_with_gauge,
):
    # Determine expected metric types for counter metrics
    counter_type = aggregator.GAUGE
    if counter_metric_monotonic:
        counter_type = aggregator.MONOTONIC_COUNT

    metric_name = 'prometheus.custom.counter'
    _counter = CounterMetricFamily('my_counter', 'Random counter')
    _counter.add_metric([], 42)
    mocked_prometheus_scraper_config.update(config)
    check = mocked_prometheus_check
    check.submit_openmetric('custom.counter', _counter, mocked_prometheus_scraper_config)
    aggregator.assert_metric(metric_name, 42, tags=[], count=1, metric_type=counter_type)

    if counter_with_gauge:
        aggregator.assert_metric(metric_name + '.total', 42, tags=[], count=1, metric_type=aggregator.MONOTONIC_COUNT)

    aggregator.assert_all_metrics_covered() 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:27,代碼來源:test_openmetrics.py

示例5: _instanceMetric

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def _instanceMetric(self, data):
        if data["type"] is "counter":
            return CounterMetricFamily(data["name"], data["help"], labels=data["labels"].keys())
        elif data["type"] is "gauge":
            return GaugeMetricFamily(data["name"], data["help"], labels=data["labels"].keys())
        else:
            raise Exception("Unsupported metric type: {type}".format(type=data['type'])) 
開發者ID:spreaker,項目名稱:prometheus-pgbouncer-exporter,代碼行數:9,代碼來源:collector.py

示例6: test_counter_to_prometheus

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def test_counter_to_prometheus(self):
        meter = get_meter_provider().get_meter(__name__)
        metric = meter.create_metric(
            "test@name",
            "testdesc",
            "unit",
            int,
            metrics.Counter,
            ["environment@", "os"],
        )
        labels = {"environment@": "staging", "os": "Windows"}
        key_labels = metrics.get_labels_as_key(labels)
        aggregator = SumAggregator()
        aggregator.update(123)
        aggregator.take_checkpoint()
        record = MetricRecord(metric, key_labels, aggregator)
        collector = CustomCollector("testprefix")
        collector.add_metrics_data([record])

        for prometheus_metric in collector.collect():
            self.assertEqual(type(prometheus_metric), CounterMetricFamily)
            self.assertEqual(prometheus_metric.name, "testprefix_test_name")
            self.assertEqual(prometheus_metric.documentation, "testdesc")
            self.assertTrue(len(prometheus_metric.samples) == 1)
            self.assertEqual(prometheus_metric.samples[0].value, 123)
            self.assertTrue(len(prometheus_metric.samples[0].labels) == 2)
            self.assertEqual(
                prometheus_metric.samples[0].labels["environment_"], "staging"
            )
            self.assertEqual(
                prometheus_metric.samples[0].labels["os"], "Windows"
            )

    # TODO: Add unit test once GaugeAggregator is available
    # TODO: Add unit test once Measure Aggregators are available 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:37,代碼來源:test_prometheus_exporter.py

示例7: _create_counter

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def _create_counter(self):
        """
        Create a counter instance.
        
        :return: prometheus_client counter instance
        """
        description = "Costs billed to Azure Enterprise Agreement {}".format(self._enrollment)
        c = CounterMetricFamily(self._metric_name, description, labels=base_columns)
        return c 
開發者ID:blue-yonder,項目名稱:azure-cost-mon,代碼行數:11,代碼來源:enterprise_billing_collector.py

示例8: test_parse_one_counter

# 需要導入模塊: from prometheus_client import core [as 別名]
# 或者: from prometheus_client.core import CounterMetricFamily [as 別名]
def test_parse_one_counter(p_check, mocked_prometheus_scraper_config):
    """
    name: "go_memstats_mallocs_total"
    help: "Total number of mallocs."
    type: COUNTER
    metric {
      counter {
        value: 18713.0
      }
    }
    """
    text_data = (
        "# HELP go_memstats_mallocs_total Total number of mallocs.\n"
        "# TYPE go_memstats_mallocs_total counter\n"
        "go_memstats_mallocs_total 18713\n"
    )

    expected_etcd_metric = CounterMetricFamily('go_memstats_mallocs_total', 'Total number of mallocs.')
    expected_etcd_metric.add_metric([], 18713)
    # Fix up the _total change
    expected_etcd_metric.name = 'go_memstats_mallocs_total'

    # Iter on the generator to get all metrics
    response = MockResponse(text_data, text_content_type)
    check = p_check
    metrics = [k for k in check.parse_metric_family(response, mocked_prometheus_scraper_config)]

    assert 1 == len(metrics)
    current_metric = metrics[0]
    assert expected_etcd_metric == current_metric 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:32,代碼來源:test_openmetrics.py


注:本文中的prometheus_client.core.CounterMetricFamily方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。