{"id":80,"date":"2009-03-12T11:16:18","date_gmt":"2009-03-12T11:16:18","guid":{"rendered":"http:\/\/www.piglets.org\/?p=80"},"modified":"2015-10-06T14:09:19","modified_gmt":"2015-10-06T14:09:19","slug":"my-first-munin-plugin","status":"publish","type":"post","link":"https:\/\/www.piglets.org\/blog\/2009\/03\/12\/my-first-munin-plugin\/","title":{"rendered":"My first Munin plugin"},"content":{"rendered":"<p><a href=\"http:\/\/munin.projects.linpro.no\/\">Munin<\/a> is a great, really useful project for monitoring all sorts of things on servers over short and long term periods, and can help identify and even warn of undue server loads. It is also appropriately and poetically named for one of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Odinn\">Odinn's<\/a> crows (so I suppose I should have written this on a Wednesday).<\/p>\n<p>We've been running Munin on one of our <a href=\"http:\/\/fs1.ulster.ac.uk\/munin\/\">production servers<\/a> at work for quite some time, and it gives us a lot of confidence that, to say the least, the server is running in its comfort zone around the clock. Among other bits and pieces, we run <a href=\"http:\/\/foss.ulster.ac.uk\/projects\/opus\">OPUS<\/a> and the <a href=\"http:\/\/foss.ulster.ac.uk\/projects\/pdsystem\">PDSystem<\/a> on this box, two of our home grown projects that are available to the students. For some time now I've considered writing a plugin for OPUS to show logged in users, and I finally did this, albeit the counts are not nearly so reliable as I'd like for two reasons, but I'll probably discuss that in another post. Anyway, I arranged for OPUS to drop a simple text file which simply contains counts of online users with the syntax<\/p>\n<pre>\r\nstudent: 10\r\nadmin: 2\r\n<\/pre>\n<p>and so on, for each of the categories of users. Then I needed a plugin to deal with this. I decided to write it simple shell script, since its portable and I'm not much of a perl fan.<\/p>\n<pre lang=Shell>\r\n#!\/bin\/sh\r\n\r\n#\r\n# Munin plugin for OPUS showing online users\r\n# Copyright Colin Turner\r\n# GPL V2+\r\n#\r\n\r\n# Munin plugins, at their simplest, are run either with \"config\" or\r\n# no parameters (I plan to add auto configuration later).\r\ncase $1 in\r\n  config)\r\n  # In config mode, we spout out details of the graphs we will have\r\n  # I want one graph, with lots of stacked values. The first one is\r\n  # an AREA, and the others are stacked above them. I also (-l 0)\r\n  # make sure the graph shows everything down to zero.\r\n\tcat <<'EOM'\r\ngraph_title OPUS online users\r\ngraph_args -l 0\r\ngraph_vlabel online users\r\ngraph_info The number of online users on OPUS is shown.\r\nstudent.label student\r\nstudent.min 0\r\nstudent.draw AREA\r\nstaff.label academic\r\nstaff.min 0\r\nstaff.draw STACK\r\ncompany.label hr staff\r\ncompany.min 0\r\ncompany.draw STACK\r\nsupervisor.label supervisor\r\nsupervisor.min 0\r\nsupervisor.draw STACK\r\nadmin.label admin\r\nadmin.min 0\r\nadmin.draw STACK\r\nroot.label root\r\nroot.min 0\r\nroot.draw STACK\r\napplication.label application\r\napplication.min 0\r\napplication.draw STACK\r\nEOM\r\n\texit 0;;\r\nesac\r\n\r\n# Now the plugin is being run for data. Bail if the file is unavailable\r\nif [ ! -r \/var\/lib\/opus\/online_users ] ; then\r\n     echo Cannot read \/var\/lib\/opus\/online_users >&2\r\n     exit -1\r\nfi\r\n\r\n# Otherwise, a quick sed converts the default format to what Munin needs\r\ncat \/var\/lib\/opus\/online_users | sed -e \"s\/:\/.value\/\"\r\n<\/pre>\n<p>The plugin has now been running for several days, and you can see its output <a href=\"http:\/\/fs1.ulster.ac.uk\/munin\/ulster.ac.uk\/fs1.ulster.ac.uk-opus_munin.html\">here<\/a>. There are problems with it, but that's more to do with PHP, Debian and user choice, and I'll comment on that another time. However, already it gives me a useful feel for a lot of user behaviour.<\/p>\n<p>Writing Munin plugins is easy, and Munin does so much of the hard work of turning your creation into something useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Munin is a great, really useful project for monitoring all sorts of things on servers over short and long term periods, and can help identify and even warn of undue server loads. It is also appropriately and poetically named for one of Odinn's crows (so I suppose I should have written this on a Wednesday). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"vkexunit_cta_each_option":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[7],"tags":[16,24,120,118],"class_list":["post-80","post","type-post","status-publish","format-standard","hentry","category-11-free-software","tag-free-software","tag-munin","tag-8-php","tag-7-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/p52I4w-1i","_links":{"self":[{"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/posts\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":1,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions\/359"}],"wp:attachment":[{"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.piglets.org\/blog\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}