Skip to content

Commit ded653c

Browse files
authored
Add addGlobalTag (#55)
1 parent 71edd62 commit ded653c

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ The module can calculate derived metrics. To do so, use `addDerivedMetric(std::s
185185

186186
Derived metrics are generated each time as new value is passed to the module. Their names are suffixed with derived mode name.
187187

188+
### Global tags
189+
Glabal tags are tags that are added to each metric. The following tags are set to global by library itself:
190+
- `hostname`
191+
- `name` - process name
192+
193+
You can add your own global tag by calling `addGlobalTag(std::string name, std::string value)`.
194+
188195
### Monitoring process
189196
Currently process monitoring is supported only on Linux. To enable it use:
190197
```cpp

include/Monitoring/Monitoring.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class Monitoring
8787
/// Enables metric buffering
8888
/// \param size buffer size
8989
void enableBuffering(const unsigned int size = 20);
90+
91+
/// Adds global tag
92+
/// \param name tag name
93+
/// \param value tag value
94+
void addGlobalTag(std::string name, std::string value);
9095
private:
9196
/// Derived metrics handler
9297
/// \see class DerivedMetrics

src/Monitoring.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ void Monitoring::stopAndSendTimer(std::string name) {
9090
}
9191
}
9292

93+
void Monitoring::addGlobalTag(std::string name, std::string value)
94+
{
95+
for (auto& backend: mBackends) {
96+
backend->addGlobalTag(name, value);
97+
}
98+
}
99+
93100
void Monitoring::addBackend(std::unique_ptr<Backend> backend) {
94101
ProcessDetails processDetails{};
95102
backend->addGlobalTag("hostname", processDetails.getHostname());

test/testMonitoring.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ BOOST_AUTO_TEST_CASE(createMonitoring)
2222
std::string stringMetric("monitoringString");
2323
double doubleMetric = static_cast <double> (rand()) / static_cast <double> (RAND_MAX);
2424

25+
monitoring->addGlobalTag("device", "sampleDevice");
26+
2527
monitoring->send({intMetric, "myCrazyMetricI"});
2628
monitoring->send({stringMetric, "myCrazyMetricS"});
2729
monitoring->send({doubleMetric, "myCrazyMetricD"});

0 commit comments

Comments
 (0)