From 91946d5d67dc302bb147f0640cb5614416945891 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Aug 2018 19:50:03 +0100 Subject: [PATCH] Improve PDU monitoring --- cookbooks/munin/files/default/plugins/apcpdu_ | 128 ------------------ .../default/plugins/snmp__apcpdu_current | 40 ++++++ .../files/default/plugins/snmp__apcpdu_power | 36 +++++ .../default/plugins/snmp__apcpdu_voltage | 34 +++++ .../munin/templates/default/munin.conf.erb | 28 ++++ roles/ironbelly.rb | 15 -- 6 files changed, 138 insertions(+), 143 deletions(-) delete mode 100755 cookbooks/munin/files/default/plugins/apcpdu_ create mode 100755 cookbooks/munin/files/default/plugins/snmp__apcpdu_current create mode 100755 cookbooks/munin/files/default/plugins/snmp__apcpdu_power create mode 100755 cookbooks/munin/files/default/plugins/snmp__apcpdu_voltage diff --git a/cookbooks/munin/files/default/plugins/apcpdu_ b/cookbooks/munin/files/default/plugins/apcpdu_ deleted file mode 100755 index 7fada2897..000000000 --- a/cookbooks/munin/files/default/plugins/apcpdu_ +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (c) 2009 - Rune Nordbøe Skillingstad -# Copyright (c) 2009 - Kai Ove Gran -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; version 2 dated June, -# 1991. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -# snmp_host_apcpdu - For APC PDUs. Graphs total current throughput. -# -#%# family=snmpauto -#%# capabilities=snmpconf - -use strict; -use Net::SNMP; - -my $DEBUG = $ENV{DEBUG} || 0; -my $host = $ENV{host} || undef; -my $port = $ENV{port} || 161; -my $community = $ENV{community} || "public"; -my $iface = $ENV{interface} || undef; -my $timeout = $ENV{timeout} || 1; -my $snmp_ver = $ENV{version} || 1; - -if($0 =~ /^(?:|.*\/)apcpdu_([^_]+)$/) { - $host = $1; - if($host =~ /^([^:]+):(\d+)$/) { - $host = $1; - $port = $2; - } -} elsif(!defined($host)) { - die "# Error: couldn't understand what I'm supposed to monitor."; -} - -my @oidsList = ( - '1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1', - '1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.1', - '1.3.6.1.4.1.318.1.1.12.1.7.0' -); - -if(defined $ARGV[0] and $ARGV[0] eq "snmpconf") { - for(my $i = 0; $i < @oidsList; $i++) { - print "require " . $oidsList[$i] . "[0-9]\n"; - } - exit 0; -} - -my ($session, $error) = Net::SNMP->session( - -hostname => $host, - -community => $community, - -port => $port, - -timeout => $timeout, - -version => $snmp_ver, -); - -if(!defined ($session)) { - die "# Croaking: $error"; -} - -if($ARGV[0] and $ARGV[0] eq "config") { - my $name = &get_single($session, '1.3.6.1.4.1.318.1.1.4.3.3.0'); - if($name) { -# print "host_name $host\n" unless $host eq 'localhost'; - print "graph_title Current for $name\n"; - print "graph_args --base 1000 -l 0\n"; - print "graph_vlabel Amps\n"; - print "graph_category Ups\n"; - print "graph_info This graph shows the total throughput of the PDU\n"; - print "graph_order load threshold rating\n"; - print "load.label Load\n"; - print "load.type GAUGE\n"; - print "load.info Current load in amps.\n"; - print "load.draw LINE2\n"; - print "threshold.label Threshold\n"; - print "threshold.type GAUGE\n"; - print "threshold.info Near overload threshold.\n"; - print "threshold.draw LINE2\n"; - print "rating.label Rating\n"; - print "rating.type GAUGE\n"; - print "rating.info Rating (Max amps).\n"; - print "rating.draw LINE2\n"; - } - exit 0; -} - -my @response = &get_multiple($session, @oidsList); - -printf "load.value %.02f\n", $response[0] / 10; -printf "threshold.value %d\n", $response[1]; -printf "rating.value %d\n", $response[2]; - - -sub get_multiple { - my $handle = shift; - my @oids = @_; - - my @result; - foreach my $oid (@oids) { - push(@result, &get_single($handle,$oid)); - } - chomp @result; - return @result; -} - -sub get_single { - my ($handle, $oid) = @_; - - my $response = $handle->get_request ($oid); - if(!defined $response->{$oid}) { - print "# No response\n" if $DEBUG; - return ""; - } else { - print "# Got response \"".$response->{$oid}."\"\n" if $DEBUG; - return $response->{$oid}; - } -} diff --git a/cookbooks/munin/files/default/plugins/snmp__apcpdu_current b/cookbooks/munin/files/default/plugins/snmp__apcpdu_current new file mode 100755 index 000000000..edf5d99e7 --- /dev/null +++ b/cookbooks/munin/files/default/plugins/snmp__apcpdu_current @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +=head1 MAGIC MARKERS + + #%# family=snmpauto + #%# capabilities=snmpconf + +=cut + +use strict; +use warnings; +use Munin::Plugin::SNMP; + +my $session = Munin::Plugin::SNMP->session; + +if (defined $ARGV[0] and $ARGV[0] eq "config") { + my $host = $session->hostname; + my $warning = $session->get_single(".1.3.6.1.4.1.318.1.1.26.6.1.1.6.1"); + my $critical = $session->get_single(".1.3.6.1.4.1.318.1.1.26.6.1.1.7.1"); + + print "host_name $host\n" unless $host eq "localhost"; + print "graph_title Load\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel Amps\n"; + print "graph_category power\n"; + print "graph_info This graph shows the total throughput the PDU.\n"; + + print "current.label Current\n"; + print "current.type GUAGE\n"; + print "current.info Current load in amps.\n"; + print "current.draw LINE2\n"; + print "current.warning ${warning}\n"; + print "current.critical ${critical}\n"; +} else { + my $current = $session->get_single(".1.3.6.1.4.1.318.1.1.26.6.3.1.5.1"); + + $current = $current / 10 unless $current eq "U"; + + print "current.value ${current}\n"; +} diff --git a/cookbooks/munin/files/default/plugins/snmp__apcpdu_power b/cookbooks/munin/files/default/plugins/snmp__apcpdu_power new file mode 100755 index 000000000..e873bf03a --- /dev/null +++ b/cookbooks/munin/files/default/plugins/snmp__apcpdu_power @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +=head1 MAGIC MARKERS + + #%# family=snmpauto + #%# capabilities=snmpconf + +=cut + +use strict; +use warnings; +use Munin::Plugin::SNMP; + +my $session = Munin::Plugin::SNMP->session; + +if (defined $ARGV[0] and $ARGV[0] eq "config") { + my $host = $session->hostname; + + print "host_name $host\n" unless $host eq "localhost"; + print "graph_title Power\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel Watts\n"; + print "graph_category power\n"; + print "graph_info This graph shows the power being supplied by the PDU.\n"; + + print "power.label Power\n"; + print "power.type GUAGE\n"; + print "power.info Current power draw in watts.\n"; + print "power.draw LINE2\n"; +} else { + my $power = $session->get_single(".1.3.6.1.4.1.318.1.1.26.6.3.1.7.1"); + + $power = $power * 10 unless $power eq "U"; + + print "power.value ${power}\n"; +} diff --git a/cookbooks/munin/files/default/plugins/snmp__apcpdu_voltage b/cookbooks/munin/files/default/plugins/snmp__apcpdu_voltage new file mode 100755 index 000000000..70ec475e8 --- /dev/null +++ b/cookbooks/munin/files/default/plugins/snmp__apcpdu_voltage @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +=head1 MAGIC MARKERS + + #%# family=snmpauto + #%# capabilities=snmpconf + +=cut + +use strict; +use warnings; +use Munin::Plugin::SNMP; + +my $session = Munin::Plugin::SNMP->session; + +if (defined $ARGV[0] and $ARGV[0] eq "config") { + my $host = $session->hostname; + + print "host_name $host\n" unless $host eq "localhost"; + print "graph_title Voltage\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel Volts\n"; + print "graph_category power\n"; + print "graph_info This graph shows the voltage being supplied by the PDU.\n"; + + print "voltage.label Voltage\n"; + print "voltage.type GUAGE\n"; + print "voltage.info Current voltage.\n"; + print "voltage.draw LINE2\n"; +} else { + my $voltage = $session->get_single(".1.3.6.1.4.1.318.1.1.26.6.3.1.6.1"); + + print "voltage.value ${voltage}\n"; +} diff --git a/cookbooks/munin/templates/default/munin.conf.erb b/cookbooks/munin/templates/default/munin.conf.erb index 271d0c3e1..3ecb9c12b 100644 --- a/cookbooks/munin/templates/default/munin.conf.erb +++ b/cookbooks/munin/templates/default/munin.conf.erb @@ -89,6 +89,34 @@ unknown_limit 144 <% end -%> <% end -%> <% end -%> + +# Configure monitoring for pdu1.ams.openstreetmap.org +[pdu1.ams.openstreetmap] + address 10.0.48.10 + use_node_name no + +# Configure monitoring for pdu1.ams.openstreetmap.org +[pdu2.ams.openstreetmap] + address 10.0.48.10 + use_node_name no + +# Configure compound graphs for ams.openstreetmap.org +[ams.openstreetmap] + update no + apcpdu_current.graph_title Load + apcpdu_current.graph_args --lower-limit 0 + apcpdu_current.graph_vlabel Amps + apcpdu_current.graph_category power + apcpdu_current.current.sum pdu1.ams.openstreetmap:snmp_pdu1.ams.openstreetmap.org_apcpdu_current.current pdu2.ams.openstreetmap:snmp_pdu2.ams.openstreetmap.org_apcpdu_current.current + apcpdu_current.current.label Current + apcpdu_current.current.min 0 + apcpdu_power.graph_title Load + apcpdu_power.graph_args --base 1000 --lower-limit 0 + apcpdu_power.graph_vlabel Watts + apcpdu_power.graph_category power + apcpdu_power.power.sum pdu1.ams.openstreetmap:snmp_pdu1.ams.openstreetmap.org_apcpdu_power.power pdu2.ams.openstreetmap:snmp_pdu2.ams.openstreetmap.org_apcpdu_power.power + apcpdu_power.power.label Power + apcpdu_power.power.min 0 <% unless @frontends.empty? && @backends.empty? -%> # Configure compound graphs for www.openstreetmap.org diff --git a/roles/ironbelly.rb b/roles/ironbelly.rb index 1694191e1..8a9c3f741 100644 --- a/roles/ironbelly.rb +++ b/roles/ironbelly.rb @@ -26,21 +26,6 @@ default_attributes( :data => "/store/elasticsearch" } }, - :munin => { - :graphs => { - :apcpdu_ams => { - :title => "Current for Amsterdam", - :vlabel => "Amps", - :category => "Ups", - :values => { - :load => { - :sum => ["apcpdu_pdu1.load", "apcpdu_pdu2.load"], - :label => "Load" - } - } - } - } - }, :networking => { :interfaces => { :internal_ipv4 => { -- 2.39.5