PERL   77

FreeBSD Stats Grabber

Guest on 7th June 2022 01:33:27 AM

  1. #!/usr/bin/perl
  2.  
  3. ##FreeBSD Stats Grabber
  4.  
  5.  
  6.  
  7. ##### Set MySql Login/Password #####
  8.  
  9. $msqluser = "root";
  10. $msqlpass = "root";
  11.  
  12. ##### Set Paths ######
  13.  
  14. $shell = '/usr/local/bin/bash';                 ### Path to bash or csh
  15. $grep = '/usr/bin/grep';                        ### Path to grep
  16. $uptime = '/usr/bin/uptime';                    ### Path to uptime
  17. $mysqladmin = '/usr/local/bin/mysqladmin';      ### Path to mysqladmin
  18. $top = '/usr/bin/top';                          ### Path to top
  19. $wc = '/usr/bin/wc';                            ### Path to wc
  20. $w = '/usr/bin/w';                              ### Path to w
  21. $users = '/usr/bin/users';                      ### Path to users
  22. $netstat = '/usr/bin/netstat';                  ### Path to netstat
  23. $df = '/bin/df';                                ### Path to df
  24. $lynx = '/usr/local/bin/lynx';                  ### Path to lynx
  25. $ping = '/sbin/ping';                           ### Path to ping
  26. $cat = '/bin/cat';                              ### Path to cat
  27. $compat_meminfo = '/compat/linux/proc/meminfo'; ### Path to meminfo (if freebsd, you need linux compatablity)
  28. $compat_uptime = '/compat/linux/proc/uptime';   ### Path to uptime (this is to the linux uptime file, not the /usr/bin/uptime,
  29. i did this to save prossesing time)
  30.  
  31.  
  32. #########################################################
  33. #            DONT TOUCH BELOW THIS LINE                 #
  34. #   You will have to change the URLS in some locations  #
  35. #########################################################
  36.  
  37. $shell .= ' -c';
  38. $cmd_argv0 = $ARGV[0];
  39. $cmd_argv1 = $ARGV[1];
  40. $data_input = "";
  41. $data = "";
  42. $data1 = "";
  43. @data3 = "";
  44. $help = "";
  45.  
  46. if ($cmd_argv0 eq "load") {
  47.         $data_input = `$shell '$uptime'`;
  48.         $data_input =~ s/.*://;
  49.         $data_input =~ s/,//gi;
  50.         $data_input =~ s/^ //;
  51.         chomp $data_input;
  52.         print $data_input;
  53. }
  54. elsif ($cmd_argv0 eq "temp") {
  55.         #5/9*(F-32)=C
  56.         $data_input = `$shell 'lynx -dump 'http://www.weather.com/weather/local/NOXX0032?letter=S' | grep "Feels Like"'`;
  57.         $data_input =~ s/[a-zA-Z\:\ ]//g;
  58.         $data_input =~ s/\�/ /g/g;
  59.         chomp ($data_input); chop ($data_input);
  60.         @data3 = split(/, , $data_input);
  61.         $data1 = (5/9)*($data3[0]-32);
  62.         $data2 = (5/9)*($data3[1]-32);
  63.         print "$data1 $data2";
  64. }
  65. elsif ($cmd_argv0 eq "cpustats") {# user nice system interrupt idel
  66. l
  67.         $data_input = `$shell '$top -d2 -s1 | $grep "states:"'`;
  68.         $data_input =~ [a-zA-Z\,\:\ ]//g;
  69. ;
  70.         $data_input =~ \%/ /g;
  71. ;
  72.         chomp($data_input);
  73.         chop($data_input);
  74.         print $data_input;
  75. }
  76. elsif ($cmd_argv0 eq "users") {
  77.         $data_input = `$shell '$w | $wc -l'`;
  78.         $data_input =~ [\d]+)/;
  79. ;
  80.         $data1 = -2-2;
  81.         $data_input = `$shell '$users | $wc -w'`;
  82.         $data_input =~ [\d]+)/;
  83. ;
  84.         $data = ;
  85. ;
  86.         print "$data $data1";
  87. }
  88. elsif ($cmd_argv0 eq "mysql_query") {
  89.         $data_input = `$shell '$mysqladmin -u$msqluser -p$msqlpass status'`;
  90.         $data_input=~ ueries per second avg: (\d.\d+)/;
  91. ;
  92.         print ;
  93. ;
  94. }
  95. elsif ($cmd_argv0 eq "mysql_threads") {
  96.         $data_input = `$shell '$mysqladmin -u$msqluser -p$msqlpass status'`;
  97.         $data_input=~ hreads: (\d+)/;
  98. ;
  99.         print ;
  100. ;
  101. }
  102. elsif ($cmd_argv0 eq "mysql_slow") {
  103.         $data_input = `$shell '$mysqladmin -u$msqluser -p$msqlpass status'`;
  104.         $data_input=~ low queries: (\d+)/;
  105. ;
  106.         print ;
  107. ;
  108. }
  109. elsif ($cmd_argv0 eq "mysql_opens") {
  110.         $data_input = `$shell '$mysqladmin -u$msqluser -p$msqlpass status'`;
  111.         $data_input=~ pens: (\d+)/;
  112. ;
  113.         print ;
  114. ;
  115. }
  116. elsif ($cmd_argv0 eq "mysql_questions") {
  117.         $data_input = `$shell '$mysqladmin -u$msqluser -p$msqlpass status'`;
  118.         $data_input=~ uestions: (\d+)/;
  119. ;
  120.         print ;
  121. ;
  122. }
  123. elsif ($cmd_argv0 eq "procs") {
  124.         $data_input = `$shell '$top -s1 -d1 | $grep processes'`;
  125.         $data_input =~ unning\, *(\d+)/;
  126. ;
  127.         $data = ;
  128. ;
  129.         $data_input =~ rocesses\: *(\d+)/;
  130. ;
  131.         $data1 = ;
  132. ;
  133.         print "$data1 $data";
  134. }
  135. elsif ($cmd_argv0 eq "uptime") {
  136.         $data_input = `$shell '$cat $compat_uptime'`;
  137.         $data_input =~ \d+).*/;
  138. ;
  139.         $data = ;
  140. ;
  141.         $data = ($data/60);
  142.         $data = ($data/60);
  143.         print "$data";
  144. }
  145. elsif ($cmd_argv0 eq "harddrive") {
  146.         $data_input = `$shell '$df -k | $grep $cmd_argv1'`;
  147.         $data_input =~ [\/0-9a-zA-Z]+ *(\d+) *(\d+)/;
  148. ;
  149.         $data = ;
  150. ;
  151.         $data1 = ;
  152. ;
  153.         $data *= 1000;
  154.         $data1 *= 1000;
  155.         print "$data $data1";
  156. }
  157. elsif ($cmd_argv0 eq "mem") {
  158.         $data_input = `$shell '$cat $compat_meminfo | $grep Mem'`;
  159.         $data_input =~ Mem: *(\d+) *(\d+)/;
  160. ;
  161.         print " $ ";";
  162. }
  163. elsif ($cmd_argv0 eq "cache") {
  164.         $data_input = `$shell '$cat $compat_meminfo | $grep Mem'`;
  165.         $data_input =~ em: *(\d+) *(\d+) *(\d+) *(\d+) *(\d+) *(\d+)/;
  166. ;
  167.         print ; ;    
  168. }
  169. elsif ($cmd_argv0 eq "swap") {
  170.         $data_input = `$shell '$cat $compat_meminfo | $grep Swap'`;
  171.         $data_input =~ wap: *(\d+) *(\d+) *(\d+)/;
  172. ;
  173.         print " $ ";";
  174. }
  175. elsif ($cmd_argv0 eq "apache_bytes") {
  176.         $data_input = `$shell '$lynx -dump http://www.CHANGEME.com/server-status?auto | $grep kBytes'`;
  177.         $data_input =~ *Total kBytes.*: (\d+).*/;
  178. ;
  179.         $data = ;
  180. ;
  181.         $data *= 1024;
  182.         print $data;
  183. }
  184. elsif ($cmd_argv0 eq "apache_access") {
  185.         $data_input = `$shell '$lynx -dump http://www.CHANGEME.com/server-status?auto | $grep Accesses'`;
  186.         $data_input =~ *Total Accesses.*: (\d+).*/;
  187. ;
  188.         print ;
  189. ;
  190. }
  191. elsif ($cmd_argv0 eq "apache_uptime") {
  192.         $data_input = `$shell '$lynx -dump http://www.CHANGEME.com/server-status?auto | $grep Uptime'`;
  193.         $data_input =~ *Uptime.*: (\d+).*/;
  194. ;
  195.         $data = ;
  196. ;
  197.         $data = ($data/60);
  198.         $data = ($data/60);
  199.         print $data;
  200. }
  201. elsif ($cmd_argv0 eq "apache_servers") {
  202.         $data_input = `$shell '$lynx -dump http://www.CHANGEME.com/server-status?auto | $grep BusyServers'`;
  203.         $data_input =~ usyServers.*: (\d+)/;
  204. ;
  205.         $data = ;
  206. ;
  207.         $data_input = `$shell '$lynx -dump http://www.CHANGEME.com/server-status?auto | $grep IdleServers'`;
  208.         $data_input =~ dleServers.*: (\d+)/;
  209. ;
  210.         print "$data ";";
  211. }
  212. elsif ($cmd_argv0 eq "tcpopen") {
  213.         $data_input = `$shell '$netstat -tn | $grep ESTABLISHED | $wc -l'`;
  214.         $data_input =~ \d+)/;
  215. ;
  216.         print ;
  217. ;
  218. }
  219. elsif ($cmd_argv0 eq "ftpopen") {
  220.         $data_input = `$shell '$netstat -tn | $grep ".21 .*ESTABLISHED" | $wc -l'`;
  221.         $data_input =~ \d+)/;
  222. ;
  223.         print ;
  224. ;
  225. }
  226. elsif ($cmd_argv0 eq "httpopen") {
  227.         $data_input = `$shell '$netstat -tn | $grep ".80 .*ESTABLISHED" | $wc -l'`;
  228.         $data_input =~ \d+)/;
  229. ;
  230.         print ;
  231. ;
  232. }
  233. elsif ($cmd_argv0 eq "netbiosopen") {
  234.         $data_input = `$shell '$netstat -tn | $grep ".139 .*ESTABLISHED" | $wc -l'`;
  235.         $data_input =~ \d+)/;
  236. ;
  237.         print ;
  238. ;
  239. }
  240. elsif ($cmd_argv0 eq "customopen") {
  241.         $data_input = `$shell '$netstat -tn | $grep "\.$cmd_argv1 .*ESTABLISHED" | $wc -l'`;
  242.         $data_input =~ \d+)/;
  243. ;
  244.         print ;
  245. ;
  246. }
  247. elsif ($cmd_argv0 eq "ping") {
  248.         $data_input = `$shell '$ping -c 3 $cmd_argv1 | $grep round-trip'`;
  249.         $data_input =~ round-trip.+\/([\d.]+)\/([\d.]+)\//;
  250. ;
  251.         print " $ ";";
  252. }
  253. else {
  254.         $help  = "FreeBSD Stats Grabber (written by Ross) for Cacti 0.6.6+ (written by Ian Berry).\n\n";
  255.         $help .= "Usage: stat.pl <option> [argv]\n";
  256.         $help .= "Apache Options:\n";
  257.         $help .= "\tapache_bytes\tapache_access\tapache_uptime\n\tapache_servers\n\n";
  258.         $help .= "System Options:\n";
  259.         $help .= "\tcache\tcpustats\tload\tusers\n\tprocs\tuptime\tswap\tmem\n\tharddrive [hdd name ie. (da1s1e)]\n\n";
  260.         $help .= "Network Options:\n";
  261.         $help .= "\ttcpopen\t\tftpopen\thttpopen\n\tnetbiosopen\tping\tcustomopen [port number]\n\n";
  262.         $help .= "Mysql Options:\n";
  263.         $help .= "\tmysql_query\tmysql_threads\tmysql_slow\n\tmysql_opens\tmysql_questions\n";
  264.         print "$help";

Raw Paste


Login or Register to edit or fork this paste. It's free.