add header-only prometheus lib to ext

This commit is contained in:
Grant Limberg 2023-04-10 11:31:56 -07:00
parent 2115b18ae3
commit a5c212ce64
No known key found for this signature in database
GPG key ID: 8F2F97D3BE8D7735
45 changed files with 3764 additions and 0 deletions

View file

@ -0,0 +1,59 @@
#include <prometheus/registry.h>
#include <prometheus/benchmark.h>
#include <prometheus/text_serializer.h>
#include <array>
#include <chrono>
#include <cstdlib>
#include <memory>
#include <string>
#include <thread>
#include <iostream>
// use prometheus namespace
using namespace prometheus;
// create global registry for use it from our classes
static Registry globalRegistry;
class MyClass {
Benchmark::Family& benchmarkFamily { Benchmark::Family::Build(globalRegistry,
"benchmark_family", "family for check benchmark functionality") };
Benchmark& benchmark1 { benchmarkFamily.Add({{"number", "1"}}) };
Benchmark& benchmark2 { benchmarkFamily.Add({{"number", "2"}}) };
public:
MyClass() = default;
void member_to_do_something() {
benchmark1.start();
benchmark2.start();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
benchmark1.stop();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
benchmark2.stop();
}
};
int main() {
MyClass myClass;
for (;; ) {
std::this_thread::sleep_for(std::chrono::seconds(1));
myClass.member_to_do_something();
TextSerializer text_serializer;
text_serializer.Serialize(std::cout, globalRegistry.Collect());
}
}