]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/pull/tests/integration/sample_server_multi.cc
801f1b9d9e8f11b78d3061fbc56246483abb25d3
5 #include "prometheus/client_metric.h"
6 #include "prometheus/counter.h"
7 #include "prometheus/exposer.h"
8 #include "prometheus/family.h"
9 #include "prometheus/registry.h"
12 using namespace prometheus
;
14 // create an http server running on port 8080
15 Exposer exposer
{"127.0.0.1:8080", 1};
17 auto registryA
= std::make_shared
<Registry
>();
19 // add a new counter family to the registry (families combine values with the
20 // same name, but distinct label dimensions)
21 auto& counter_familyA
= BuildCounter()
22 .Name("time_running_seconds_total")
23 .Help("How many seconds is this server running?")
24 .Register(*registryA
);
26 // add a counter to the metric family
27 auto& seconds_counterA
= counter_familyA
.Add(
28 {{"another_label", "bar"}, {"yet_another_label", "baz"}});
30 // ask the exposer to scrape registryA on incoming scrapes for "/metricsA"
31 exposer
.RegisterCollectable(registryA
, "/metricsA");
33 auto registryB
= std::make_shared
<Registry
>();
35 auto& counter_familyB
=
37 .Name("other_time_running_seconds_total")
38 .Help("How many seconds has something else been running?")
39 .Register(*registryB
);
41 auto& seconds_counterB
= counter_familyB
.Add(
42 {{"another_label", "not_bar"}, {"yet_another_label", "not_baz"}});
44 // This endpoint exposes registryB.
45 exposer
.RegisterCollectable(registryB
, "/metricsB");
48 std::this_thread::sleep_for(std::chrono::seconds(1));
49 // increment the counters by one (second)
50 seconds_counterA
.Increment(1.0);
51 seconds_counterB
.Increment(1.5);