Kagome
Polkadot Runtime Engine in C++17
handler_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_METRICS_IMPL_PROMETHEUS_HANDLER_IMPL_HPP
7 #define KAGOME_CORE_METRICS_IMPL_PROMETHEUS_HANDLER_IMPL_HPP
8 
9 #include <functional>
10 #include <memory>
11 #include <string_view>
12 
13 #include <prometheus/collectable.h>
14 #include "log/logger.hpp"
15 #include "metrics/handler.hpp"
16 
17 namespace kagome::metrics {
18 
19  class PrometheusHandler : public Handler {
20  public:
21  explicit PrometheusHandler();
22  ~PrometheusHandler() override = default;
23 
24  void registerCollectable(Registry &registry) override;
25 
27  std::shared_ptr<Session> session) override;
28 
29  private:
31  const std::weak_ptr<prometheus::Collectable> &collectable);
32  void removeCollectable(
33  const std::weak_ptr<prometheus::Collectable> &collectable);
34  static void cleanupStalePointers(
35  std::vector<std::weak_ptr<prometheus::Collectable>> &collectables);
36  std::size_t writeResponse(std::shared_ptr<Session> session,
37  Session::Request request,
38  const std::string &body);
39 
40  std::mutex collectables_mutex_;
41  std::vector<std::weak_ptr<prometheus::Collectable>> collectables_;
42 
44  };
45 
46 } // namespace kagome::metrics
47 
48 #endif // KAGOME_CORE_METRICS_IMPL_HANDLER_IMPL_HPP
an interface to add request handler for metrics::Exposer implementation generally will contain metric...
Definition: handler.hpp:22
std::size_t writeResponse(std::shared_ptr< Session > session, Session::Request request, const std::string &body)
boost::beast::http::request< Body > Request
Definition: session.hpp:22
std::vector< std::weak_ptr< prometheus::Collectable > > collectables_
void removeCollectable(const std::weak_ptr< prometheus::Collectable > &collectable)
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
~PrometheusHandler() override=default
void onSessionRequest(Session::Request request, std::shared_ptr< Session > session) override
main interface for session request handling
void registerCollectable(Registry &registry) override
registers general type metrics registry for metrics collection
static void cleanupStalePointers(std::vector< std::weak_ptr< prometheus::Collectable >> &collectables)
the class stores metrics, provides interface to create metrics and families of metrics TODO(sanblch) ...
Definition: registry.hpp:30