Monitoring  3.3.4
O2 Monitoring library
Metric.h
Go to the documentation of this file.
1 
6 #ifndef ALICEO2_MONITORING_CORE_METRIC_H
7 #define ALICEO2_MONITORING_CORE_METRIC_H
8 
9 #include <string>
10 #include <chrono>
11 #include <map>
12 #include <regex>
13 #include <variant>
14 #include <vector>
15 #include "Tags.h"
16 
17 namespace o2
18 {
20 namespace monitoring
21 {
22 
24 enum class Verbosity : short { Prod,
25  Info,
26  Debug };
27 
29 enum MetricType { INT = 0,
30  STRING = 1,
31  DOUBLE = 2,
32  UINT64_T = 3 };
33 
34 class DerivedMetrics;
35 
37 class Metric
38 {
39  public:
43  Metric(int value, const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity);
44 
48  Metric(std::string value, const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity);
49 
53  Metric(double value, const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity);
54 
58  Metric(uint64_t value, const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity);
59 
62  Metric(const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity, const std::chrono::time_point<std::chrono::system_clock>& timestamp = Metric::getCurrentTimestamp());
63 
67  Metric&& addValue(int value, const std::string& name);
68 
72  Metric&& addValue(double value, const std::string& name);
73 
77  Metric&& addValue(uint64_t value, const std::string& name);
78 
82  Metric&& addValue(std::string value, const std::string& name);
83 
87  Metric&& addValue(const std::variant<int, std::string, double, uint64_t>& value, const std::string& name);
88 
90  ~Metric() = default;
91 
94  const std::string& getName() const;
95 
98  std::chrono::time_point<std::chrono::system_clock> getTimestamp() const;
99 
102  const std::vector<std::pair<std::string, std::variant<int, std::string, double, uint64_t>>>& getValues() const;
103 
106  const std::pair<std::string, std::variant<int, std::string, double, uint64_t>>& getFirstValue() const;
107 
109  std::size_t getValuesSize() const noexcept;
110 
113  const std::vector<std::pair<int, int>>& getTags() const;
114 
119  Metric&& addTag(tags::Key key, tags::Value value);
120 
125  Metric&& addTag(tags::Key key, unsigned short int number);
126 
128  Verbosity getVerbosity();
129 
132  static auto getCurrentTimestamp() -> decltype(std::chrono::system_clock::now());
133 
135  static void setDefaultVerbosity(Verbosity verbosity);
136 
139 
141  static void setVerbosityPolicy(Verbosity verbosity, const std::regex& regex);
142 
144  static bool includeTimestamp;
145 
147  int getFirstValueType() const;
148 
149  protected:
152 
154  Metric&& setTags(std::vector<std::pair<int, int>>&& tags);
155 
157  std::vector<std::pair<std::string, std::variant<int, std::string, double, uint64_t>>> mValues;
158 
160  std::string mName;
161 
163  std::chrono::time_point<std::chrono::system_clock> mTimestamp;
164 
166  std::vector<std::pair<int, int>> mTags;
167 
170 
172  static std::map<std::underlying_type<Verbosity>::type, std::regex> mRegexPolicy;
173 
175  void overwriteVerbosity();
176 
178  static constexpr char mDefaultValueName[] = "value";
179 };
180 
181 } // namespace monitoring
182 } // namespace o2
183 
184 #endif // ALICEO2_MONITORING_CORE_METRIC_H
static auto getCurrentTimestamp() -> decltype(std::chrono::system_clock::now())
Definition: Metric.cxx:137
Definition: Backend.h:23
std::string mName
Metric name.
Definition: Metric.h:160
std::vector< std::pair< int, int > > mTags
Metric tags.
Definition: Metric.h:166
MetricType
Metric types.
Definition: Metric.h:29
static bool includeTimestamp
Whether timestamp should be included or not.
Definition: Metric.h:144
Verbosity
Metric and Backedn verbosity.
Definition: Metric.h:24
Enables Calculation of derived metrics.
Definition: DerivedMetrics.h:41
Represents a metric including value, type of the value, name, timestamp and tags. ...
Definition: Metric.h:37
static std::map< std::underlying_type< Verbosity >::type, std::regex > mRegexPolicy
Regex policy map.
Definition: Metric.h:172
static Verbosity DefaultVerbosity
Default metric verbosity.
Definition: Metric.h:138
std::chrono::time_point< std::chrono::system_clock > mTimestamp
Metric timestamp.
Definition: Metric.h:163
Verbosity mVerbosity
Metric verbosity.
Definition: Metric.h:169
std::vector< std::pair< std::string, std::variant< int, std::string, double, uint64_t > > > mValues
Metric values.
Definition: Metric.h:157