@@ -13,9 +13,8 @@ InfluxPusher::InfluxPusher(std::string_view dbname) : d_dbname(dbname)
13
13
14
14
void InfluxPusher::queueValue (const std::string& line)
15
15
{
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++;
19
18
checkSend ();
20
19
}
21
20
@@ -41,25 +40,41 @@ void InfluxPusher::addValueObserver(int src, string_view name, const initializer
41
40
buffer+= " " ;
42
41
bool lefirst=true ;
43
42
for (const auto & v : values) {
43
+ d_numvalues++;
44
44
if (!lefirst) {
45
45
buffer +=" ," ;
46
46
}
47
47
lefirst=false ;
48
48
buffer += string (v.first ) + " =" +to_string (v.second );
49
49
}
50
50
buffer += " " + to_string ((uint64_t )(t* 1000000000 ))+" \n " ;
51
-
51
+ d_nummsmts++;
52
+ d_msmtmap[(string)name]++;
52
53
queueValue (buffer);
53
54
}
54
55
55
-
56
+
56
57
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)
57
69
{
58
70
if (d_mute)
59
71
return ;
60
72
61
73
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;
63
78
return ;
64
79
}
65
80
for (const auto & p : values) {
@@ -68,13 +83,26 @@ void InfluxPusher::addValue(const SatID& id, string_view name, const initializer
68
83
return ;
69
84
}
70
85
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
+ }
74
101
75
102
buffer+= " " ;
76
103
bool lefirst=true ;
77
104
for (const auto & v : values) {
105
+ d_numvalues++;
78
106
if (!lefirst) {
79
107
buffer +=" ," ;
80
108
}
@@ -83,14 +111,19 @@ void InfluxPusher::addValue(const SatID& id, string_view name, const initializer
83
111
84
112
std::visit ([&buffer](auto && arg) {
85
113
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
+ }
89
121
}, v.second );
90
122
}
91
123
buffer += " " + to_string ((uint64_t )(t*1000000000 ))+" \n " ;
124
+ d_nummsmts++;
125
+ d_msmtmap[(string)name]++;
92
126
queueValue (buffer);
93
-
94
127
}
95
128
96
129
0 commit comments