Fix some bugs in plugin PromExporter. (#2189)

This commit is contained in:
Tanglong3bf 2024-10-21 09:51:34 +08:00 committed by GitHub
parent ca2210331d
commit 284d14b8ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -91,7 +91,7 @@ class Gauge : public Metric
static std::string_view type() static std::string_view type()
{ {
return "counter"; return "gauge";
} }
void setToCurrentTime() void setToCurrentTime()

View File

@ -28,6 +28,7 @@ void PromExporter::initAndStart(const Json::Value &config)
} }
auto resp = HttpResponse::newHttpResponse(); auto resp = HttpResponse::newHttpResponse();
resp->setBody(thisPtr->exportMetrics()); resp->setBody(thisPtr->exportMetrics());
resp->setContentTypeCode(CT_TEXT_PLAIN);
resp->setExpiredTime(5); resp->setExpiredTime(5);
callback(resp); callback(resp);
}, },
@ -118,12 +119,12 @@ static std::string exportCollector(
.append(collector->name()) .append(collector->name())
.append(" ") .append(" ")
.append(collector->help()) .append(collector->help())
.append("\r\n"); .append("\n");
res.append("# TYPE ") res.append("# TYPE ")
.append(collector->name()) .append(collector->name())
.append(" ") .append(" ")
.append(collector->type()) .append(collector->type())
.append("\r\n"); .append("\n");
for (auto const &sampleGroup : sampleGroups) for (auto const &sampleGroup : sampleGroups)
{ {
auto const &metricPtr = sampleGroup.metric; auto const &metricPtr = sampleGroup.metric;
@ -157,11 +158,11 @@ static std::string exportCollector(
res.append(" ") res.append(" ")
.append(std::to_string( .append(std::to_string(
sample.timestamp.microSecondsSinceEpoch() / 1000)) sample.timestamp.microSecondsSinceEpoch() / 1000))
.append("\r\n"); .append("\n");
} }
else else
{ {
res.append("\r\n"); res.append("\n");
} }
} }
} }