Skip to content

Commit

Permalink
add ability to write metrics from ingame
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Apr 27, 2020
1 parent 28718b7 commit caae628
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
44 changes: 38 additions & 6 deletions monitoring_digilines/metric_controller.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


minetest.register_node("monitoring_digilines:metric_controller", {
description = "Monitoring metric controller",
groups = {
Expand Down Expand Up @@ -55,15 +54,48 @@ minetest.register_node("monitoring_digilines:metric_controller", {
effector = {
action = function(pos, _, channel, msg)
local meta = minetest.get_meta(pos)
if meta:get_string("channel") ~= channel or type(msg) ~= "string" then
if meta:get_string("channel") ~= channel then
return
end

local value = monitoring.metrics_mapped[msg]
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 value then
digiline:receptor_send(pos, digiline.rules.default, channel, value)
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
metric.set(msg.value)
elseif metric.type == "counter" then
if msg.increment then
metric.inc(msg.value)
else
metric.set(msg.value)
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
end
end
}
}
Expand Down
12 changes: 12 additions & 0 deletions monitoring_digilines/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Monitoring, digilines component

Usage:

Reading:
```lua
if event.type == "program" then
-- query metric by its name
Expand All @@ -18,6 +19,17 @@ if event.type == "digiline" and event.channel == "ctrl_channel" then
end
```

Writing:
```lua
digiline_send("channel", {
metric: "ingame_lua_tube_mese",
help: "my mese lua tube count"
counter: true,
increment: true,
value: 20
})
```

# License

* textures/monitoring_controller_top.png
Expand Down

0 comments on commit caae628

Please sign in to comment.