From 002d143548874a908d95a80b8c21e1938a262045 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 5 Jan 2017 18:09:00 +0100 Subject: [PATCH] drbd-utils: munin/nagios plugins are vendored --- drbd-utils/README.md | 27 ++++ .../{munin-plugins => munin/drbd-config} | 0 drbd-utils/files/munin/drbd-plugin | 143 ++++++++++++++++++ drbd-utils/files/nagios/check_drbd | 0 drbd-utils/tasks/main.yml | 5 +- drbd-utils/tasks/munin.yml | 11 +- drbd-utils/tasks/nagios.yml | 14 +- 7 files changed, 187 insertions(+), 13 deletions(-) create mode 100644 drbd-utils/README.md rename drbd-utils/files/{munin-plugins => munin/drbd-config} (100%) create mode 100644 drbd-utils/files/munin/drbd-plugin create mode 100644 drbd-utils/files/nagios/check_drbd diff --git a/drbd-utils/README.md b/drbd-utils/README.md new file mode 100644 index 00000000..86ae3aa6 --- /dev/null +++ b/drbd-utils/README.md @@ -0,0 +1,27 @@ +# drbd-utils + +Install tools to setup DRBD replication accross servers. + +## Tasks + +Everything is in the `tasks/main.yml` file. + +## Available variables + +The variable `admin_users` must be a "dict" of one or more users : + +``` +admin_users: + foo: + name: foo + uid: 1001 + fullname: 'Mr Foo' + password_hash: 'sdfgsdfgsdfgsdfg' + ssh_key: 'ssh-rsa AZERTYXYZ' + bar: + name: bar + uid: 1002 + fullname: 'Mr Bar' + password_hash: 'gsdfgsdfgsdfgsdf' + ssh_key: 'ssh-rsa QWERTYUIOP' +``` diff --git a/drbd-utils/files/munin-plugins b/drbd-utils/files/munin/drbd-config similarity index 100% rename from drbd-utils/files/munin-plugins rename to drbd-utils/files/munin/drbd-config diff --git a/drbd-utils/files/munin/drbd-plugin b/drbd-utils/files/munin/drbd-plugin new file mode 100644 index 00000000..63c5a02b --- /dev/null +++ b/drbd-utils/files/munin/drbd-plugin @@ -0,0 +1,143 @@ +#!/usr/bin/perl + +# http://www.drbd.org/users-guide/ch-admin.html#s-proc-drbd + +use strict; + +my $file="/proc/drbd"; +my $store = {}; +my $temp; + +&crunch; +&display; + +sub display{ + if ($ARGV[0] and $ARGV[0] eq "config"){ + print "graph_title DRBD\n"; + print "graph_category DRBD\n"; + print "graph_info Graph DRBD\n"; + print "graph_vlabel Bytes per \${graph_period} read (-) / written (+)\n"; + print "graph_args --base 1024 --lower-limit 0\n"; + + foreach my $key ( keys %$store ){ + my $drbdname = 'drbd'.$key; + print $drbdname."dr.label $drbdname disk\n"; + print $drbdname."dr.cdef ".$drbdname."dr,819,*\n"; + print $drbdname."dr.type DERIVE\n"; + print $drbdname."dr.min 0\n"; + print $drbdname."dr.graph no\n"; + print $drbdname."dw.label $drbdname disk\n"; + print $drbdname."dw.cdef ".$drbdname."dw,819,*\n"; + print $drbdname."dw.type DERIVE\n"; + print $drbdname."dw.min 0\n"; + print $drbdname."dw.negative ".$drbdname."dr\n"; + print $drbdname."nr.label $drbdname net\n"; + print $drbdname."nr.cdef ".$drbdname."nr,819,*\n"; + print $drbdname."nr.type DERIVE\n"; + print $drbdname."nr.min 0\n"; + print $drbdname."nr.graph no\n"; + print $drbdname."ns.label $drbdname net\n"; + print $drbdname."ns.cdef ".$drbdname."ns,819,*\n"; + print $drbdname."ns.type DERIVE\n"; + print $drbdname."ns.min 0\n"; + print $drbdname."ns.negative ".$drbdname."nr\n"; + } + exit 0; + } + + foreach my $key ( keys %$store ){ + my $drbdname = 'drbd'.$key; + print $drbdname."dw.value ".$store->{$key}->{'dw'}."\n"; + print $drbdname."dr.value ".$store->{$key}->{'dr'}."\n"; + print $drbdname."ns.value ".$store->{$key}->{'ns'}."\n"; + print $drbdname."nr.value ".$store->{$key}->{'nr'}."\n"; + } +} + +sub crunch{ +open (IN, $file ) || die "Could not open $file for reading: $!"; + while (){ + next if /version:|GIT-hash:/; + chomp; + + my ($drbd) = $_ =~ /^\s+(\d):/; + $temp = $drbd if $drbd =~ /\d/; + + if (/resync/){ + my ($hits) = $_ =~ /hits:(\d*)/; + $store->{ $temp }->{'resync'}->{hits} = $hits if $hits ne undef; + + my ($misses) = $_ =~ /misses:(\d*)/; + $store->{ $temp }->{'resync'}->{misses} = $misses if $misses ne undef; + + my ($starving) = $_ =~ /starving:(\d*)/; + $store->{ $temp }->{'resync'}->{starving} = $starving if $starving ne undef; + + my ($dirty) = $_ =~ /dirty:(\d*)/; + $store->{ $temp }->{'resync'}->{dirty} = $dirty if $dirty ne undef; + + my ($changed) = $_ =~ /changed:(\d*)/; + $store->{ $temp }->{'resync'}->{changed} = $changed if $changed ne undef; + } + + if (/act_log/){ + my ($hits) = $_ =~ /hits:(\d*)/; + $store->{ $temp }->{'act_log'}->{hits} = $hits if $hits ne undef; + + my ($misses) = $_ =~ /misses:(\d*)/; + $store->{ $temp }->{'act_log'}->{misses} = $misses if $misses ne undef; + + my ($starving) = $_ =~ /starving:(\d*)/; + $store->{ $temp }->{'act_log'}->{starving} = $starving if $starving ne undef; + + my ($dirty) = $_ =~ /dirty:(\d*)/; + $store->{ $temp }->{'act_log'}->{dirty} = $dirty if $dirty ne undef; + + my ($changed) = $_ =~ /changed:(\d*)/; + $store->{ $temp }->{'act_log'}->{changed} = $changed if $changed ne undef; + } + + my ($ns) = $_ =~ /ns:(\d*)/; + $store->{ $temp }->{'ns'} = $ns if $ns ne undef; + + my ($nr) = $_ =~ /nr:(\d*)/; + $store->{ $temp }->{'nr'} = $nr if $ns ne undef; + + my ($dw) = $_ =~ /dw:(\d*)/; + $store->{ $temp }->{'dw'} = $dw if $dw ne undef; + + my ($dr) = $_ =~ /dr:(\d*)/; + $store->{ $temp }->{'dr'} = $dr if $dr ne undef; + + my ($al) = $_ =~ /al:(\d*)/; + $store->{ $temp }->{'al'} = $al if $dr ne undef; + + my ($bm) = $_ =~ /bm:(\d*)/; + $store->{ $temp }->{'bm'} = $bm if $dr ne undef; + + my ($lo) = $_ =~ /lo:(\d*)/; + $store->{ $temp }->{'lo'} = $lo if $dr ne undef; + + my ($pe) = $_ =~ /pe:(\d*)/; + $store->{ $temp }->{'pe'} = $pe if $dr ne undef; + + my ($ua) = $_ =~ /ua:(\d*)/; + $store->{ $temp }->{'ua'} = $ua if $dr ne undef; + + my ($ap) = $_ =~ /ap:(\d*)/; + $store->{ $temp }->{'ap'} = $ap if $ap ne undef; + + my ($hits) = $_ =~ /hits:(\d*)/; + $store->{ $temp }->{'hits'} = $hits if $hits ne undef; + + my ($used) = $_ =~ /used:(\d*\\\d*)\s/; + $store->{ $temp }->{'used'} = $used if $used ne undef; +} + +close (IN); + +#print Dumper \$store; + +} + +exit 0; diff --git a/drbd-utils/files/nagios/check_drbd b/drbd-utils/files/nagios/check_drbd new file mode 100644 index 00000000..e69de29b diff --git a/drbd-utils/tasks/main.yml b/drbd-utils/tasks/main.yml index 2ffb0580..6e0eca0a 100644 --- a/drbd-utils/tasks/main.yml +++ b/drbd-utils/tasks/main.yml @@ -1,9 +1,6 @@ --- - include: packages.yml -- name: Mount /usr in rw - command: mount -o remount,rw /usr warn=no - changed_when: False - - include: munin.yml + - include: nagios.yml diff --git a/drbd-utils/tasks/munin.yml b/drbd-utils/tasks/munin.yml index ca96909f..c761bc6e 100644 --- a/drbd-utils/tasks/munin.yml +++ b/drbd-utils/tasks/munin.yml @@ -1,14 +1,15 @@ --- +# https://raw.githubusercontent.com/munin-monitoring/contrib/master/plugins/drbd/drbd - name: Get Munin plugin - get_url: - url: 'https://raw.githubusercontent.com/munin-monitoring/contrib/master/plugins/drbd/drbd' - dest: '/etc/munin/plugins/' + copy: + src: munin/drbd-plugin + dest: /etc/munin/plugins/drbd mode: "755" notify: restart munin-node - name: Copy Munin plugin conf copy: - src: files/munin-plugins - dest: '/etc/munin/plugin-conf.d/drbd' + src: munin/drbd-config + dest: /etc/munin/plugin-conf.d/drbd notify: restart munin-node diff --git a/drbd-utils/tasks/nagios.yml b/drbd-utils/tasks/nagios.yml index 41e8eab4..148adb75 100644 --- a/drbd-utils/tasks/nagios.yml +++ b/drbd-utils/tasks/nagios.yml @@ -1,6 +1,12 @@ --- -- name: Get Nagios plugin - get_url: - url: 'https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=3367&cf_id=30' - dest: '/usr/local/lib/nagios/plugins/check_drbd' + +- name: Mount /usr in rw + command: mount -o remount,rw /usr warn=no + changed_when: False + +# https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=3367&cf_id=30 +- name: Install Nagios plugin + copy: + src: "nagios/check_drbd" + dest: "/usr/local/lib/nagios/plugins/check_drbd" mode: "755"