Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed May 14, 2021
1 parent 5be07f6 commit 3ffacda
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions metric_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,42 @@ minetest.register_node("monitoring_digilines:metric_controller", {
receptor = {},
effector = {
action = function(pos, _, channel, msg)
local meta = minetest.get_meta(pos)
if meta:get_string("channel") ~= channel then
return
end
local meta = minetest.get_meta(pos)
if meta:get_string("channel") ~= channel then
return
end

if type(msg) == "table" and msg.metric and msg.value and
type(msg.metric) == "string" and type(msg.value) == "number" then
-- set and/or create metric
if type(msg) == "table" and msg.metric and msg.value and
type(msg.metric) == "string" and type(msg.value) == "number" then
-- set and/or create metric

local metric = monitoring.metrics_mapped[msg.metric]
if not metric then
-- create metric
if msg.counter then
metric = monitoring.counter(
msg.metric,
msg.help or "counter for " .. msg.metric
)
else
metric = monitoring.gauge(
msg.metric,
msg.help or "gauge for " .. msg.metric
)
end
local metric = monitoring.metrics_mapped[msg.metric]
if not metric then
-- create metric
if msg.counter then
metric = monitoring.counter(msg.metric, msg.help or "counter for " .. msg.metric)
else
metric = monitoring.gauge(msg.metric, msg.help or "gauge for " .. msg.metric)
end
end

if metric.type == "gauge" then
if metric.type == "gauge" then
metric.value = msg.value
elseif metric.type == "counter" then
if msg.increment then
metric.value = metric.value + msg.value
else
metric.value = msg.value
elseif metric.type == "counter" then
if msg.increment then
metric.value = metric.value + msg.value
else
metric.value = msg.value
end
end
end
end

if type(msg) == "string" then
-- simple string to get metrics from
local metric = monitoring.metrics_mapped[msg]
if metric then
digiline:receptor_send(pos, digiline.rules.default, channel, metric)
end
if type(msg) == "string" then
-- simple string to get metrics from
local metric = monitoring.metrics_mapped[msg]
if metric then
digiline:receptor_send(pos, digiline.rules.default, channel, metric)
end
end
end
}
Expand Down

0 comments on commit 3ffacda

Please sign in to comment.