Skip to content

Commit 852aadd

Browse files
committed
also make string tags possible, keep more statistics
1 parent 2d66645 commit 852aadd

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

Diff for: influxpush.cc

+46-13
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ InfluxPusher::InfluxPusher(std::string_view dbname) : d_dbname(dbname)
1313

1414
void InfluxPusher::queueValue(const std::string& line)
1515
{
16-
d_buffer.insert(line);
17-
// if(d_buffer.insert(line).second)
18-
// cout<<line;
16+
if(!d_buffer.insert(line).second)
17+
d_numdedupmsmts++;
1918
checkSend();
2019
}
2120

@@ -41,25 +40,41 @@ void InfluxPusher::addValueObserver(int src, string_view name, const initializer
4140
buffer+= " ";
4241
bool lefirst=true;
4342
for(const auto& v : values) {
43+
d_numvalues++;
4444
if(!lefirst) {
4545
buffer +=",";
4646
}
4747
lefirst=false;
4848
buffer += string(v.first) + "="+to_string(v.second);
4949
}
5050
buffer += " " + to_string((uint64_t)(t* 1000000000))+"\n";
51-
51+
d_nummsmts++;
52+
d_msmtmap[(string)name]++;
5253
queueValue(buffer);
5354
}
5455

55-
56+
5657
void InfluxPusher::addValue(const SatID& id, string_view name, const initializer_list<pair<const char*, var_t>>& values, double t, std::optional<int> src, std::optional<string> tag)
58+
{
59+
60+
vector<pair<string,var_t>> tags{{"sv", id.sv}, {"gnssid", id.gnss}, {"sigid", id.sigid}};
61+
62+
if(src) {
63+
tags.push_back({*tag, *src});
64+
}
65+
addValue(tags, name, values, t);
66+
}
67+
68+
void InfluxPusher::addValue(const vector<pair<string,var_t>>& tags, string_view name, const initializer_list<pair<const char*, var_t>>& values, double t)
5769
{
5870
if(d_mute)
5971
return;
6072

6173
if(t > 2200000000 || t < 0) {
62-
cerr<<"Unable to store item "<<name<<" for sv "<<id.gnss<<","<<id.sv<<": time out of range "<<t<<endl;
74+
cerr<<"Unable to store item "<<name<<" for ";
75+
// for(const auto& t: tags)
76+
// cerr<<t.first<<"="<<t.second<<" ";
77+
cerr<<": time out of range "<<t<<endl;
6378
return;
6479
}
6580
for(const auto& p : values) {
@@ -68,13 +83,26 @@ void InfluxPusher::addValue(const SatID& id, string_view name, const initializer
6883
return;
6984
}
7085

71-
string buffer = string(name) +",gnssid="+to_string(id.gnss)+",sv=" +to_string(id.sv)+",sigid="+to_string(id.sigid);
72-
if(src)
73-
buffer += ","+*tag+"="+to_string(*src);
86+
string buffer = string(name);
87+
for(const auto& t : tags) {
88+
buffer += ","+t.first + "=";
89+
std::visit([&buffer](auto&& arg) {
90+
using T = std::decay_t<decltype(arg)>;
91+
if constexpr (std::is_same_v<T, string>) {
92+
// string tags really don't need a "
93+
buffer += arg;
94+
}
95+
else {
96+
// resist the urge to do integer tags, it sucks
97+
buffer += to_string(arg);
98+
}
99+
}, t.second);
100+
}
74101

75102
buffer+= " ";
76103
bool lefirst=true;
77104
for(const auto& v : values) {
105+
d_numvalues++;
78106
if(!lefirst) {
79107
buffer +=",";
80108
}
@@ -83,14 +111,19 @@ void InfluxPusher::addValue(const SatID& id, string_view name, const initializer
83111

84112
std::visit([&buffer](auto&& arg) {
85113
using T = std::decay_t<decltype(arg)>;
86-
buffer += to_string(arg);
87-
if constexpr (!std::is_same_v<T, double>)
88-
buffer+="i";
114+
if constexpr (std::is_same_v<T, string>)
115+
buffer += "\""+arg+"\"";
116+
else {
117+
buffer += to_string(arg);
118+
if constexpr (!std::is_same_v<T, double>)
119+
buffer+="i";
120+
}
89121
}, v.second);
90122
}
91123
buffer += " " + to_string((uint64_t)(t*1000000000))+"\n";
124+
d_nummsmts++;
125+
d_msmtmap[(string)name]++;
92126
queueValue(buffer);
93-
94127
}
95128

96129

Diff for: influxpush.hh

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
struct InfluxPusher
1010
{
11-
typedef std::variant<double, int32_t, uint32_t, int64_t> var_t;
11+
typedef std::variant<double, int32_t, uint32_t, int64_t, string> var_t;
1212
explicit InfluxPusher(std::string_view dbname);
1313
void addValueObserver(int src, std::string_view name, const std::initializer_list<std::pair<const char*, double>>& values, double t, std::optional<SatID> satid=std::optional<SatID>());
1414
void addValue(const SatID& id, std::string_view name, const std::initializer_list<std::pair<const char*, var_t>>& values, double t, std::optional<int> src = std::optional<int>(), std::optional<string> tag = std::optional<string>("src"));
15-
15+
16+
17+
void addValue(const vector<pair<string, var_t>>& tags, string_view name, const initializer_list<pair<const char*, var_t>>& values, double t);
1618
void checkSend();
1719
void doSend(const std::set<std::string>& buffer);
1820
~InfluxPusher();
@@ -22,4 +24,8 @@ struct InfluxPusher
2224
time_t d_lastsent{0};
2325
string d_dbname;
2426
bool d_mute{false};
27+
int64_t d_nummsmts{0};
28+
int64_t d_numvalues{0};
29+
int64_t d_numdedupmsmts{0};
30+
map<std::string, int64_t> d_msmtmap;
2531
};

0 commit comments

Comments
 (0)