-
Notifications
You must be signed in to change notification settings - Fork 0
/
Measurement.h
51 lines (38 loc) · 1.13 KB
/
Measurement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by jmmanos on 1/7/20.
//
#ifndef INFLUXDBV2CLIENT_MEASUREMENT_H
#define INFLUXDBV2CLIENT_MEASUREMENT_H
/**
* Class to store a measurement that gets converted to line protocol for InfluxDB ingestion.
*/
class Measurement {
public:
Measurement(String name): _name(name) {}
void addTag(String key, String value) {
_tags += (_tags == "") ? (key + "=" + value) : ("," + key + "=" + value);
}
void addValue(String key, float value) {
_values += (_values == "") ? (key + "=" + String(value)) : ("," + key + "=" + String(value));
}
void setTimestamp(long int seconds) {
_timestamp = String(seconds) + "000000000";
}
String toString() const {
String measurementString = _name;
if (_tags != "") {
measurementString += "," + _tags;
}
measurementString += " " + _values;
if (_timestamp != "") {
measurementString += " " + _timestamp;
}
return measurementString;
}
private:
String _name;
String _tags;
String _values;
String _timestamp;
};
#endif //INFLUXDBV2CLIENT_MEASUREMENT_H