Prometheus Client Library for Modern C++
Loading...
Searching...
No Matches
exposer.h
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <memory>
6#include <mutex>
7#include <string>
8#include <vector>
9
10#include "prometheus/collectable.h"
11#include "prometheus/detail/pull_export.h"
12
13class CivetServer;
14struct CivetCallbacks;
15
16namespace prometheus {
17
18namespace detail {
19class Endpoint;
20} // namespace detail
21
22class PROMETHEUS_CPP_PULL_EXPORT Exposer {
23 public:
24 explicit Exposer(const std::string& bind_address,
25 const std::size_t num_threads = 2,
26 const CivetCallbacks* callbacks = nullptr);
27 explicit Exposer(std::vector<std::string> options,
28 const CivetCallbacks* callbacks = nullptr);
29 ~Exposer();
30
31 Exposer(const Exposer&) = delete;
32 Exposer(Exposer&&) = delete;
33 Exposer& operator=(const Exposer&) = delete;
34 Exposer& operator=(Exposer&&) = delete;
35
36 void RegisterCollectable(const std::weak_ptr<Collectable>& collectable,
37 const std::string& uri = std::string("/metrics"));
38
39 void RegisterAuth(
40 std::function<bool(const std::string&, const std::string&)> authCB,
41 const std::string& realm = "Prometheus-cpp Exporter",
42 const std::string& uri = std::string("/metrics"));
43
44 void RemoveCollectable(const std::weak_ptr<Collectable>& collectable,
45 const std::string& uri = std::string("/metrics"));
46
47 std::vector<int> GetListeningPorts() const;
48
49 private:
50 detail::Endpoint& GetEndpointForUri(const std::string& uri);
51
52 std::unique_ptr<CivetServer> server_;
53 std::vector<std::unique_ptr<detail::Endpoint>> endpoints_;
54 std::mutex mutex_;
55};
56
57} // namespace prometheus
Definition exposer.h:22