Skip to content

Commit 55033b8

Browse files
authored
Add concept of run number (#234)
1 parent ad665d1 commit 55033b8

File tree

10 files changed

+60
-15
lines changed

10 files changed

+60
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ endif()
1717

1818
# Define project
1919
project(Monitoring
20-
VERSION 3.6.0
20+
VERSION 3.7.0
2121
DESCRIPTION "O2 Monitoring library"
2222
LANGUAGES CXX
2323
)
@@ -188,6 +188,7 @@ set(EXAMPLES
188188
examples/6-Increment.cxx
189189
examples/7-InternalBenchamrk.cxx
190190
examples/8-DbFiller.cxx
191+
examples/9-RunNumber.cxx
191192
examples/10-Buffering.cxx
192193
)
193194

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Metric{"name"}.addValue(10, "value")
8080
```
8181
8282
#### Tags
83+
1. Metric tags
8384
Each metric can be tagged with any number of [predefined tags](include/Monitoring/Tags.h).
8485
In order to do so use `addTag(tags::Key, tags::Value)` or `addTag(tags::Key, unsigned short)` methods. The latter method allows assigning numeric value to a tag.
8586
@@ -89,6 +90,15 @@ Metric{10, "name"}.addTag(tags::Key::Subsystem, tags::Value::QC)
8990

9091
See the example: [examples/2-TaggedMetrics.cxx](examples/2-TaggedMetrics.cxx).
9192

93+
2. Global tags
94+
Global tags are added to each metric sent eg. `hostname` tag is added by default by the library.
95+
96+
You can add your own global tag by calling `addGlobalTag(std::string_view key, std::string_view value)` or `addGlobalTag(tags::Key, tags::Value)` on Monitoring object.
97+
98+
3. Run number
99+
Run number is special case of a global tag, its value can be overwritten at any time, therefore it benefits simplified handling: `setRunNumber(uint32_t)`
100+
101+
92102
### Sending metric
93103
Pass metric object to `send` method as l-value reference:
94104
```cpp
@@ -137,11 +147,6 @@ The derived value is generated only from the first value of the metric and it is
137147
138148
See how it works in the example: [examples/4-RateDerivedMetric.cxx](examples/4-RateDerivedMetric.cxx).
139149
140-
### Global tags
141-
Global tags are added to each metric sent using given monitoring instance. `hostname` is set as global by default.
142-
143-
You can add your own global tag by calling `addGlobalTag(std::string_view key, std::string_view value)` or `addGlobalTag(tags::Key, tags::Value)`.
144-
145150
### Process monitoring
146151
147152
This feature provides basic performance status of the process. Note that is runs in separate thread (without mutex).

examples/9-RunNumber.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
///
2+
/// \file 9-RunNumber.cxx
3+
/// \author Adam Wegrzynek <[email protected]>
4+
///
5+
6+
#include "Monitoring/MonitoringFactory.h"
7+
8+
using namespace o2::monitoring;
9+
10+
int main()
11+
{
12+
13+
// Configure monitoring
14+
// Pass string with list of URLs as parameter
15+
auto monitoring = MonitoringFactory::Get("influxdb-stdout://");
16+
17+
monitoring->send(Metric{10, "myMetric"});
18+
monitoring->setRunNumber(1);
19+
monitoring->send(Metric{10, "myMetric"});
20+
monitoring->setRunNumber(2);
21+
monitoring->send(Metric{10, "myMetric"});
22+
}

include/Monitoring/Backend.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ class Backend
3535
private:
3636
/// Verbosity level
3737
Verbosity verbosityLevel;
38+
protected:
39+
/// Run number
40+
uint32_t mRunNumber;
3841

3942
public:
4043
/// Default constructor
41-
Backend() { verbosityLevel = Verbosity::Info; }
44+
Backend() {
45+
mRunNumber = 0;
46+
verbosityLevel = Verbosity::Info;
47+
}
48+
49+
/// Run number setter
50+
void setRunNumber(uint32_t runNumber) {
51+
mRunNumber = runNumber;
52+
}
4253

4354
/// Default destructor
4455
virtual ~Backend() = default;

include/Monitoring/Monitoring.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ class Monitoring
8888
/// \param value tag value
8989
void addGlobalTag(tags::Key key, tags::Value value);
9090

91-
/// Returns a metric which will be periodically sent to backends
92-
/// \param name metric name
93-
/// \return periodically send metric
94-
//ComplexMetric& getAutoPushMetric(std::string name, unsigned int interval = 1);
95-
91+
/// Sets run number
92+
/// \param name run run number
93+
void setRunNumber(uint32_t run);
9694
private:
9795
/// Sends multiple (not related to each other) metrics
9896
/// \param metrics vector of metrics

include/Monitoring/Tags.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ enum class Key : unsigned short int {
3939
FLP,
4040
EPN,
4141
Unit,
42-
Run,
4342
ID,
4443
Type,
4544
CRORC,
@@ -48,7 +47,7 @@ enum class Key : unsigned short int {
4847
};
4948

5049
/// Tag keys array
51-
static constexpr std::array<std::string_view, 15> TAG_KEY = {
50+
static constexpr std::array<std::string_view, 14> TAG_KEY = {
5251
"hostname"sv,
5352
"rolenane"sv,
5453
"name"sv,
@@ -58,7 +57,6 @@ static constexpr std::array<std::string_view, 15> TAG_KEY = {
5857
"FLP"sv,
5958
"EPN"sv,
6059
"unit"sv,
61-
"run"sv,
6260
"id"sv,
6361
"type"sv,
6462
"CRORC"sv,

src/Backends/ApMonBackend.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void ApMonBackend::send(const Metric& metric)
6868
entity += '=';
6969
(value > 0) ? entity += tags::GetValue(value) : entity += std::to_string(0 - value);
7070
}
71+
if (mRunNumber != 0) convert << ",run=" << mRunNumber;
7172

7273
int valueSize = metric.getValuesSize();
7374
char **paramNames, **paramValues;

src/Backends/InfluxDB.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ std::string InfluxDB::toInfluxLineProtocol(const Metric& metric)
8585
convert << "," << tags::TAG_KEY[key] << "=";
8686
(value > 0) ? convert << tags::GetValue(value) : convert << (0 - value);
8787
}
88+
if (mRunNumber != 0) convert << ",run=" << mRunNumber;
8889
convert << ' ';
8990
for (const auto& [name, value] : metric.getValues()) {
9091
convert << name << '=';

src/Backends/StdOut.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void StdOut::send(const Metric& metric)
8484
convert << ',' << tags::TAG_KEY[key] << "=";
8585
(value > 0) ? convert << tags::GetValue(value) : convert << (0 - value);
8686
}
87+
if (mRunNumber != 0) convert << ",run=" << mRunNumber;
8788
convert << '\n';
8889
std::cout << convert.str();
8990
}

src/Monitoring.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ void Monitoring::addGlobalTag(tags::Key key, tags::Value value)
110110
}
111111
}
112112

113+
void Monitoring::setRunNumber(uint32_t run)
114+
{
115+
for (auto& backend : mBackends) {
116+
backend->setRunNumber(run);
117+
}
118+
}
119+
113120
void Monitoring::addBackend(std::unique_ptr<Backend> backend)
114121
{
115122
ProcessDetails processDetails{};

0 commit comments

Comments
 (0)