root/src/modules-lua/noit/module/munin.lua

Revision 3f95e0c50baf9d8aed9d35b63a9a0b40a28e0cbf, 4.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

remnants of the Varnish base, fix from Piotr Sikora

  • Property mode set to 100644
Line 
1 -- Copyright (c) 2010, OmniTI Computer Consulting, Inc.
2 -- All rights reserved.
3 --
4 -- Redistribution and use in source and binary forms, with or without
5 -- modification, are permitted provided that the following conditions are
6 -- met:
7 --
8 --     * Redistributions of source code must retain the above copyright
9 --       notice, this list of conditions and the following disclaimer.
10 --     * Redistributions in binary form must reproduce the above
11 --       copyright notice, this list of conditions and the following
12 --       disclaimer in the documentation and/or other materials provided
13 --       with the distribution.
14 --     * Neither the name OmniTI Computer Consulting, Inc. nor the names
15 --       of its contributors may be used to endorse or promote products
16 --       derived from this software without specific prior written
17 --       permission.
18 --
19 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 -- This connects to a Munin instance on the management port (4949)
32 -- It issues the stats comment and translates the output into metrics
33
34 module(..., package.seeall)
35
36 function onload(image)
37   image.xml_description([=[
38 <module>
39   <name>munin</name>
40   <description><para>Monitor metrics exposed by a munin-node instance.</para></description>
41   <loader>lua</loader>
42   <object>noit.module.munin</object>
43   <moduleconfig />
44   <checkconfig>
45     <parameter name="port" required="optional" default="4949"
46                allowed="\d+">Specifies the port on which the management interface can be reached.</parameter>
47     <parameter name="plugins" required="optional"
48                allowed=".+">A list of space separated plugins from which to fetch metrics. If not specified, a list will be retrieved from the munin node.</parameter>
49   </checkconfig>
50   <examples>
51     <example>
52       <title>Monitor a node running munun-node</title>
53       <para>The following example pulls all munin metrics from 10.1.2.3 and just "processes" metrics from 10.1.2.4</para>
54       <programlisting><![CDATA[
55       <noit>
56         <modules>
57           <loader image="lua" name="lua">
58             <config><directory>/opt/reconnoiter/libexec/modules-lua/?.lua</directory></config>
59           </loader>
60           <module loader="lua" name="munin" object="noit.module.munin"/>
61         </modules>
62         <checks>
63           <check uuid="535cc224-9f66-11df-b198-8b094b17808a" module="munin" target="10.1.2.3" />
64           <check uuid="5acce980-9f66-11df-8027-ebfe9d8b53e1" module="munin" target="10.1.2.4">
65             <config><plugins>processes</plugins></config>
66           </check>
67         </checks>
68       </noit>
69       ]]></programlisting>
70     </example>
71   </examples>
72 </module>
73 ]=]);
74   return 0
75 end
76
77 function init(module)
78   return 0
79 end
80
81 function config(module, options)
82   return 0
83 end
84
85 function initiate(module, check)
86   local e = noit.socket()
87   local plugins = check.config.plugins
88   local rv, err = e:connect(check.target, check.config.port or 4949)
89
90   check.bad()
91   check.unavailable()
92
93   if rv ~= 0 then
94     check.status(err or "connect failed")
95     return
96   end
97
98   str = e:read("\n") -- munin banner
99   if str == nil or str == "" then
100     check.status("no banner, ACL issue?")
101     return
102   end
103
104   e:write("list\r\n")
105   local rplugins = e:read("\n")
106   if rplugins == nil or rplugins == "" then
107     check.status("no plugins")
108     return
109   end
110
111   rplugins = string.gsub(rplugins, "[\r\n]+$", "")
112   check.metric_string("remote_plugins", rplugins)
113   if plugins == nil then plugins = rplugins end
114
115   check.available()
116   local i = 0
117   for p in string.gmatch(plugins, "%s*(%S+)%s*") do
118     e:write("fetch " .. p .. "\r\n")
119     local rawstats = e:read("\.\n")
120     for k, v in string.gmatch(rawstats, "\n?(%S+)\.value%s+([^\r\n]+)") do
121       if v == "U" then
122         check.metric_double(p .. "`" .. k,nil)
123       else
124         check.metric(p .. "`" .. k,v)
125       end
126       i = i + 1
127     end
128   end
129
130   check.status(string.format("%d stats", i))
131   check.good()
132 end
133
Note: See TracBrowser for help on using the browser.