-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathDPLMonitoringBackend.cxx
More file actions
82 lines (72 loc) · 2.65 KB
/
DPLMonitoringBackend.cxx
File metadata and controls
82 lines (72 loc) · 2.65 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
// 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.
#include "DPLMonitoringBackend.h"
#include "Framework/DriverClient.h"
#include "Framework/ServiceRegistry.h"
#include <fmt/format.h>
#include <sstream>
namespace o2::framework
{
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
inline unsigned long DPLMonitoringBackend::convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp)
{
return std::chrono::duration_cast<std::chrono::milliseconds>(
timestamp.time_since_epoch())
.count();
}
DPLMonitoringBackend::DPLMonitoringBackend(ServiceRegistry& registry)
: mRegistry{registry}
{
}
void DPLMonitoringBackend::addGlobalTag(std::string_view name, std::string_view value)
{
// FIXME: tags are ignored by DPL in any case...
mTagString += fmt::format("{}{}={}", mTagString.empty() ? "" : ",", name.data(), value);
}
void DPLMonitoringBackend::send(std::vector<o2::monitoring::Metric>&& metrics)
{
for (auto& m : metrics) {
send(m);
}
}
void DPLMonitoringBackend::send(o2::monitoring::Metric const& metric)
{
std::ostringstream mStream;
mStream << "[METRIC] " << metric.getName();
for (auto& value : metric.getValues()) {
auto stringValue = std::visit(overloaded{
[](const std::string& value) -> std::string { return value; },
[](auto value) -> std::string { return std::to_string(value); }},
value.second);
if (metric.getValuesSize() == 1) {
mStream << ',' << metric.getFirstValueType() << ' ' << stringValue;
} else {
mStream << ' ' << value.first << '=' << stringValue;
}
}
// FIXME: tags are ignored by the DPL backend in any case...
mStream << ' ' << convertTimestamp(metric.getTimestamp()) << ' ' << mTagString;
bool first = mTagString.empty();
for (const auto& [key, value] : metric.getTags()) {
if (!first) {
mStream << ',';
}
first = true;
mStream << o2::monitoring::tags::TAG_KEY[key] << "=" << o2::monitoring::tags::GetValue(value);
}
mStream << '\n';
mRegistry.get<framework::DriverClient>().tell(mStream.str());
}
} // namespace o2::framework