/bin/plugins/slapd_bdb_cache_

https://github.com/ebonyeye/sonic-dns-munin · Perl · 158 lines · 97 code · 11 blank · 50 comment · 31 complexity · 2c68129e7aa9e9a4f25b6027789dcfdd MD5 · raw file

  1. #!/usr/bin/perl -w
  2. # -*- perl -*-
  3. #
  4. # Plugin copyright Bjorn Ruberg <bjorn@ruberg.no> 2005-2009
  5. #
  6. # Licensed under GPLv2. Be nice.
  7. #
  8. # Environment variables:
  9. #
  10. # - dbstat The full path to a db_stat binary able to
  11. # communicate with the LDAP backend BDB
  12. # database files. RHEL and friends use
  13. # slapd_db_stat, while Debian and such use
  14. # e.g. db4.6_stat.
  15. # - dbdir The full path to the directory where
  16. # the LDAP backend BDB database files are.
  17. # - title (Optional) The plugin's title. Useful if you
  18. # have more than one DIT installed.
  19. # - warning (Optional) A threshold integer value. Triggers
  20. # plugin to send warnings if cache percentage
  21. # drops below the given value.
  22. #
  23. # Limitations:
  24. #
  25. # - The plugin only checks _one_ database directory. To work
  26. # around that, i.e. if you have more than one DIT in your
  27. # OpenLDAP, create symlinked files and corresponding entries
  28. # in the Munin environment file(s). Note that this will
  29. # break autoconf, i.e. autoconf will probably still suggest
  30. # a default set of symlinks.
  31. #
  32. # Sample config for multiple database directories:
  33. # [slapd_bdb_cache_*]
  34. # env.dbstat /usr/bin/db4.6_stat
  35. #
  36. # [slapd_bdb_cache_database1_*]
  37. # env.dbdir /var/lib/ldap/database1
  38. #
  39. # [slapd_bdb_cache_database2_*]
  40. # env.dbdir /var/lib/ldap/database2
  41. #
  42. # Magic markers
  43. #%# family=auto
  44. #%# capabilities=autoconf suggest
  45. use strict;
  46. use vars qw ( $measure $config $dbdir $dbstat $warning);
  47. my $arg = shift (@ARGV);
  48. # Finding db_stat should be done here
  49. $dbstat = ($ENV{'dbstat'} || "/usr/bin/db4.6_stat");
  50. # Also the LDAP database files
  51. $dbdir = ($ENV{'dbdir'} || "/var/lib/ldap");
  52. # And the graph title
  53. my $title = ($ENV{'title'} || '');
  54. # Die if no valid file ending, unless suggest/autoconf.
  55. if ($0 !~ /_(pages|percent)$/) {
  56. unless ($arg && $arg =~ /^(suggest|autoconf)$/) {
  57. die ("Plugin must be suffixed with 'percent' or 'pages'. Try running 'munin-node-configure suggest'");
  58. }
  59. }
  60. # Check file name
  61. if ($0 =~ /_pages$/) {
  62. $measure = "pages";
  63. } elsif ($0 =~ /_percent$/) {
  64. $measure = "percent";
  65. }
  66. # Parse command line arguments
  67. if ($arg && $arg eq "config") {
  68. $config = 1;
  69. } elsif ($arg && $arg eq "autoconf") {
  70. if (! -x $dbstat) {
  71. print "no (Can't execute db_stat file '$dbstat')\n";
  72. } elsif (-d $dbdir && -r $dbdir) {
  73. print "no (Can't open database directory '$dbdir')";
  74. } else {
  75. print "yes\n";
  76. }
  77. exit 0;
  78. } elsif ($arg && $arg eq "suggest") {
  79. print "pages\n";
  80. print "percent\n";
  81. exit 0;
  82. }
  83. if ($config) {
  84. print <<EOF;
  85. graph_title Requested pages found in cache $title
  86. graph_category OpenLDAP
  87. graph_info Pages found in cache (indexes)
  88. EOF
  89. if ($measure eq "pages") {
  90. print <<EOF;
  91. graph_args --base 1000 -l 0
  92. graph_vlabel Cache hits per \${graph_period}
  93. EOF
  94. } else {
  95. print <<EOF;
  96. graph_args --base 1000 --upper-limit 100 -l 0 --vertical-label %
  97. graph_vlabel Cache hits (percentage)
  98. EOF
  99. }
  100. }
  101. my @output = `$dbstat -h $dbdir -m`;
  102. my $file = ""; # "Total";
  103. my $pages = undef;
  104. my $percent = undef;
  105. my $counter = 0;
  106. foreach my $line (@output) {
  107. chomp $line;
  108. if ($line =~ /^Pool File\: (.*)$/) {
  109. $file = $1;
  110. }
  111. if ($file &&
  112. $line =~ /^(\d+)\s+Requested pages found in the cache \((\d+)\%\)/) {
  113. $pages = $1;
  114. $percent = $2;
  115. }
  116. if ($file && defined ($pages) && defined ($percent)) {
  117. $file =~ s/\.bdb$//;
  118. my $val = "slapd_bdb_cache_${measure}_${file}";
  119. if ($config) {
  120. print "$val.label $file\n";
  121. if ($measure eq "pages") {
  122. print "$val.type DERIVE\n";
  123. print "$val.min 0\n";
  124. if ($counter == 0) {
  125. print "$val.draw AREA\n";
  126. } else {
  127. print "$val.draw STACK\n";
  128. }
  129. print "$val.info Number of $file pages found in cache\n";
  130. } else {
  131. print "$val.type GAUGE\n";
  132. print "$val.info Percentage of $file pages found in cache\n";
  133. print "$val.warning $warning:\n" if $ENV{'warning'};
  134. }
  135. } else {
  136. if ($measure eq "pages") {
  137. print "$val.value $pages\n";
  138. } else {
  139. print "$val.value $percent\n";
  140. }
  141. }
  142. $file = "";
  143. $pages = undef;
  144. $percent = undef;
  145. $counter++;
  146. }
  147. }