Software /
code /
prosody-modules
Comparison
mod_munin/mod_munin.lua @ 1648:648ce9087902
mod_munin: Cleanup [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 07 Apr 2015 17:04:06 +0200 |
parent | 1624:0f20390f6fa5 |
child | 1676:accbf0db0246 |
comparison
equal
deleted
inserted
replaced
1647:8860405e2af6 | 1648:648ce9087902 |
---|---|
2 | 2 |
3 local s_format = string.format; | 3 local s_format = string.format; |
4 local array = require"util.array"; | 4 local array = require"util.array"; |
5 local it = require"util.iterators"; | 5 local it = require"util.iterators"; |
6 local mt = require"util.multitable"; | 6 local mt = require"util.multitable"; |
7 local set = require"util.set"; | |
8 | 7 |
9 local meta = mt.new(); meta.data = module:shared"meta"; | 8 local meta = mt.new(); meta.data = module:shared"meta"; |
10 local data = mt.new(); data.data = module:shared"data"; | 9 local data = mt.new(); data.data = module:shared"data"; |
11 | 10 |
12 local munin_listener = {}; | 11 local munin_listener = {}; |
45 | 44 |
46 function munin_commands.cap(conn) | 45 function munin_commands.cap(conn) |
47 conn:write("cap\n"); | 46 conn:write("cap\n"); |
48 end | 47 end |
49 | 48 |
50 function munin_commands.list(conn, line) | 49 function munin_commands.list(conn) |
51 conn:write(array(it.keys(data.data)):concat(" ") .. "\n"); | 50 conn:write(array(it.keys(data.data)):concat(" ") .. "\n"); |
52 end | 51 end |
53 | 52 |
54 function munin_commands.config(conn, line) | 53 function munin_commands.config(conn, line) |
55 -- TODO what exactly? | 54 -- TODO what exactly? |
56 local stat = line:match("%s(%S+)"); | 55 local stat = line:match("%s(%S+)"); |
57 if not stat then conn:write("# Unknown service\n.\n"); return end | 56 if not stat then conn:write("# Unknown service\n.\n"); return end |
58 for key, name, k, value in meta:iter(stat, "", nil) do | 57 for _, _, k, value in meta:iter(stat, "", nil) do |
59 conn:write(s_format("%s %s\n", k, value)); | 58 conn:write(s_format("%s %s\n", k, value)); |
60 end | 59 end |
61 for key, name, k, value in meta:iter(stat, nil, nil) do | 60 for _, name, k, value in meta:iter(stat, nil, nil) do |
62 if name ~= "" then | 61 if name ~= "" then |
63 conn:write(s_format("%s.%s %s\n", name, k, value)); | 62 conn:write(s_format("%s.%s %s\n", name, k, value)); |
64 end | 63 end |
65 end | 64 end |
66 conn:write(".\n"); | 65 conn:write(".\n"); |
67 end | 66 end |
68 | 67 |
69 function munin_commands.fetch(conn, line) | 68 function munin_commands.fetch(conn, line) |
70 local stat = line:match("%s(%S+)"); | 69 local stat = line:match("%s(%S+)"); |
71 if not stat then conn:write("# Unknown service\n.\n"); return end | 70 if not stat then conn:write("# Unknown service\n.\n"); return end |
72 for key, name, value in data:iter(stat, nil) do | 71 for _, name, value in data:iter(stat, nil) do |
73 conn:write(s_format("%s.value %s\n", name, tostring(value))); | 72 conn:write(s_format("%s.value %s\n", name, tostring(value))); |
74 end | 73 end |
75 conn:write(".\n"); | 74 conn:write(".\n"); |
76 end | 75 end |
77 | 76 |
107 elseif not meta:get(key, name, "label") then | 106 elseif not meta:get(key, name, "label") then |
108 meta:set(key, name, "label", name); | 107 meta:set(key, name, "label", name); |
109 end | 108 end |
110 | 109 |
111 data:set(key, name, value); | 110 data:set(key, name, value); |
112 else | |
113 -- module:log("debug", "Ignoring stat %q", stat); | |
114 end | 111 end |
115 end | 112 end |
116 end); | 113 end); |
117 | 114 |
118 module:provides("net", { | 115 module:provides("net", { |