Reputation: 2053
I am trying to get the required prometheus metrics values using c++ code. For example, i need to execute the currently running metrics query "go_gc_duration_seconds{quantile="0"}" using c++ code and get the value of the query. If somebody having sample projects kindly share and assist me.
Upvotes: 1
Views: 3806
Reputation: 217
It seems that you'll need to make the http request, and parse the json to extract the results. This can be done quite easily using e.g.
Upvotes: 0
Reputation: 11
The way I get prometheus metrics using c++ is like this:
Select a client library for modern c++, https://github.com/jupp0r/prometheus-cpp it is a good choice.
Create a exposer(actually a http server), like Exposer exposer{"127.0.0.1:8080"};
Create a metrics registry, like auto registry = std::make_shared<Registry>();
Set value or get value
std::map<std::string, std::string> labels; labels.insert(make_pair("quantile", "0")); auto &counter_family = BuildCounter().Name('go_gc_duration_seconds').Register(*registry_ptr_); auto &metric_counter = counter_family.Add(labels);
we can use http api to get value.
Upvotes: 1