File: gauge.h

package info (click to toggle)
golang-github-google-certificate-transparency 0.0~git20160709.0.0f6e3d1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,676 kB
  • sloc: cpp: 35,278; python: 11,838; java: 1,911; sh: 1,885; makefile: 950; xml: 520; ansic: 225
file content (85 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download
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
80
81
82
83
84
85
#ifndef CERT_TRANS_MONITORING_GAUGE_H_
#define CERT_TRANS_MONITORING_GAUGE_H_

#include <chrono>
#include <mutex>
#include <string>

#include "base/macros.h"
#include "monitoring/labelled_values.h"
#include "monitoring/metric.h"


namespace cert_trans {

// A metric whose values can go down as well as up (e.g. memory usage.)
template <class... LabelTypes>
class Gauge : public Metric {
 public:
  static Gauge<LabelTypes...>* New(
      const std::string& name,
      const typename NameType<LabelTypes>::name&... label_names,
      const std::string& help);

  double Get(const LabelTypes&...) const;

  void Set(const LabelTypes&... labels, double value);

  // TODO(alcutter): Not over the moon about having this here.
  std::map<std::vector<std::string>, Metric::TimestampedValue> CurrentValues()
      const override;

 private:
  Gauge(const std::string& name,
        const typename NameType<LabelTypes>::name&... label_names,
        const std::string& help);

  LabelledValues<LabelTypes...> values_;

  DISALLOW_COPY_AND_ASSIGN(Gauge);
};


// static
template <class... LabelTypes>
Gauge<LabelTypes...>* Gauge<LabelTypes...>::New(
    const std::string& name,
    const typename NameType<LabelTypes>::name&... label_names,
    const std::string& help) {
  return new Gauge(name, label_names..., help);
}


template <class... LabelTypes>
Gauge<LabelTypes...>::Gauge(
    const std::string& name,
    const typename NameType<LabelTypes>::name&... label_names,
    const std::string& help)
    : Metric(GAUGE, name, {label_names...}, help),
      values_(name, label_names...) {
}


template <class... LabelTypes>
double Gauge<LabelTypes...>::Get(const LabelTypes&... labels) const {
  return values_.Get(labels...);
}


template <class... LabelTypes>
void Gauge<LabelTypes...>::Set(const LabelTypes&... labels, double value) {
  values_.Set(labels..., value);
}


template <class... LabelTypes>
std::map<std::vector<std::string>, Metric::TimestampedValue>
Gauge<LabelTypes...>::CurrentValues() const {
  return values_.CurrentValues();
}


}  // namespace cert_trans


#endif  // CERT_TRANS_MONITORING_GAUGE_H_