File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 11#include " metrics.hpp"
22
3+ #include < algorithm>
34#include < fstream>
45#include < random>
56
1011
1112Metrics::Metrics ()
1213 : publish_interval(Setup::getSetupInt(" LODA_METRICS_PUBLISH_INTERVAL" ,
13- 600 )), // magic number
14+ 300 )), // magic number
1415 notified(false ) {
1516 host = Setup::getSetupValue (" LODA_INFLUXDB_HOST" );
1617 if (!host.empty ()) {
@@ -41,13 +42,18 @@ void Metrics::write(const std::vector<Entry> entries) const {
4142 for (auto &entry : entries) {
4243 out << entry.field ;
4344 for (auto &l : entry.labels ) {
44- out << " ," << l.first << " =" << l.second ;
45+ auto v = l.second ;
46+ std::replace (v.begin (), v.end (), ' ' , ' _' );
47+ out << " ," << l.first << " =" << v;
4548 }
4649 out << " value=" << entry.value << " \n " ;
4750 }
4851 out.close ();
49- if (!WebClient::postFile (host + " /write?db=loda" , file_name, auth)) {
52+ const std::string url = host + " /write?db=loda" ;
53+ if (WebClient::postFile (url, file_name, auth)) {
54+ std::remove (file_name.c_str ());
55+ } else {
56+ WebClient::postFile (url, file_name, auth, true ); // for debugging
5057 Log::get ().error (" Error publishing metrics" , false );
5158 }
52- std::remove (file_name.c_str ());
5359}
Original file line number Diff line number Diff line change @@ -256,6 +256,7 @@ bool Miner::checkRegularTasks() {
256256 labels[" user" ] = it.first ;
257257 entries.push_back ({" programs" , labels, static_cast <double >(it.second )});
258258 }
259+ labels.clear ();
259260 labels[" kind" ] = " removed" ;
260261 entries.push_back ({" programs" , labels, static_cast <double >(num_removed)});
261262 Metrics::get ().write (entries);
You can’t perform that action at this time.
0 commit comments