Skip to content

Commit 6c9781c

Browse files
authored
Fix codacy issues (#118)
1 parent 361cfe6 commit 6c9781c

File tree

6 files changed

+50
-70
lines changed

6 files changed

+50
-70
lines changed

README.md

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![travis-ci](https://api.travis-ci.org/AliceO2Group/Monitoring.svg?branch=master)](https://travis-ci.org/AliceO2Group/Monitoring)
33
[![aliBuild](https://img.shields.io/badge/aliBuild-dashboard-lightgrey.svg)](https://alisw.cern.ch/dashboard/d/000000001/main-dashboard?orgId=1&var-storagename=All&var-reponame=All&var-checkname=build%2FMonitoring%2Fo2-dataflow%2F0&var-upthreshold=30m&var-minuptime=30)
44
[![codecov](https://codecov.io/gh/AliceO2Group/Monitoring/branch/dev/graph/badge.svg)](https://codecov.io/gh/AliceO2Group/Monitoring/branch/dev)
5+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3816cb37f02e4801ac62df080d5b6c9c)](https://www.codacy.com/app/awegrzyn/Monitoring?utm_source=github.com&utm_medium=referral&utm_content=AliceO2Group/Monitoring&utm_campaign=Badge_Grade)
56
[![JIRA](https://img.shields.io/badge/JIRA-issues-blue.svg)](https://alice.its.cern.ch/jira/projects/OMON)
67
[![doxygen](https://img.shields.io/badge/doxygen-documentation-blue.svg)](https://aliceo2group.github.io/Monitoring/)
78

@@ -20,14 +21,13 @@ Monitoring module allows to inject user defined metrics and monitor the process
2021
<strong>[Click here if you don't have aliBuild installed](https://alice-doc.github.io/alice-analysis-tutorial/building/)</strong>
2122
<br>
2223

23-
+ Compile `Monitoring` and its dependecies via `aliBuild`
24-
```
25-
aliBuild init Monitoring@master
26-
aliBuild build Monitoring --defaults o2-daq
24+
+ Compile `Monitoring` and its dependecies via `aliBuild`
25+
```bash
26+
aliBuild build Monitoring --defaults o2-dataflow
2727
```
2828

29-
+ Load the enviroment for Monitoring (in the `alice` directory)
30-
```
29+
+ Load the enviroment for Monitoring (in the `alice` directory)
30+
```bash
3131
alienv load Monitoring/latest
3232
```
3333

@@ -37,16 +37,14 @@ In case of an issue with `aliBuild` refer to [the official instructions](https:/
3737
Manual installation of the O<sup>2</sup> Monitoring module.
3838

3939
#### Requirements
40-
+ C++ compiler with C++17 support, eg.:
41-
+ `gcc-c++` package from `devtoolset-7` on CentOS 7
42-
+ `clang++` on Mac OS
43-
+ Boost >= 1.56
44-
+ libcurl
45-
+ [ApMon](http://monalisa.caltech.edu/monalisa__Download__ApMon.html) (optional)
40+
+ C++ compiler with C++17 support
41+
+ Boost >= 1.56
42+
+ libcurl
43+
+ [ApMon](http://monalisa.caltech.edu/monalisa__Download__ApMon.html) (optional)
4644

4745
#### Monitoring module compilation
4846

49-
```
47+
```bash
5048
git clone https://github.com/AliceO2Group/Monitoring.git
5149
cd Monitoring; mkdir build; cd build
5250
cmake .. -DCMAKE_INSTALL_PREFIX=<installdir>
@@ -67,14 +65,14 @@ std::unique_ptr<Monitoring> monitoring = MonitoringFactory::Get("backend[-protoc
6765
6866
See table below to find out how to create `URI` for each backend:
6967
70-
| Backend name | Transport | URI backend[-protocol] | URI query | Default verbosity |
71-
| ------------ |:---------:|:----------------------:|:----------:| -----------------:|
72-
| InfluxDB | HTTP | `influxdb-http` | `?db=<db>` | `info` |
73-
| InfluxDB | UDP | `influxdb-udp` | - | `info` |
74-
| InfluxDB | Unix datagram | `influxdb-unix` | - | `info` |
75-
| ApMon | UDP | `apmon` | - | `info` |
76-
| StdOut | - | `stdout`, `infologger` | - | `debug` |
77-
| Flume | UDP | `flume` | - | `info` |
68+
| Backend name | Transport | URI backend[-protocol] | URI query | Default verbosity |
69+
| ------------ |:-----------:|:----------------------:|:----------:| -----------------:|
70+
| InfluxDB | HTTP | `influxdb-http` | `?db=<db>` | `info` |
71+
| InfluxDB | UDP | `influxdb-udp` | - | `info` |
72+
| InfluxDB | Unix socket | `influxdb-unix` | - | `info` |
73+
| ApMon | UDP | `apmon` | - | `info` |
74+
| StdOut | - | `stdout`, `infologger` | - | `debug` |
75+
| Flume | UDP | `flume` | - | `info` |
7876
7977
##### StdCout output format
8078
```
@@ -84,13 +82,13 @@ See table below to find out how to create `URI` for each backend:
8482
### Metrics
8583
A metric consist of 5 parameters: name, value, timestamp, verbosity and tags.
8684

87-
| Parameter name | Type | Required | Default |
88-
| -------------- |:---------------------------------------------:|:--------:| --------------:|
89-
| name | string | yes | - |
90-
| value | int / double / string / uint64_t | yes | - |
91-
| timestamp | chrono::time_point&lt;std::chrono::system_clock&gt; | no | current timestamp |
92-
| verbosity | Debug / Info / Prod | no | Info |
93-
| tags | vector<unsigned int> | no | - |
85+
| Parameter name | Type | Required | Default |
86+
| -------------- |:--------------------------------:|:--------:| ------------:|
87+
| name | string | yes | - |
88+
| value | int / double / string / uint64_t | yes | - |
89+
| timestamp | time_point&lt;system_clock&gt; | no | current time |
90+
| verbosity | Debug / Info / Prod | no | Info |
91+
| tags | vector<unsigned int> | no | - |
9492

9593
A metric can be constructed by providing required parameters (value and name):
9694
```cpp
@@ -106,7 +104,6 @@ Metric{10, "name", Verbosity::Prod}
106104

107105
Metrics need to match backends verbosity in order to be sent, eg. backend with `/info` verbosity will accept `Info` and `Prod` metrics only.
108106

109-
110107
#### Tags
111108
Each metric can be tagged with any number of [predefined tags](include/Monitoring/Tags.h).
112109
In order to do so use `addTag(tags::Key, tags::Value)` or `addTag(tags::Key, unsigned short)` methods. The latter method allows assigning numeric value to a tag.
@@ -153,18 +150,18 @@ See how it works in the example: [examples/10-Buffering.cxx](examples/10-Bufferi
153150

154151
### Calculating derived metrics
155152
The module can calculate derived metrics. To do so, use optional `DerivedMetricMode mode` parameter of `send` method:
156-
+ `DerivedMetricMode::NONE` - no action,
157-
+ `DerivedMetricMode::RATE` - rate between two following metrics,
158-
+ `DerivedMetricMode::AVERAGE` - average value of all metrics stored in cache.
153+
+ `DerivedMetricMode::NONE` - no action,
154+
+ `DerivedMetricMode::RATE` - rate between two following metrics,
155+
+ `DerivedMetricMode::AVERAGE` - average value of all metrics stored in cache.
159156

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

162159
See how it works in the example: [examples/4-RateDerivedMetric.cxx](examples/4-RateDerivedMetric.cxx).
163160

164161
### Global tags
165162
Glabal tags are tags that are added to each metric. The following tags are set to global by library itself:
166-
- `hostname`
167-
- `name` - process name
163+
+ `hostname`
164+
+ `name` - process name
168165

169166
You can add your own global tag by calling `addGlobalTag(std::string_view key, std::string_view value)` or `addGlobalTag(tags::Key, tags::Value)`.
170167

@@ -173,9 +170,9 @@ You can add your own global tag by calling `addGlobalTag(std::string_view key, s
173170
enableProcessMonitoring([interval in seconds]);
174171
```
175172
The following metrics are generated every interval:
176-
+ **cpuUsedPercentage** - percentage of a core usage over time interval
177-
+ **involuntaryContextSwitches** - involuntary context switches over time interval
178-
+ **memoryUsagePercentage** - ratio of the process's resident set size to the physical memory on the machine, expressed as a percentage (Linux only)
173+
+ **cpuUsedPercentage** - percentage of a core usage over time interval
174+
+ **involuntaryContextSwitches** - involuntary context switches over time interval
175+
+ **memoryUsagePercentage** - ratio of the process's resident set size to the physical memory on the machine, expressed as a percentage (Linux only)
179176
180177
### Automatic metric updates
181178
Sometimes it's necessary to provide value every exact interval of time (even though value does not change). This can be done using `AutoPushMetric`.
@@ -188,8 +185,8 @@ See how it works in the example: [examples/11-AutoUpdate.cxx](examples/11-AutoUp
188185
## System monitoring, server-side backends installation and configuration
189186
This guide explains manual installation. For `ansible` deployment see [AliceO2Group/system-configuration](https://gitlab.cern.ch/AliceO2Group/system-configuration/tree/master/ansible) gitlab repo.
190187

191-
+ [Collectd](doc/collectd.md)
192-
+ [Flume](doc/flume.md)
193-
+ [InfluxDB](doc/influxdb.md)
194-
+ [Grafana](doc/grafana.md)
195-
+ [MonALISA](http://monalisa.caltech.edu/monalisa__Documentation__Service_Installation_Guide.html) (external link)
188+
+ [Collectd](doc/collectd.md)
189+
+ [Flume](doc/flume.md)
190+
+ [InfluxDB](doc/influxdb.md)
191+
+ [Grafana](doc/grafana.md)
192+
+ [MonALISA](http://monalisa.caltech.edu/monalisa__Documentation__Service_Installation_Guide.html) (external link)

src/Backends/Flume.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace monitoring
1818
namespace backends
1919
{
2020

21-
Flume::Flume(const std::string& host, unsigned int port)
21+
Flume::Flume(const std::string& host, unsigned int port) :
22+
mTransport(std::make_unique<transports::UDP>(host, port))
2223
{
23-
mTransport = std::make_unique<transports::UDP>(host, port);
2424
MonLogger::Get() << "Flume/UDP backend initialized"
2525
<< " ("<< host << ":" << port << ")" << MonLogger::End();
2626
}

src/Backends/InfluxDB.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ namespace monitoring
2020
namespace backends
2121
{
2222

23-
InfluxDB::InfluxDB(const std::string& host, unsigned int port)
23+
InfluxDB::InfluxDB(const std::string& host, unsigned int port) :
24+
mTransport(std::make_unique<transports::UDP>(host, port))
2425
{
25-
transport = std::make_unique<transports::UDP>(host, port);
2626
MonLogger::Get() << "InfluxDB/UDP backend initialized"
2727
<< " ("<< host << ":" << port << ")" << MonLogger::End();
2828
}
2929

3030
InfluxDB::InfluxDB(const std::string& host, unsigned int port, const std::string& search)
3131
{
32-
transport = std::make_unique<transports::HTTP>(
32+
mTransport = std::make_unique<transports::HTTP>(
3333
"http://" + host + ":" + std::to_string(port) + "/write?" + search
3434
);
3535
MonLogger::Get() << "InfluxDB/HTTP backend initialized" << " (" << "http://" << host
3636
<< ":" << std::to_string(port) << "/write?" << search << ")" << MonLogger::End();
3737
}
3838

39-
InfluxDB::InfluxDB(const std::string& socketPath)
39+
InfluxDB::InfluxDB(const std::string& socketPath) :
40+
mTransport(std::make_unique<transports::Unix>(socketPath))
4041
{
41-
transport = std::make_unique<transports::Unix>(socketPath);
4242
MonLogger::Get() << "InfluxDB/Unix backend initialized (" << socketPath << ")" << MonLogger::End();
4343
}
4444

@@ -71,7 +71,7 @@ void InfluxDB::sendMultiple(std::string measurement, std::vector<Metric>&& metri
7171
convert << " " << convertTimestamp(metrics.back().getTimestamp());
7272

7373
try {
74-
transport->send(convert.str());
74+
mTransport->send(convert.str());
7575
} catch (MonitoringException&) {
7676
}
7777
}
@@ -84,7 +84,7 @@ void InfluxDB::send(std::vector<Metric>&& metrics) {
8484
}
8585

8686
try {
87-
transport->send(std::move(influxMetrics));
87+
mTransport->send(std::move(influxMetrics));
8888
} catch (MonitoringException&) {
8989
}
9090

@@ -93,7 +93,7 @@ void InfluxDB::send(std::vector<Metric>&& metrics) {
9393
void InfluxDB::send(const Metric& metric)
9494
{
9595
try {
96-
transport->send(toInfluxLineProtocol(metric));
96+
mTransport->send(toInfluxLineProtocol(metric));
9797
} catch (MonitoringException&) {
9898
}
9999
}

src/Backends/InfluxDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class InfluxDB final : public Backend
6767
void addGlobalTag(std::string_view name, std::string_view value) override;
6868

6969
private:
70-
std::unique_ptr<transports::TransportInterface> transport; ///< InfluxDB transport
70+
std::unique_ptr<transports::TransportInterface> mTransport; ///< InfluxDB transport
7171
std::string tagSet; ///< Global tagset (common for each metric)
7272

7373
/// Escapes " ", "," and "=" characters

src/Transports/TCP.cxx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ void TCP::send(std::string&& message)
4545
}
4646
}
4747

48-
void TCP::read() {
49-
for (;;) {
50-
boost::system::error_code error;
51-
boost::array<char, 128> buf;
52-
size_t len = mSocket.read_some(boost::asio::buffer(buf), error);
53-
if (error == boost::asio::error::eof) {
54-
break;
55-
} else {
56-
return;
57-
}
58-
std::cout.write(buf.data(), len);
59-
}
60-
}
61-
6248
} // namespace transports
6349
} // namespace monitoring
6450
} // namespace o2

src/Transports/TCP.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class TCP : public TransportInterface
3939
/// \param message r-value string formated
4040
void send(std::string&& message) override;
4141

42-
/// Dummy read method - Forwards read out buffer to cout
43-
void read();
44-
4542
private:
4643
/// Boost Asio I/O functionality
4744
boost::asio::io_service mIoService;

0 commit comments

Comments
 (0)