]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
graphite: adapt to to changes in map()
authorPetr Špaček <petr.spacek@nic.cz>
Fri, 23 Oct 2020 16:07:59 +0000 (18:07 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Tue, 27 Oct 2020 10:25:54 +0000 (11:25 +0100)
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.

doc/upgrading.rst
etc/config/config.cluster
etc/config/config.splitview
modules/graphite/README.rst
modules/graphite/graphite.lua

index 4f11fc1bcab81979593873717832fa595abf7607..76c5d56bbac7a9e91818dc6a294fdab05a514892 100644 (file)
@@ -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 <mod-graphite>`.
+  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.
index 742d1a54627e900438116d74946b5a5beaefd448..58227bdf64da928cc26cd29e941f3b12d760a6ba 100644 (file)
@@ -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',
        },
index 8e3fb225ad104472f7276aa0a99431b2acfc8e0b..1b1d1983bbb110711c4b26c1407f4db849119b89 100644 (file)
@@ -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',
        },
index cae92a4c913a1facdff005c7725f34252468f9de..2f86a6f148db73585cd7c006eef7c518fcc6f372 100644 (file)
@@ -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
                }
        }
 
index e2ac67eb09e7917d5cd2817bb4e05921595312d2..8f6ba742417a5df986df5ec77a05684e3ef9cf45 100644 (file)
@@ -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