-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMetric.cxx
More file actions
167 lines (139 loc) · 4.51 KB
/
Metric.cxx
File metadata and controls
167 lines (139 loc) · 4.51 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file Metric.cxx
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
///
#include "Monitoring/Metric.h"
#include <iostream>
#include <chrono>
#include <memory>
namespace o2
{
/// ALICE O2 Monitoring system
namespace monitoring
{
std::chrono::time_point<std::chrono::system_clock> Metric::getTimestamp() const
{
return mTimestamp;
}
const std::string& Metric::getName() const
{
return mName;
}
Metric::Metric(int value, const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
{
overwriteVerbosity();
addValue(value, Metric::mDefaultValueName);
}
Metric::Metric(std::string value, const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
{
overwriteVerbosity();
addValue(value, Metric::mDefaultValueName);
}
Metric::Metric(double value, const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
{
overwriteVerbosity();
addValue(value, Metric::mDefaultValueName);
}
Metric::Metric(uint64_t value, const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
{
overwriteVerbosity();
addValue(value, Metric::mDefaultValueName);
}
Metric&& Metric::addValue(int value, const std::string& name)
{
mValues.push_back({name, value});
return std::move(*this);
}
Metric&& Metric::addValue(double value, const std::string& name)
{
mValues.push_back({name, value});
return std::move(*this);
}
Metric&& Metric::addValue(uint64_t value, const std::string& name)
{
mValues.push_back({name, value});
return std::move(*this);
}
Metric&& Metric::addValue(std::string value, const std::string& name)
{
mValues.push_back({name, value});
return std::move(*this);
}
Metric&& Metric::addValue(const std::variant<int, std::string, double, uint64_t>& value, const std::string& name)
{
mValues.push_back({name, value});
return std::move(*this);
}
Metric::Metric(const std::string& name, Verbosity verbosity, const std::chrono::time_point<std::chrono::system_clock>& timestamp) : mName(name), mTimestamp(timestamp), mVerbosity(verbosity)
{
overwriteVerbosity();
}
Verbosity Metric::getVerbosity()
{
return mVerbosity;
}
void Metric::setVerbosityPolicy(Verbosity verbosity, const std::regex& regex)
{
mRegexPolicy.insert({static_cast<std::underlying_type<tags::Value>::type>(verbosity), regex});
}
void Metric::overwriteVerbosity()
{
for (auto const& [verbosity, regex] : mRegexPolicy) {
if (std::regex_match(mName, regex)) {
mVerbosity = static_cast<Verbosity>(verbosity);
}
}
}
Metric&& Metric::addTag(tags::Key key, tags::Value value)
{
mTags.push_back({static_cast<std::underlying_type<tags::Key>::type>(key), static_cast<std::underlying_type<tags::Value>::type>(value)});
return std::move(*this);
}
Metric&& Metric::addTag(tags::Key key, unsigned short number)
{
mTags.push_back({static_cast<std::underlying_type<tags::Key>::type>(key), 0 - number});
return std::move(*this);
}
Metric&& Metric::setTags(std::vector<std::pair<int, int>>&& tags)
{
mTags = std::move(tags);
return std::move(*this);
}
const std::vector<std::pair<int, int>>& Metric::getTags() const
{
return mTags;
}
auto Metric::getCurrentTimestamp() -> decltype(std::chrono::system_clock::now())
{
return std::chrono::system_clock::now();
}
void Metric::setDefaultVerbosity(Verbosity verbosity)
{
Metric::DefaultVerbosity = verbosity;
}
const std::vector<std::pair<std::string, std::variant<int, std::string, double, uint64_t>>>& Metric::getValues() const
{
return mValues;
}
const std::pair<std::string, std::variant<int, std::string, double, uint64_t>>& Metric::getFirstValue() const
{
return mValues.front();
}
std::size_t Metric::getValuesSize() const noexcept
{
return mValues.size();
}
bool Metric::includeTimestamp = true;
Verbosity Metric::DefaultVerbosity = Verbosity::Info;
std::map<std::underlying_type<Verbosity>::type, std::regex> Metric::mRegexPolicy;
} // namespace monitoring
} // namespace o2