[solved] PHP Script server only recording 2 of 3 values

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
Toddles18
Posts: 22
Joined: Fri Feb 20, 2009 1:28 pm

[solved] PHP Script server only recording 2 of 3 values

Post by Toddles18 »

I wrote a PHP Script server file, it is returning values just fine for 2 of the 3 values, however the 3rd never gets stored in the rrd file.

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);	
	}
?>
From the poller log

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"

When I export the data from my RRD file the cpuidle column has no values, even though it is collecting them.
Technical Support
General Information
Date Wed, 02 Mar 2016 13:35:32 -0500
Cacti Version 0.8.8f
Cacti OS win32
SNMP Version NET-SNMP version: 5.5
RRDTool Version RRDTool 1.4.x
Hosts 4
Graphs 34
Data Sources Script - Script Server (PHP): 16
Script Query - Script Server: 18
Total: 34
Poller Information
Interval 60
Type cmd.php
Items Action[2]: 72
Total: 72
Concurrent Processes 8
Max Threads 4
PHP Servers 4
Script Timeout 25
Max OID 10
Last Run Statistics Time:12.0814 Method:cmd.php Processes:8 Threads:N/A Hosts:5 HostsPerProcess:1 DataSources:72 RRDsProcessed:30
PHP Information
PHP Version 5.5.20
PHP OS WINNT
PHP uname Windows NT MIHQDBMONITOR01 6.3 build 9200 (Windows Server 2012 R2 Standard Edition) AMD64
PHP SNMP Installed
max_execution_time 60
memory_limit 512M
Toddles18
Posts: 22
Joined: Fri Feb 20, 2009 1:28 pm

Re: PHP Script server only recording 2 of 3 returned values

Post by Toddles18 »

Well apparently I jinxed it by posting here, in a good way. It's working now. I did go into my datatemplate and changed the dropdown for cpuidle datasource to be cpuother, saved, and then changed back to cpuidle. maybe that fixed it.
Technical Support
General Information
Date Wed, 02 Mar 2016 13:35:32 -0500
Cacti Version 0.8.8f
Cacti OS win32
SNMP Version NET-SNMP version: 5.5
RRDTool Version RRDTool 1.4.x
Hosts 4
Graphs 34
Data Sources Script - Script Server (PHP): 16
Script Query - Script Server: 18
Total: 34
Poller Information
Interval 60
Type cmd.php
Items Action[2]: 72
Total: 72
Concurrent Processes 8
Max Threads 4
PHP Servers 4
Script Timeout 25
Max OID 10
Last Run Statistics Time:12.0814 Method:cmd.php Processes:8 Threads:N/A Hosts:5 HostsPerProcess:1 DataSources:72 RRDsProcessed:30
PHP Information
PHP Version 5.5.20
PHP OS WINNT
PHP uname Windows NT MIHQDBMONITOR01 6.3 build 9200 (Windows Server 2012 R2 Standard Edition) AMD64
PHP SNMP Installed
max_execution_time 60
memory_limit 512M
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests