Here's my script file, pretty simple
Code: Select all
<?php
#!/usr/bin/php -q
/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die("<br><strong>This script is only meant to run at the command line.</strong>");
}
$no_http_headers = true;
/* display No errors */
error_reporting(0);
include_once(dirname(__FILE__) . "/../include/global.php");
include_once(dirname(__FILE__) . "/../lib/snmp.php");
include_once(dirname(__FILE__) . "/../lib/ping.php");
if (!isset($called_by_script_server)) {
array_shift($_SERVER["argv"]);
print call_user_func_array("ss_getcpu", $_SERVER["argv"]);
}
function ss_getcpu($odbcname) {
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$connectionstring = odbc_connect($odbcname, $dbuser, $dbpass);
$query = "SELECT Value1, Value2, Value3 FROM GlobalDB.dbo.stats_counters WITH (NOLOCK) WHERE CounterName = 'CPU'";
$dataset = odbc_do($connectionstring, $query);
$cpusql = odbc_result($dataset, 1);
$cpuidle = odbc_result($dataset, 2);
$cpuother = odbc_result($dataset, 3);
odbc_close($connectionstring);
//Since this is running through a script server the results must be 'returned', printing them doesn't work.
$returnstring = "cpuidle:$cpuidle cpuother:$cpuother cpusql:$cpusql";
return trim($returnstring);
}
?>
Code: Select all
01/07/2014 12:53:05 PM - CMDPHP: Poller[0] Host[2] DS[249] SERVER: D:/Apache2/htdocs/cacti/scripts/ss_mssql_cpu.php ss_getcpu MIHQCOMPDBADM01, output: cpuidle:96 cpuother:4 cpusql:0
01/07/2014 12:53:05 PM - CMDPHP: Poller[0] DEVEL: SQL Exec: "insert into poller_output (local_data_id, rrd_name, time, output) values (249, '', '2014-01-07 12:53:02', 'cpuidle:96 cpuother:4 cpusql:0')"
01/07/2014 01:01:19 PM - WEBLOG: Poller[0] CACTI2RRD: d:/rrdtool/rrdtool.exe graph - --imgformat=PNG --start=1389103239 --end=1389117618 --title="SQL - MIHQCOMPDBADM01 - CPU" --base=1000 --height=120 --width=500 --upper-limit="100" --lower-limit="0" COMMENT:"From 2014/01/07 09\:00\:39 To 2014/01/07 13\:00\:18\c" COMMENT:" \n" --vertical-label="Percent" --slope-mode --font TITLE:10: --font AXIS:7: --font LEGEND:8: --font UNIT:7: DEF:a="D\:/Apache2/htdocs/cacti/rra/2/249.rrd":"cpusql":LAST DEF:b="D\:/Apache2/htdocs/cacti/rra/2/249.rrd":"cpuother":LAST DEF:c="D\:/Apache2/htdocs/cacti/rra/2/249.rrd":"cpuidle":LAST LINE2:a#FF0000FF:"CPU-SQL\: " GPRINT:a:LAST:" Current%8.2lf %s" GPRINT:a:AVERAGE:"Average\: %8.2lf %s\n" LINE2:b#00FF00FF:"CPU-OTHER\: " GPRINT:b:LAST:"Current\: %8.2lf %s" GPRINT:b:AVERAGE:"Average\: %8.2lf %s\n" LINE2:c#0000FFFF:"CPU-IDLE\: " GPRINT:c:LAST:" Current\: %8.2lf %s" GPRINT:c:AVERAGE:"Average\: %8.2lf %s"