From eaa3cd83adf860732b955a77b8f5fca7e30c65c2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 28 Nov 2022 12:27:01 +0100 Subject: [PATCH 1/2] 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; } From 21f548d3c07189c6a413cf88c2b60cc9ada73497 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 16 Jan 2023 12:00:53 +0100 Subject: [PATCH 2/2] Remove no-op InfluxDB URL param precision=ns is the default. --- lib/perfdata/influxdbcommonwriter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index fd588a178..32ee7f9be 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -554,7 +554,6 @@ Url::Ptr InfluxdbCommonWriter::AssembleBaseUrl() url->SetScheme(GetSslEnable() ? "https" : "http"); url->SetHost(GetHost()); url->SetPort(GetPort()); - url->AddQueryElement("precision", "ns"); return url; }