File: gateway.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 (79 lines) | stat: -rw-r--r-- 2,075 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <future>
#include <memory>
#include <mutex>
#include <string>
#include <utility>
#include <vector>

#include "prometheus/collectable.h"
#include "prometheus/detail/http_method.h"
#include "prometheus/detail/push_export.h"
#include "prometheus/labels.h"

namespace prometheus {

namespace detail {
class CurlWrapper;
}

class PROMETHEUS_CPP_PUSH_EXPORT Gateway {
 public:
  Gateway(const std::string& host, const std::string& port,
          const std::string& jobname, const Labels& labels = {},
          const std::string& username = {}, const std::string& password = {});

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

  ~Gateway();

  void RegisterCollectable(const std::weak_ptr<Collectable>& collectable,
                           const Labels* labels = nullptr);

  static Labels GetInstanceLabel(std::string hostname);

  // Push metrics to the given pushgateway.
  int Push();

  std::future<int> AsyncPush();

  // PushAdd metrics to the given pushgateway.
  int PushAdd();

  std::future<int> AsyncPushAdd();

  // Delete metrics from the given pushgateway.
  int Delete();

  // Delete metrics from the given pushgateway.
  std::future<int> AsyncDelete();

  // Delete metrics from the given pushgateway (for configured instance labels).
  int DeleteForInstance();

  // Delete metrics from the given pushgateway (for configured instance labels).
  std::future<int> AsyncDeleteForInstance();

 private:
  std::string jobUri_;
  std::string labels_;
  std::unique_ptr<detail::CurlWrapper> curlWrapper_;
  std::mutex mutex_;

  using CollectableEntry = std::pair<std::weak_ptr<Collectable>, std::string>;
  std::vector<CollectableEntry> collectables_;

  std::string getUri(const CollectableEntry& collectable) const;

  int push(detail::HttpMethod method);

  std::future<int> async_push(detail::HttpMethod method);

  static void CleanupStalePointers(std::vector<CollectableEntry>& collectables);
};

}  // namespace prometheus