File: exposer.h

package info (click to toggle)
prometheus-cpp 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: cpp: 3,596; sh: 37; makefile: 12
file content (57 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <cstddef>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <vector>

#include "prometheus/collectable.h"
#include "prometheus/detail/pull_export.h"

class CivetServer;
struct CivetCallbacks;

namespace prometheus {

namespace detail {
class Endpoint;
}  // namespace detail

class PROMETHEUS_CPP_PULL_EXPORT Exposer {
 public:
  explicit Exposer(const std::string& bind_address,
                   const std::size_t num_threads = 2,
                   const CivetCallbacks* callbacks = nullptr);
  explicit Exposer(std::vector<std::string> options,
                   const CivetCallbacks* callbacks = nullptr);
  ~Exposer();

  Exposer(const Exposer&) = delete;
  Exposer(Exposer&&) = delete;
  Exposer& operator=(const Exposer&) = delete;
  Exposer& operator=(Exposer&&) = delete;

  void RegisterCollectable(const std::weak_ptr<Collectable>& collectable,
                           const std::string& uri = std::string("/metrics"));

  void RegisterAuth(
      std::function<bool(const std::string&, const std::string&)> authCB,
      const std::string& realm = "Prometheus-cpp Exporter",
      const std::string& uri = std::string("/metrics"));

  void RemoveCollectable(const std::weak_ptr<Collectable>& collectable,
                         const std::string& uri = std::string("/metrics"));

  std::vector<int> GetListeningPorts() const;

 private:
  detail::Endpoint& GetEndpointForUri(const std::string& uri);

  std::unique_ptr<CivetServer> server_;
  std::vector<std::unique_ptr<detail::Endpoint>> endpoints_;
  std::mutex mutex_;
};

}  // namespace prometheus