From eaa3cd83adf860732b955a77b8f5fca7e30c65c2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 28 Nov 2022 12:27:01 +0100 Subject: [PATCH] Influx DB: don't unneccessarily truncate timestamps to whole seconds Instead send timestamps with the highest possible precision (ns). Useful for check intervals <1s. --- lib/perfdata/influxdbcommonwriter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index a42d9e182..fd588a178 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -398,7 +399,7 @@ void InfluxdbCommonWriter::SendMetric(const Checkable::Ptr& checkable, const Dic } } - msgbuf << " " << static_cast(ts); + msgbuf << " " << std::fixed << std::setprecision(0) << ts * 1.0e9; Log(LogDebug, GetReflectionType()->GetName()) << "Checkable '" << checkable->GetName() << "' adds to metric list:'" << msgbuf.str() << "'."; @@ -553,7 +554,7 @@ Url::Ptr InfluxdbCommonWriter::AssembleBaseUrl() url->SetScheme(GetSslEnable() ? "https" : "http"); url->SetHost(GetHost()); url->SetPort(GetPort()); - url->AddQueryElement("precision", "s"); + url->AddQueryElement("precision", "ns"); return url; }