Skip to content

Instantly share code, notes, and snippets.

@nextensible
Created December 30, 2014 13:24
Show Gist options
  • Save nextensible/573de236d6f5b6a80bf7 to your computer and use it in GitHub Desktop.
Save nextensible/573de236d6f5b6a80bf7 to your computer and use it in GitHub Desktop.
Munin Plugin for NaviServer Uptime
#!/usr/bin/env tclsh
#
# Wildcard-script to monitor the memory usage of a running naviserver instance.
# To monitor a naviserver instance named "development", link this plugin such as:
#
# ln /usr/share/munin/node/plugins-contrib/naviserver_memsize /etc/munin/node.d/naviserver_development_memsize
#
# To configure this plugin put something like the
# following into /etc/munin/plugin-conf.d/naviserver
#
# [naviserver_*]
# env.url /SYSTEM/munin?t=
#
# [naviserver_development_*]
# env.address localhost
# env.port 8000
# env.ssl false
#
lassign [split $argv0 _] . serverName service
array set config {
address localhost
port 8000
ssl false
url /SYSTEM/munin?t=
}
foreach n [array names config] {
if {[info exists ::env($n)]} {
#puts "override $n with $::env($n)"
set config($n) $::env($n)
}
}
if {$argv eq "config" } {
puts "graph_title $serverName nsd uptime "
puts "graph_category naviserver"
puts "graph_info This graph shows the uptime in days for NaviServer instance $serverName"
puts "graph_args --lower-limit 0"
puts "uptime.label uptime"
puts "uptime.info Uptime"
puts "uptime.type GAUGE"
puts "uptime.min 0"
return
}
if {$config(ssl)} {
# The following catch is due to a seemingly incorrect setup for tcl in fedora core.
if {[catch {package req tls}]} {lappend auto_path /usr/lib/tcl8.5; package req tls}
set f [tls::socket $config(address) $config(port)]
} else {
set f [socket $config(address) $config(port)]
}
puts $f "GET $config(url)$service HTTP/1.0\n"
flush $f
set content [read $f]
close $f
foreach line [split $content \n] {
set line [string trim $line]
if {$line eq ""} {set output 1; continue}
if {[info exists output]} {puts $line}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment