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.
'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',
},
'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',
},
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
}
}
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 = {
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
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
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