Prometheus Client Library for Modern C++
Loading...
Searching...
No Matches
handler.h
1#pragma once
2
3#include <memory>
4#include <mutex>
5#include <vector>
6
7#include "CivetServer.h"
8#include "prometheus/collectable.h"
9#include "prometheus/counter.h"
10#include "prometheus/family.h"
11#include "prometheus/registry.h"
12#include "prometheus/summary.h"
13
14namespace prometheus::detail {
15class MetricsHandler : public CivetHandler {
16 public:
17 explicit MetricsHandler(Registry& registry);
18
19 void RegisterCollectable(const std::weak_ptr<Collectable>& collectable);
20 void RemoveCollectable(const std::weak_ptr<Collectable>& collectable);
21
22 bool handleGet(CivetServer* server, struct mg_connection* conn) override;
23
24 private:
25 static void CleanupStalePointers(
26 std::vector<std::weak_ptr<Collectable>>& collectables);
27
28 std::mutex collectables_mutex_;
29 std::vector<std::weak_ptr<Collectable>> collectables_;
30 Family<Counter>& bytes_transferred_family_;
31 Counter& bytes_transferred_;
32 Family<Counter>& num_scrapes_family_;
33 Counter& num_scrapes_;
34 Family<Summary>& request_latencies_family_;
35 Summary& request_latencies_;
36};
37} // namespace prometheus::detail