Skip to content

Commit 37b2751

Browse files
committed
fix metric publication error
1 parent 17ce2c0 commit 37b2751

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/metrics.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "metrics.hpp"
22

3+
#include <algorithm>
34
#include <fstream>
45
#include <random>
56

@@ -10,7 +11,7 @@
1011

1112
Metrics::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
}

src/miner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)