Last active
August 29, 2015 14:03
-
-
Save teamon/257c8a7ba3c53d3f8ea4 to your computer and use it in GitHub Desktop.
Munin passeger 4 plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nobody ALL=(ALL) NOPASSWD:/usr/local/bin/passenger-status, /usr/local/bin/passenger-memory-stats |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# == Install == | |
# 1. Download this file in /usr/share/munin/plugins/passenger_ | |
# | |
# 2. Symlink passenger_memory and passenger_status | |
# ln -s "/etc/munin/plugins/passenger_memory" "/usr/share/munin/plugins/passenger_" | |
# ln -s "/etc/munin/plugins/passenger_status" "/usr/share/munin/plugins/passenger_" | |
# | |
# 3. Allow user nobody to access passenger tools | |
# # file: /etc/sudoers.d/munin-passenger | |
# nobody ALL=(ALL) NOPASSWD:/usr/local/bin/passenger-status, /usr/local/bin/passenger-memory-stats | |
# | |
# 4. Restart munin-node | |
if($0 =~ /status$/){ | |
if(defined $ARGV[0] and $ARGV[0] eq "config"){ | |
print <<'EOS'; | |
graph_category Passenger | |
graph_title passenger status | |
graph_vlabel count | |
sessions.label sessions | |
sessions.draw LINE2 | |
max.label max processes | |
max.draw LINE1 | |
processes.label running processes | |
processes.draw LINE1 | |
queue.label active processes | |
queue.draw LINE2 | |
EOS | |
} else { | |
my $status = `sudo /usr/local/bin/passenger-status`; | |
my ($max_pool_size) = ($status =~ m/pool size.+?(\d+)/); | |
my ($processes) = ($status =~ m/processes.+?(\d+)/i); | |
my ($queue) = ($status =~ m/queue.+?(\d+)/); | |
my @sessions = $status =~ /sessions.+?(\d+)/ig; | |
my $sessions_count = 0; | |
foreach my $s (@sessions) { | |
$sessions_count += int($s); | |
} | |
print "max.value $max_pool_size\n"; | |
print "processes.value $processes\n"; | |
print "queue.value $queue\n"; | |
print "sessions.value $sessions_count\n"; | |
} | |
} elsif ($0 =~ /memory$/){ | |
if(defined $ARGV[0] and $ARGV[0] eq "config"){ | |
print <<'EOS'; | |
graph_category Passenger | |
graph_title Passenger memory stats | |
graph_vlabel count | |
memory.label memory | |
EOS | |
} else { | |
my $memory = `sudo /usr/local/bin/passenger-memory-stats`; | |
my @apps = $memory =~ /(\d+\.\d+)[MB\s]+Passenger/ig; | |
my $total = 0; | |
foreach my $a (@apps) { | |
$total += ($a * 1000 * 1000); | |
} | |
print "memory.value $total\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment