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

Commit

Permalink
import
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jun 26, 2020
0 parents commit 772e2d9
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: luacheck

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt-get install -y luarocks
- name: luacheck install
run: luarocks install --local luacheck
- name: luacheck run
run: $HOME/.luarocks/bin/luacheck ./
18 changes: 18 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
allow_defined_top = true

globals = {
"monitoring",
"minetest",
"mesecon"
}

read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},

-- Minetest
"vector", "ItemStack",
"dump"

}
22 changes: 22 additions & 0 deletions action_on.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

function register_action_on_metric(nodename, metricname, prettyname)
local nodedef = minetest.registered_nodes[nodename]
if nodedef and nodedef.mesecons and nodedef.mesecons.effector and nodedef.mesecons.effector.action_on then
local metric_count = monitoring.counter("mesecons_" .. metricname .. "_count",
"number of " .. prettyname .. " executes")
local metric_time = monitoring.counter("mesecons_" .. metricname .. "_time",
"total time of " .. prettyname .. " executes in us")

nodedef.mesecons.effector.action_on = metric_count.wrap( metric_time.wraptime(nodedef.mesecons.effector.action_on) )

end
end

register_action_on_metric("mesecons_pistons:piston_normal_off", "piston_normal_on", "Piston")
register_action_on_metric("mesecons_pistons:piston_sticky_off", "piston_sticky_on", "Sticky piston")

register_action_on_metric("mesecons_movestones:movestone", "movestone", "Movestone")
register_action_on_metric("mesecons_movestones:sticky_movestone", "sticky_movestone", "Sticky movestone")
register_action_on_metric("mesecons_movestones:movestone_vertical", "movestone_vertical", "Vertical movestone")
register_action_on_metric("mesecons_movestones:sticky_movestone_vertical",
"sticky_movestone_vertical", "Vertical sticky movestone")
40 changes: 40 additions & 0 deletions functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


local metrics = {} -- { { count=, time= }, ... }


function register_function(name)
local entry = {}
entry.count = monitoring.counter("mesecons_function_" .. name .. "_count",
"number of " .. name .. " function executes")
entry.time = monitoring.counter("mesecons_function_" .. name .. "_time",
"time of " .. name .." function executes")

metrics[name] = entry
end

register_function("change");
register_function("lc_interrupt");
register_function("lc_digiline_relay");
register_function("deactivate");
register_function("activate");
register_function("receptor_on");
register_function("receptor_off");
register_function("other");

local old_execute = mesecon.queue.execute
mesecon.queue.execute = function(self, action)

local t0 = minetest.get_us_time()
old_execute(self, action)
local t1 = minetest.get_us_time()
local delta_t = t1 - t0

local metric = metrics[action.func]
if not metric then
metric = metrics["other"]
end

metric.count.inc()
metric.time.inc(delta_t)
end
30 changes: 30 additions & 0 deletions globals.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


monitoring.wrap_global({"mesecon", "queue", "add_action"}, "mesecons_queue_action_add")
local execute_calls_metric = monitoring.wrap_global({"mesecon", "queue", "execute"}, "mesecons_queue_execute")

if monitoring.settings.handle_errors then
-- enable error handling in mesecons queue
local old_execute = mesecon.queue.execute
mesecon.queue.execute = function(self, action)
monitoring.protected_call(execute_calls_metric, function()
old_execute(self, action)
end, action.pos)
end
end

if minetest.settings:get_bool("monitoring.mesecons.verbose") then

monitoring.wrap_global({"mesecon", "get_node_force"}, "mesecons_get_node_force")
monitoring.wrap_global({"mesecon", "activate"}, "mesecons_activate")
monitoring.wrap_global({"mesecon", "deactivate"}, "mesecons_deactivate")
monitoring.wrap_global({"mesecon", "turnon"}, "mesecons_turnon")
monitoring.wrap_global({"mesecon", "turnoff"}, "mesecons_turnoff")
monitoring.wrap_global({"mesecon", "changesignal"}, "mesecons_changesignal")
monitoring.wrap_global({"mesecon", "swap_node_force"}, "swap_node_force")

monitoring.wrap_global({"mesecon", "vm_begin"}, "mesecons_vm_begin")
monitoring.wrap_global({"mesecon", "vm_abort"}, "mesecons_vm_abort")
monitoring.wrap_global({"mesecon", "vm_commit"}, "mesecons_vm_commit")

end
19 changes: 19 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if not minetest.get_modpath("mesecons") then
print("[monitoring] mesecons extension not loaded")
return
else
print("[monitoring] mesecons extension loaded")
end


local MP = minetest.get_modpath("monitoring_mesecons")

dofile(MP.."/queue.lua")
dofile(MP.."/globals.lua")
dofile(MP.."/luac.lua")

if minetest.settings:get_bool("monitoring.mesecons.verbose") then
dofile(MP.."/functions.lua")
end

dofile(MP.."/action_on.lua")
56 changes: 56 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
License of source code
----------------------

The MIT License (MIT)
Copyright (C) 2018-2019 Thomas Rudin

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

For more details:
https://opensource.org/licenses/MIT


Licenses of media (textures)
----------------------------

Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2019 Thomas Rudin

You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:

Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.

ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.

No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.

Notices:

You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
47 changes: 47 additions & 0 deletions luac.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

local BASENAME = "mesecons_luacontroller:luacontroller"


local metric_count = monitoring.counter(
"mesecons_luacontroller_nodetimer_count",
"number of luac nodetimer calls"
);

local metric_time = monitoring.counter(
"mesecons_luacontroller_nodetimer_time",
"time of luac nodetimer calls"
);

local metric_time_max = monitoring.gauge(
"mesecons_luacontroller_nodetimer_time_max",
"max time of luac nodetimer calls",
{ autoflush=true }
)

for a = 0, 1 do -- 0 = off 1 = on
for b = 0, 1 do
for c = 0, 1 do
for d = 0, 1 do
local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
local node_name = BASENAME..cid

local def = minetest.registered_nodes[node_name]

if def then
local old_on_timer = def.on_timer

def.on_timer = function(...)
local t0 = minetest.get_us_time()
old_on_timer(...)
local t1 = minetest.get_us_time()
local diff = t1 -t0

metric_time_max.setmax(diff)
metric_time.inc(diff)
metric_count.inc(1)
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = monitoring_mesecons
depends = monitoring
optional_depends = mesecons, mesecons_pistons, mesecons_movestones, mesecons_debug, mesecons_luacontroller
23 changes: 23 additions & 0 deletions queue.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@



-- queue size metric
local metric_action_queue_size = monitoring.gauge(
"mesecons_action_queue_size",
"size of action queue"
)

local metric_action_queue_size_max = monitoring.gauge(
"mesecons_action_queue_size_max",
"max size of action queue",
{ autoflush=true }
)

minetest.register_globalstep(function()
if not mesecon.queue.actions then
return
end

metric_action_queue_size.set(#mesecon.queue.actions)
metric_action_queue_size_max.setmax(#mesecon.queue.actions)
end)
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Monitoring extension for mesecons

Base-mod: https://github.com/thomasrudin-mt/monitoring

# Metrics

* mesecons_action_queue_count *number of action queue items*
* various, see `metrics.lua`

# Settings

* **monitoring.mesecons.verbose** more metrics

# License

MIT

0 comments on commit 772e2d9

Please sign in to comment.