Project

General

Profile

« Previous | Next » 

Revision e9e295f7

Added by Jim Pingle over 14 years ago

Read data into variables before passing to rrdtool, so it's easier to extend this to store data elsewhere in addition to (or instead of) rrdtool. Also, switch to using cpustats for CPU statistics instead of top.

View differences:

etc/inc/rrd.inc
186 186
	$pfctl = "/sbin/pfctl";
187 187
	$sysctl = "/sbin/sysctl";
188 188
	$php = "/usr/local/bin/php";
189
	$top = "/usr/bin/top";
189
	$cpustats = "/usr/local/sbin/cpustats";
190 190
	$spamd_gather = "/usr/local/bin/spamd_gather_stats.php";
191 191
	$ifconfig = "/sbin/ifconfig";
192 192
	$captiveportal_gather = "/usr/local/bin/captiveportal_gather_stats.php";
......
356 356

  
357 357
				$rrdupdatesh .= "\n";
358 358
				$rrdupdatesh .= "# polling wireless for interface $ifname $realif \n";
359
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$wireless N:\\\n";
360
				$rrdupdatesh .= "`$ifconfig {$realif} list sta| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n";
359
				$rrdupdatesh .= "WIFI=`$ifconfig {$realif} list sta| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n";
360
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$wireless N:${WIFI}\n";
361 361
			}
362 362

  
363 363
			/* OpenVPN, set up the rrd file */
......
394 394
				$rrdupdatesh .= " sleep 0.2\n";
395 395
				$rrdupdatesh .= " echo \"quit\"\n";
396 396
				$rrdupdatesh .= "}\n";
397
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$vpnusers N:\\\n";
398
				$rrdupdatesh .= "`list_current_users | nc -U {$g['varetc_path']}/openvpn/server{$vpnid}.sock | awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | wc -l | awk '{print $1}'` &\n";
397
				$rrdupdatesh .= "OVPN=`list_current_users | nc -U {$g['varetc_path']}/openvpn/server{$vpnid}.sock | awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | wc -l | awk '{print $1}'` &\n";
398
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$vpnusers N:\${OVPN}\n";
399 399
			}
400 400

  
401 401
			/* QUEUES, set up the queues databases */
......
567 567
		}
568 568

  
569 569
		/* the CPU stats gathering function. */
570
		$rrdupdatesh .= "`$top -d 2 -s 1 0 | $awk '{gsub(/%/, \"\")} BEGIN { \\\n";
571
		$rrdupdatesh .= "printf \"$rrdtool update $rrddbpath$ifname$proc \" } \\\n";
572
		$rrdupdatesh .= "{ if ( \$2 == \"processes:\" ) { processes = \$1; } \\\n";
573
		$rrdupdatesh .= "else if ( \$1 == \"CPU:\" ) { user = \$2; nice = \$4; sys = \$6; interrupt = \$8; } \\\n";
574
		$rrdupdatesh .= "} END { printf \"N:\"user\":\"nice\":\"sys\":\"interrupt\":\"processes }'`\n\n";
570
		$rrdupdatesh .= "CPU=`$cpustats | cut -f1-4 -d':'`\n";
571
		/* Using ps uxaH will count all processes including system threads. Top was undercounting. */
572
		$rrdupdatesh .= "PROCS=`ps uxaH | wc -l | awk '{print \$1;}'`\n";
573
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$proc N:\${CPU}:\${PROCS}\n";
575 574

  
576 575
		/* End CPU statistics */
577 576

  
......
605 604
		}
606 605

  
607 606
		/* the Memory stats gathering function. */
608
		$rrdupdatesh .= "`$sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_free_count vm.stats.vm.v_cache_count vm.stats.vm.v_wire_count | ";
609
		$rrdupdatesh .= " $awk '{getline active;getline inactive;getline free;getline cache;getline wire;printf \"$rrdtool update $rrddbpath$ifname$mem N:\"";
610
		$rrdupdatesh .= "((active/$0) * 100)\":\"((inactive/$0) * 100)\":\"((free/$0) * 100)\":\"((cache/$0) * 100)\":\"(wire/$0 * 100)}'`\n\n";
607
		$rrdupdatesh .= "MEM=`$sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_free_count vm.stats.vm.v_cache_count vm.stats.vm.v_wire_count | ";
608
		$rrdupdatesh .= " $awk '{getline active;getline inactive;getline free;getline cache;getline wire;printf ";
609
		$rrdupdatesh .= "((active/$0) * 100)\":\"((inactive/$0) * 100)\":\"((free/$0) * 100)\":\"((cache/$0) * 100)\":\"(wire/$0 * 100)}'`\n";
610
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$mem N:\${MEM}\n";
611 611
		
612 612
		/* End Memory statistics */
613 613

  
......
705 705
			/* the Captive Portal stats gathering function. */
706 706
			$rrdupdatesh .= "\n";
707 707
			$rrdupdatesh .= "# polling Captive Portal for number of concurrent users\n";
708
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalconcurrent \\\n";
709
			$rrdupdatesh .= "`$php -q $captiveportal_gather concurrent`\n";
708
			$rrdupdatesh .= "CP=`$php -q $captiveportal_gather concurrent`\n";
709
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalconcurrent \${CP}\n";
710 710
			
711 711
			$ifname= "captiveportal";
712 712
			if (!file_exists("$rrddbpath$ifname$captiveportalloggedin")) {
......
740 740
			/* the Captive Portal stats gathering function. */
741 741
			$rrdupdatesh .= "\n";
742 742
			$rrdupdatesh .= "# polling Captive Portal for number of logged in users\n";
743
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalloggedin \\\n";
744
			$rrdupdatesh .= "`$php -q $captiveportal_gather loggedin`\n";
743
			$rrdupdatesh .= "CP=`$php -q $captiveportal_gather loggedin`\n";
744
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalloggedin \${CP}\n";
745 745
			
746 746
			$ifname= "captiveportal";
747 747
			if (!file_exists("$rrddbpath$ifname$captiveportaltotalusers")) {
......
775 775
			/* the Captive Portal stats gathering function. */
776 776
			$rrdupdatesh .= "\n";
777 777
			$rrdupdatesh .= "# polling Captive Portal for number of concurrent users\n";
778
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportaltotalusers \\\n";
779
			$rrdupdatesh .= "`$php -q $captiveportal_gather total`\n";
778
			$rrdupdatesh .= "CP=`$php -q $captiveportal_gather total`\n";
779
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportaltotalusers \${CP}\n";
780 780
			
781 781
		}
782 782

  

Also available in: Unified diff