Skip to content

Commit

Permalink
Send both raw and derived metrics (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Jun 6, 2018
1 parent ded653c commit 0ec0739
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ See table below to find out how to create `URI` for each backend:
### Sending metric
```cpp
send(Metric&& metric)
send(Metric&& metric, [DerivedMetricMode mode])
```
Where metric constructor receives following parameters:
- `T value`
Expand All @@ -118,6 +118,8 @@ For example:
monitoring->send({10, "myMetricInt"});
```
Regarding `DerivedMetricMode` see [Calculating derived metrics](#calculating-derived-metrics).
### Customized metrics
Two additional methods can be chained the to `send(Metric&& metric)` in order to __insert custom tags__ or __set custom timestamp__:
+ `addTags(std::vector<Tag>&& tags)`
Expand Down Expand Up @@ -179,9 +181,10 @@ Metrics consist of 4 parameters: name, value, timestamp and tags.
+ process name

### Calculating derived metrics
The module can calculate derived metrics. To do so, use `addDerivedMetric(std::string name, DerivedMetricMode mode)` with one of two available modes:
+ `DerivedMetricMode::RATE` - rate between two following metrics;
+ `DerivedMetricMode::AVERAGE` - average value of all metrics stored in cache;
The module can calculate derived metrics. To do so, use optional `DerivedMetricMode mode` parameter of `send` method:
+ `DerivedMetricMode::NONE` - no action,
+ `DerivedMetricMode::RATE` - rate between two following metrics,
+ `DerivedMetricMode::AVERAGE` - average value of all metrics stored in cache.

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

Expand Down
3 changes: 3 additions & 0 deletions include/Monitoring/Monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class Monitoring
/// List of timers
std::unordered_map <std::string, std::chrono::time_point<std::chrono::steady_clock>> mTimers;

/// Pushes metric to all backends or to the buffer
void pushToBackends(Metric&& metric);

/// States whether Process Monitor thread is running
std::atomic<bool> mMonitorRunning;

Expand Down
25 changes: 16 additions & 9 deletions src/Monitoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,15 @@ void Monitoring::sendGrouped(std::string measurement, std::vector<Metric>&& metr
}
}

void Monitoring::send(std::vector<Metric>&& metrics) {
void Monitoring::send(std::vector<Metric>&& metrics)
{
for (auto& b: mBackends) {
b->send(std::move(metrics));
}
}

void Monitoring::send(Metric&& metric, DerivedMetricMode mode)
void Monitoring::pushToBackends(Metric&& metric)
{
if (mode == DerivedMetricMode::RATE) {
metric = mDerivedHandler->rate(metric);
}

if (mode == DerivedMetricMode::INCREMENT) {
metric = mDerivedHandler->increment(metric);
}
if (mBuffering) {
mStorage.push_back(std::move(metric));
if (mStorage.size() >= mBufferSize) {
Expand All @@ -163,5 +157,18 @@ void Monitoring::send(Metric&& metric, DerivedMetricMode mode)
}
}

void Monitoring::send(Metric&& metric, DerivedMetricMode mode)
{
if (mode == DerivedMetricMode::RATE) {
pushToBackends(mDerivedHandler->rate(metric));
}

if (mode == DerivedMetricMode::INCREMENT) {
pushToBackends(mDerivedHandler->increment(metric));
}

pushToBackends(std::move(metric));
}

} // namespace monitoring
} // namespace o2

0 comments on commit 0ec0739

Please sign in to comment.