]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/pull/tests/integration/sample_server_multi.cc
801f1b9d9e8f11b78d3061fbc56246483abb25d3
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / pull / tests / integration / sample_server_multi.cc
1 #include <chrono>
2 #include <memory>
3 #include <thread>
4
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"
10
11 int main() {
12 using namespace prometheus;
13
14 // create an http server running on port 8080
15 Exposer exposer{"127.0.0.1:8080", 1};
16
17 auto registryA = std::make_shared<Registry>();
18
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);
25
26 // add a counter to the metric family
27 auto& seconds_counterA = counter_familyA.Add(
28 {{"another_label", "bar"}, {"yet_another_label", "baz"}});
29
30 // ask the exposer to scrape registryA on incoming scrapes for "/metricsA"
31 exposer.RegisterCollectable(registryA, "/metricsA");
32
33 auto registryB = std::make_shared<Registry>();
34
35 auto& counter_familyB =
36 BuildCounter()
37 .Name("other_time_running_seconds_total")
38 .Help("How many seconds has something else been running?")
39 .Register(*registryB);
40
41 auto& seconds_counterB = counter_familyB.Add(
42 {{"another_label", "not_bar"}, {"yet_another_label", "not_baz"}});
43
44 // This endpoint exposes registryB.
45 exposer.RegisterCollectable(registryB, "/metricsB");
46
47 for (;;) {
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);
52 }
53 return 0;
54 }