-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_server.cc
53 lines (42 loc) · 1.4 KB
/
sample_server.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <chrono>
#include <cstdio>
#include <map>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include <prometheus/exposer.h>
#include <prometheus/marker.h>
#include <prometheus/registry.h>
using namespace prometheus;
auto registry = Registry::Create(Exposer::GetInstance());
auto& histogram_family = BuildHistogram()
.Name("function_call_latency")
.Help("Time cost in the functinon, in us")
.Labels({{"label", "value"}})
.Register(*registry);
auto& histogram1 = histogram_family.Add(
{{"name", "foo"}},
Histogram::BucketBoundaries{1, 10, 50, 100, 1000, 5000, 10000, 50000, 100000, 500000, 10000000});
auto& histogram2 = histogram_family.Add(
{{"name", "bar"}},
Histogram::BucketBoundaries{1, 10, 50, 100, 1000, 5000, 10000, 50000, 100000, 500000, 10000000});
int main(int argc, char** argv) {
std::vector<std::thread> thrs;
thrs.emplace_back(std::thread([]() {
for (;;) {
prometheus::Marker marker(histogram1);
std::this_thread::sleep_for(std::chrono::milliseconds(rand() % 100));
}
}));
thrs.emplace_back(std::thread([]() {
for (;;) {
prometheus::Marker marker(histogram2);
std::this_thread::sleep_for(std::chrono::microseconds(rand() % 100));
}
}));
for (auto& t : thrs) {
t.join();
}
return 0;
}