mirror of
https://github.com/openappsec/openappsec.git
synced 2025-11-16 01:12:18 +03:00
Feb 10 2025 dev (#255)
* sync code * sync code * code sync * code sync --------- Co-authored-by: Ned Wright <nedwright@proton.me> Co-authored-by: Daniel Eisenberg <danielei@checkpoint.com>
This commit is contained in:
50
core/metric/metric_scraper.cc
Normal file
50
core/metric/metric_scraper.cc
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "metric/metric_scraper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_METRICS);
|
||||
|
||||
class MetricScraper::Impl
|
||||
{
|
||||
public:
|
||||
void
|
||||
init()
|
||||
{
|
||||
Singleton::Consume<I_RestApi>::by<MetricScraper>()->addGetCall(
|
||||
"service-metrics",
|
||||
[&] () { return getAllPrometheusMetrics(); }
|
||||
);
|
||||
}
|
||||
|
||||
string
|
||||
getAllPrometheusMetrics()
|
||||
{
|
||||
auto all_metrics_events_res = MetricScrapeEvent().query();
|
||||
for (auto metric_vec : all_metrics_events_res) {
|
||||
for (PrometheusData metric : metric_vec) {
|
||||
metric.label = "{" + metric.label + "}";
|
||||
all_metrics.emplace_back(metric);
|
||||
}
|
||||
}
|
||||
stringstream ss;
|
||||
{
|
||||
cereal::JSONOutputArchive archive(ss);
|
||||
archive(cereal::make_nvp("metrics", all_metrics));
|
||||
}
|
||||
all_metrics.clear();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
vector<PrometheusData> all_metrics;
|
||||
};
|
||||
|
||||
MetricScraper::MetricScraper() : Component("MetricScraper"), pimpl(make_unique<MetricScraper::Impl>()) {}
|
||||
|
||||
MetricScraper::~MetricScraper() {}
|
||||
|
||||
void
|
||||
MetricScraper::init()
|
||||
{
|
||||
pimpl->init();
|
||||
}
|
||||
Reference in New Issue
Block a user