From: Petr Špaček Date: Fri, 23 Oct 2020 16:07:59 +0000 (+0200) Subject: graphite: adapt to to changes in map() X-Git-Tag: v5.2.0~6^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1065cc73e44c06c5df1498dc369a75f519e3d2e;p=thirdparty%2Fknot-resolver.git graphite: adapt to to changes in map() We don't have leader instance anymore, so each instance independently provides Graphite statistics. This commit also changes default Graphite prefix to solve problem with conflicting instance names. --- diff --git a/doc/upgrading.rst b/doc/upgrading.rst index 4f11fc1bc..76c5d56bb 100644 --- a/doc/upgrading.rst +++ b/doc/upgrading.rst @@ -45,6 +45,14 @@ Users Configuration file ------------------ +* Statistics exporter :ref:`mod-graphite` now uses default prefix which combines + :func:`hostname()` and :envvar:`worker.id` instead of bare :func:`hostname()`. + This prevents :ref:`systemd-multiple-instances` from sending + conflicting statistics to server. In case you want to continue in previous time series you + can manually set the old values using option ``prefix`` + in :ref:`Graphite configuration `. + Beware that non-default values require careful + :ref:`instance-specific-configuration` to avoid conflicting names. * Lua variable :envvar:`worker.id` is now a string with either Systemd instance name or PID (instead of number). If your custom configuration uses :envvar:`worker.id` value please check your scripts. diff --git a/etc/config/config.cluster b/etc/config/config.cluster index 742d1a546..58227bdf6 100644 --- a/etc/config/config.cluster +++ b/etc/config/config.cluster @@ -20,8 +20,6 @@ modules = { 'hints > iterate', -- Load /etc/hosts and allow custom root hints 'stats', -- Track internal statistics graphite = { -- Send statistics to local InfluxDB - -- `worker.id` allows us to keep per-fork statistics - prefix = hostname()..worker.id, -- Address of the Graphite/InfluxDB server host = '192.168.1.2', }, diff --git a/etc/config/config.splitview b/etc/config/config.splitview index 8e3fb225a..1b1d1983b 100644 --- a/etc/config/config.splitview +++ b/etc/config/config.splitview @@ -14,8 +14,6 @@ modules = { 'hints > iterate', -- Load /etc/hosts and allow custom root hints 'stats', -- Track internal statistics graphite = { -- Send statistics to local InfluxDB - -- `worker.id` allows us to keep per-fork statistics - prefix = hostname()..worker.id, -- Address of the Graphite/InfluxDB server host = '192.168.1.2', }, diff --git a/modules/graphite/README.rst b/modules/graphite/README.rst index cae92a4c9..2f86a6f14 100644 --- a/modules/graphite/README.rst +++ b/modules/graphite/README.rst @@ -19,11 +19,11 @@ By default the module uses UDP so it doesn't guarantee the delivery, set ``tcp = modules = { graphite = { - prefix = hostname(), -- optional metric prefix + prefix = hostname() .. worker.id, -- optional metric prefix host = '127.0.0.1', -- graphite server address port = 2003, -- graphite server port interval = 5 * sec, -- publish interval - tcp = false -- set to true if want TCP mode + tcp = false -- set to true if you want TCP mode } } diff --git a/modules/graphite/graphite.lua b/modules/graphite/graphite.lua index e2ac67eb0..8f6ba7424 100644 --- a/modules/graphite/graphite.lua +++ b/modules/graphite/graphite.lua @@ -3,7 +3,6 @@ if not stats then modules.load('stats') end -- This is leader-only module -if worker.id > 0 then return {} end local M = {} local socket = require("cqueues.socket") local proto_txt = { @@ -44,16 +43,6 @@ local function make_tcp(host, port) return make_socket(host, port, socket.SOCK_STREAM) end -local function merge(results) - local t = {} - for _, result in ipairs(results) do - for k, v in pairs(result) do - t[k] = (t[k] or 0) + v - end - end - return t -end - -- Send the metrics in a table to multiple Graphite consumers local function publish_table(metrics, prefix, now) local s @@ -106,7 +95,7 @@ function M.init() M.cli = {} M.info = {} M.interval = 5 * sec - M.prefix = 'kresd.' .. hostname() + M.prefix = string.format('kresd.%s.%s', hostname(), worker.id) return 0 end @@ -120,10 +109,10 @@ function M.publish() local now = os.time() -- Publish built-in statistics if not M.cli then error("no graphite server configured") end - publish_table(merge(map 'cache.stats()'), M.prefix..'.cache', now) - publish_table(merge(map 'worker.stats()'), M.prefix..'.worker', now) + publish_table(cache.stats(), M.prefix..'.cache', now) + publish_table(worker.stats(), M.prefix..'.worker', now) -- Publish extended statistics if available - publish_table(merge(map 'stats.list()'), M.prefix, now) + publish_table(stats.list(), M.prefix, now) return 0 end