Skip to content

Commit f974016

Browse files
authored
Zabbix: multiple metrics support; connection issue resolved (#16)
1 parent 3af3d2d commit f974016

File tree

14 files changed

+123
-49
lines changed

14 files changed

+123
-49
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Metric can be sent by one of the following ways:
156156
+ `send(T value, std::string name)`
157157
+ `sendTagged(T value, std::string name, std::vector<Tag>&& tags)`
158158
+ `sendTimed(T value, std::string name, std::chrono::time_point<std::chrono::system_clock>& timestamp)`
159+
3. Sending multiple metrics (only InfluxDB and Zabbix are supported, other backends fallback into sending metrics one by one)
160+
+ `void send(std::string name, std::vector<Metric>&& metrics)`
159161

160162
## Derived metrics
161163
The module can calculate derived metrics. To do so, use `addDerivedMetric(std::string name, DerivedMetricMode mode)` with one of two available modes:
@@ -303,6 +305,17 @@ collector->send(10, "myMetric");
303305
collector->send({10, "myMetric"});
304306
```
305307
308+
### Sending multiple metrics at once - examples/8-Multiple.cxx
309+
```cpp
310+
// configure monitoring (only once per process), pass configuration path as parameter
311+
Monitoring::Configure("file:///home/awegrzyn/hackathon/Monitoring/examples/config-default.ini");
312+
313+
// Send two metrics at once as a single measurement
314+
Monitoring::Get().send("measurementName", {
315+
{10, "myMetricInt"},
316+
{10.10, "myMetricFloat"}
317+
});
318+
```
306319

307320
## System monitoring, server-side backends installation and configuration
308321
This guide explains manual installation. For `ansible` deployment see [AliceO2Group/system-configuration](https://gitlab.cern.ch/AliceO2Group/system-configuration/tree/master/ansible) gitlab repo.

include/Monitoring/Backend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Backend
3232
/// Sends metric via backend
3333
virtual void send(const Metric& metric) = 0;
3434

35+
/// Sends multiple metrics (if supported), otherwise falls back into sending single metrics
36+
virtual void sendMultiple(std::string measurement, std::vector<Metric>&& metrics) = 0;
37+
3538
/// Sets a tag
3639
virtual void addGlobalTag(std::string name, std::string value) = 0;
3740
};

include/Monitoring/Collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Collector
5656
/// Sends a metric to all avaliabes backends
5757
/// If metric has been added to DerivedMetric the derived metric is calculated (see addDerivedMetric method)
5858
/// \param metric r-value to metric object
59-
void send(Metric&& metric, std::size_t skipBackend = -1);
59+
void send(Metric&& metric);
6060

6161
/// Sends multiple metrics to as a single measurement
6262
/// If it's not supported by backend it fallbacks into sending multiple metrics

src/Backends/ApMonBackend.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ void ApMonBackend::addGlobalTag(std::string name, std::string value)
4242
entity += value;
4343
}
4444

45+
void ApMonBackend::sendMultiple(std::string measurement, std::vector<Metric>&& metrics)
46+
{
47+
for (auto& m : metrics) {
48+
std::string tempName = m.getName();
49+
m.setName(measurement + "-" + m.getName());
50+
send(m);
51+
m.setName(tempName);
52+
}
53+
}
54+
4555
void ApMonBackend::send(const Metric& metric)
4656
{
4757
std::string name = metric.getName();

src/Backends/ApMonBackend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class ApMonBackend final : public Backend
4242
/// \param metric reference to metric object:
4343
void send(const Metric& metric) override;
4444

45+
/// Sends multiple metric in single packet
46+
/// Not supported by the backend therefore it falls back to sending metric one by one
47+
/// \param name measurement name
48+
/// \param metrics list of metrics
49+
void sendMultiple(std::string measurement, std::vector<Metric>&& metrics) override;
50+
4551
/// Extends entity value
4652
/// \param name tag name (unused)
4753
/// \param value tag value that is concatenated to entity string

src/Backends/Flume.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ std::string Flume::metricToJson(const Metric& metric)
4545
return s;
4646
}
4747

48+
void Flume::sendMultiple(std::string measurement, std::vector<Metric>&& metrics)
49+
{
50+
for (auto& m : metrics) {
51+
std::string tempName = m.getName();
52+
m.setName(measurement + "-" + m.getName());
53+
send(m);
54+
m.setName(tempName);
55+
}
56+
}
57+
4858
void Flume::send(const Metric& metric)
4959
{
5060
mTransport->send(metricToJson(metric));

src/Backends/Flume.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Flume final : public Backend
3737
/// Default destructor
3838
~Flume() = default;
3939

40-
// Convert timestamp to unsigned long as required by Flume
40+
/// Convert timestamp to unsigned long as required by Flume
4141
/// \param chrono time_point timestamp
4242
/// \return timestamp in nanoseconds
4343
inline unsigned long convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp);
@@ -46,6 +46,13 @@ class Flume final : public Backend
4646
/// \param metric reference to metric object
4747
void send(const Metric& metric) override;
4848

49+
/// Sends multiple metric in single packet
50+
/// Not supported by the backend therefore it falls back to sending metric one by one
51+
/// TODO: changed required in Flume Source
52+
/// \param name measurement name
53+
/// \param metrics list of metrics
54+
void sendMultiple(std::string measurement, std::vector<Metric>&& metrics) override;
55+
4956
/// Adds tag
5057
/// \param name tag name
5158
/// \param value tag value

src/Backends/InfluxDB.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ void InfluxDB::escape(std::string& escaped)
4949
boost::replace_all(escaped, " ", "\\ ");
5050
}
5151

52-
void InfluxDB::sendMultiple(std::string name, std::vector<Metric>&& metrics)
52+
void InfluxDB::sendMultiple(std::string measurement, std::vector<Metric>&& metrics)
5353
{
54-
escape(name);
54+
escape(measurement);
5555
std::stringstream convert;
56-
convert << name << "," << tagSet << " ";
56+
convert << measurement << "," << tagSet << " ";
5757

5858
for (const auto& metric : metrics) {
5959
std::string value = boost::lexical_cast<std::string>(metric.getValue());

src/Backends/InfluxDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class InfluxDB final : public Backend
5353
/// Sends multiple values in single measurement
5454
/// \param name measurement name
5555
/// \param metrics list of metrics
56-
void sendMultiple(std::string name, std::vector<Metric>&& metrics);
56+
void sendMultiple(std::string measurement, std::vector<Metric>&& metrics);
5757

5858
/// Adds tag
5959
/// \param name tag name

src/Backends/InfoLoggerBackend.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ void InfoLoggerBackend::addGlobalTag(std::string name, std::string value)
3737
tagString += name + "=" + value;
3838
}
3939

40+
void InfoLoggerBackend::sendMultiple(std::string measurement, std::vector<Metric>&& metrics)
41+
{
42+
for (auto& m : metrics) {
43+
std::string tempName = m.getName();
44+
m.setName(measurement + "-" + m.getName());
45+
send(m);
46+
m.setName(tempName);
47+
}
48+
}
49+
4050
void InfoLoggerBackend::send(const Metric& metric)
4151
{
4252
std::string metricTags{};

0 commit comments

Comments
 (0)