Skip to content

Commit 8dba94e

Browse files
authored
Do not include code in README, use examples instead (#63)
1 parent 03fd42d commit 8dba94e

File tree

4 files changed

+34
-69
lines changed

4 files changed

+34
-69
lines changed

README.md

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,6 @@ Monitoring module allows to inject user defined metrics and monitor the process
1313
5. [System monitoring and server-side backends installation and configuration](#system-monitoring-server-side-backends-installation-and-configuration)
1414

1515
## Installation
16-
### RPM (CentOS 7 only)
17-
+ Install CERN certificates
18-
~~~
19-
yum -y install CERN-CA-certs
20-
~~~
21-
22-
+ Add `alisw` repo **(as root)**
23-
~~~
24-
cat > /etc/yum.repos.d/alisw-el7.repo <<EOF
25-
[alisw-el7]
26-
name=ALICE Software - EL7
27-
baseurl=https://ali-ci.cern.ch/repo/RPMS/el7.x86_64/
28-
enabled=1
29-
gpgcheck=0
30-
EOF
31-
~~~
32-
33-
+ Install Monitoring RPM package **(as root)**
34-
~~~
35-
yum -y install alisw-Monitoring+v1.5.4-1.x86_64
36-
~~~
37-
38-
+ Configure Modules
39-
~~~
40-
export MODULEPATH=/opt/alisw/el7/modulefiles:$MODULEPATH
41-
~~~
42-
43-
+ Load enviroment
44-
~~~
45-
eval `modulecmd bash load Monitoring/v1.5.4-1`
46-
~~~
47-
The installation directory is: `/opt/alisw/el7/Monitoring/v1.5.4-1`
4816

4917
### aliBuild
5018
<strong>[Click here if you don't have aliBuild installed](https://alice-doc.github.io/alice-analysis-tutorial/building/)</strong>
@@ -76,13 +44,13 @@ Manual installation of the O<sup>2</sup> Monitoring module.
7644

7745
#### Monitoring module compilation
7846

79-
~~~
47+
```
8048
git clone https://github.com/AliceO2Group/Monitoring.git
8149
cd Monitoring; mkdir build; cd build
8250
cmake .. -DCMAKE_INSTALL_PREFIX=<installdir>
8351
make -j
8452
make install
85-
~~~
53+
```
8654

8755
## Getting started
8856
### Monitoring instance
@@ -94,6 +62,7 @@ The library is accessible from `o2::monitoring` namespace.
9462
using namespace o2::monitoring;
9563
std::unique_ptr<Monitoring> monitoring = MonitoringFactory::Get("backend[-protocol]://host:port[/verbosity][?query]");
9664
```
65+
9766
See table below to find out how to create `URI` for each backend:
9867
9968
| Backend name | Transport | URI backend[-protocol] | URI query | Default verbosity |
@@ -117,12 +86,10 @@ Where metric constructor receives following parameters:
11786
- `std::string& name`
11887
- `[time_point<system_clock> timestamp]`
11988

120-
For example:
121-
```cpp
122-
monitoring->send({10, "myMetricInt"});
123-
```
12489

125-
Regarding `DerivedMetricMode` see [Calculating derived metrics](#calculating-derived-metrics).
90+
The `DerivedMetricMode` is described in [Calculating derived metrics](#calculating-derived-metrics) section.
91+
92+
See how it works in the example: [examples/1-Basic.cxx](examples/1-Basic.cxx)
12693

12794
### Debug metrics
12895
Debug metrics can be send by a similar method to above's `send`:
@@ -142,25 +109,23 @@ Two additional methods can be chained the to `send(Metric&& metric)` in order to
142109
+ `addTags(std::vector<Tag>&& tags)`
143110
+ `setTimestamp(std::chrono::time_point<std::chrono::system_clock>& timestamp)`
144111
145-
For example:
146-
```cpp
147-
monitoring->send(Metric{10, "myMetric"}.addTags({{"tag1", "value1"}, {"tag2", "value2"}}));
148-
monitoring->send(Metric{10, "myCrazyMetric"}.setTimestamp(timestamp));
149-
```
112+
See how it works in the example: [examples/2-TaggedMetrics.cxx](examples/2-TaggedMetrics.cxx), [examples/3-UserDefinedTimestamp.cxx](examples/3-UserDefinedTimestamp.cxx).
150113
151114
## Features and additional information
152115
153-
### Grouped values
154-
It's also possible to send multiple, grouped values in a single metric (`Flume` and `InfluxDB` backends are supproted, others fallback into sending values in seperate metrics)
116+
### Sending more than one metric
117+
In order to send more than one metric in a packet group them into vector:
155118
```cpp
156-
void sendGroupped(std::string name, std::vector<Metric>&& metrics)
119+
monitoring->send(std::vector<Metric>&& metrics);
157120
```
158121

159-
For example:
122+
It's also possible to send multiple, grouped values (only `Flume` and `InfluxDB` backends are supported); For example `cpu` metric can be composed of `cpuUser`, `cpuSystem` values.
160123
```cpp
161-
monitoring->sendGroupped("measurementName", {{20, "myMetricIntMultiple"}, {20.30, "myMetricFloatMultple"}});
124+
void sendGroupped(std::string name, std::vector<Metric>&& metrics)
162125
```
163126
127+
See how it works in the example: [examples/8-Multiple.cxx](examples/8-Multiple.cxx)
128+
164129
### Buffering metrics
165130
In order to avoid sending each metric separately, metrics can be temporary stored in the buffer and flushed at the most convenient moment.
166131
This feature can be operated with following two methods:
@@ -172,15 +137,7 @@ monitoring->flushBuffer();
172137

173138
`enableBuffering` takes maximum buffer size as its parameter. The buffer gets full all values are flushed automatically.
174139

175-
For example:
176-
```cpp
177-
monitoring->enableBuffering(5);
178-
for (int i = 1; i < 10; i++) {
179-
monitoring->send({10, "myMetricInt"});
180-
}
181-
monitoring->send({20, "myMetricInt2"});
182-
monitoring->flushBuffer();
183-
```
140+
See how it works in the example: [examples/10-Buffering.cxx](examples/10-Buffering.cxx).
184141

185142
### Metrics
186143
Metrics consist of 4 parameters: name, value, timestamp and tags.
@@ -205,6 +162,8 @@ The module can calculate derived metrics. To do so, use optional `DerivedMetricM
205162

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

165+
See how it works in the example: [examples/4-RateDerivedMetric.cxx](examples/4-RateDerivedMetric.cxx).
166+
208167
### Global tags
209168
Glabal tags are tags that are added to each metric. The following tags are set to global by library itself:
210169
- `hostname`
@@ -221,14 +180,13 @@ The following metrics are generated every interval:
221180
+ **involuntaryContextSwitches** - involuntary context switches over time interval
222181
+ **memoryUsagePercentage** - ratio of the process's resident set size to the physical memory on the machine, expressed as a percentage (Linux only)
223182
224-
## Code snippets
225-
Code snippets are available in [examples](examples/) directory.
226-
227-
+ Sending metric - [examples/1-Basic.cxx](examples/1-Basic.cxx)
228-
+ Sending metric with custom taggs - [examples/2-TaggedMetrics.cxx](examples/2-TaggedMetrics.cxx)
229-
+ Sending metric with user defined timestamp - [examples/3-UserDefinedTimestamp.cxx](examples/3-UserDefinedTimestamp.cxx)
230-
+ Calculating derived metrics - [examples/4-RateDerivedMetric.cxx](examples/4-RateDerivedMetric.cxx)
231-
+ Sending multiple values in a single metric - [examples/8-Multiple.cxx](examples/8-Multiple.cxx)
183+
### Automatic metric updates
184+
When global, higher level metrics are created it's necessary to provide values every interval of time (even though values does not change). This can be done using `AutoPushMetric`. The
185+
```cpp
186+
Metric& metric = monitoring->getAutoPushMetric("exampleMetric");
187+
metric = 10;
188+
```
189+
See how it works in the example: [examples/11-AutoUpdate.cxx](examples/11-AutoUpdate.cxx).
232190

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

examples/11-AutoUpdate.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///
2-
/// \file 1-Basic.cxx
2+
/// \file 11-AutoUpdate.cxx
33
/// \author Adam Wegrzynek <[email protected]>
44
///
55

@@ -9,10 +9,16 @@ using namespace o2::monitoring;
99

1010
int main() {
1111
auto monitoring = MonitoringFactory::Get("infologger://");
12+
13+
// Enable periodical value pushing (default every 1s)
1214
monitoring->enableAutoPush();
15+
16+
// Get reference to metrics
1317
auto& qcMetric = monitoring->getAutoPushMetric("qcMetric");
1418
auto& qcMetric2 = monitoring->getAutoPushMetric("qcMetric2");
1519
std::this_thread::sleep_for (std::chrono::milliseconds(2000));
20+
21+
// Update values
1622
qcMetric = 123;
1723
qcMetric2 = 321;
1824
std::this_thread::sleep_for (std::chrono::milliseconds(2000));

examples/6-Increment.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ int main() {
1212
// Configure monitoring
1313
// Pass string with list of URLs as parameter
1414
auto monitoring = Monitoring::Get("infologger://");
15-
15+
16+
// Increment values by ..
1617
monitoring->send({10, "myIncrementMetric"}, DerivedMetricMode::INCREMENT);
1718
monitoring->send({5, "myIncrementMetric"}, DerivedMetricMode::INCREMENT);
1819
monitoring->send({15, "myIncrementMetric"}, DerivedMetricMode::INCREMENT);

examples/8-Multiple.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ int main() {
1212
// Pass string with list of URLs as parameter
1313
auto monitoring = Monitoring::Get("flume://pcald03.cern.ch:8092");
1414

15-
//monitoring->sendGrouped("measurementName", {{20, "myMetricIntMultiple"}, {20.30, "myMetricFloatMultple"}});
15+
monitoring->sendGrouped("measurementName", {{20, "myMetricIntMultiple"}, {20.30, "myMetricFloatMultple"}});
1616
monitoring->send({{201, "myMetricIntMultiple"}, {2.34, "myMetricFloatMultple"}});
1717
}

0 commit comments

Comments
 (0)