handler.h 1.1 KB

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