[HOWTO] Testing the PHP Script Server

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Moderators, Developers

Post Reply
Author
Message
User avatar
TheWitness
Developer
Posts: 14804
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

[HOWTO] Testing the PHP Script Server

#1 Post by TheWitness » Tue May 24, 2005 4:10 pm

All,

If you are having problems with the PHP Script Server, please follow the instructions below:

1) Start PHP Script Server

Use the following command to start the script server: "php <path_cacti>/script_server.php"

You wll receive a message from PHP indicating "PHP Script Server Started Properly". If you get any warning messages, then you have to fix them right away.

2) Obtain a Script Command from the Poller Cache

a) To do this Goto System Utilities->View Poller Cache
b) Search for "Action: 2"
c) Copy the portion of the script starting with the full path and working
to the end of line. For example:
c:\wwwroot\cacti086\scripts\ss_host_cpu.php ss_host_cpu localhost public 2 161 500 get usage 0
3) Execute the Script Server Command

Paste the command from 2c into your Script Server window and press enter.

You should receive an output statement. If not, please correct any warnings or script errors before proceeding.

4) To End the Script Server session

Type "quit" in the Script Server window and press enter.

Important Note:
For older versions of PHP < 4.3.3, you should be able to execute the command cut from setp 2c directly to a command line prefixed by "php" and run that script stand alone.

TheWitness :D
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

chris.y2k.r1
Posts: 31
Joined: Tue Mar 07, 2006 11:39 pm

#2 Post by chris.y2k.r1 » Thu Apr 06, 2006 10:13 am

THAT!!!! Is good to know.

What are the symptoms of a problematic script server..... For us php dummies out there..?

ymartin59
Posts: 40
Joined: Fri Feb 17, 2006 7:42 am

#3 Post by ymartin59 » Wed Nov 08, 2006 3:56 am

Hello,
I would like to know what are advantages of the method "script server" compared to "snmp query" ?
When I compare "net-snmp_disk.xml" description and "ss_host_disk.php" design, and according to the poller cache information, I think the "net-snmp_disk" should be faster to process than script server 'host_disk" because cmd.php or cactid can collect value from a single OID directly without invoking a script. Am I right ?

When designing a new data collector, is it better to use "snmp query" (when possible of course ) or "script server" ?

User avatar
TheWitness
Developer
Posts: 14804
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

#4 Post by TheWitness » Wed Nov 08, 2006 6:58 am

SNMP Queries will always be orders of magnitude faster especially using Cactid due to the fact that we are using RAW protocol with SNMP vs. a script that essentially does the same. The Script Server speeds up scripts when compared to a native shell or perl call however.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

dam11
Posts: 4
Joined: Wed May 30, 2007 2:39 am
Location: Biarritz, France

#5 Post by dam11 » Mon Jun 11, 2007 8:41 am

Hello,

I've got a problem with the migration from an existing PHP script to Script Server method, I just follow the doc steps ("Migration of Existing PHP Scripts to Script Server") and my graphs are stopped (nothing in the poller cache).
So, I have to manually create new graphs with the script server method, it goes very well (results tested with the CLI script_server.php are right compared to stand alone script).
The opposite transition works fine (from stand alone script to script server). :o
Did I miss another step during the migration ?

Thanks for your answers.

PS : I'm using cacti-0.8.6j under Linux.

User avatar
TheWitness
Developer
Posts: 14804
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

#6 Post by TheWitness » Mon Jun 11, 2007 9:13 am

I would have to see specificatlly what you did. It does work though. Prior to migration, you should always test your script as both script and non-script. The nice thing about the script itself, it should work both ways. Once you have that done, and graphing, you can change your data input method to be script server. Last step is to re-populate your poller cache.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

dam11
Posts: 4
Joined: Wed May 30, 2007 2:39 am
Location: Biarritz, France

#7 Post by dam11 » Mon Jun 11, 2007 10:21 am

Okay, I will try to explain :wink:
This is the verbose query for qos_plug.php :

Code: Select all

+ Running data query [10].
+ Found type = '4 '[script query].
+ Found data query XML file at '/var/www/public/cacti/resource/script_queries/class_qos.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 index'
+ Executing script query '/usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 query index'
....
Here a request from poller cache :

Code: Select all

Script: /usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class  *.*.*.* comm 2 get cbQosCMDropByte 2.class-default
RRD: /var/www/public/cacti/rra/routeur_cisco_1_cmpostpolicybyte_76.rrd
And this is the verbose query for ss_qos_plug.php :

Code: Select all

+ Running data query [10].
+ Found type = '6 '[script query].
+ Found data query XML file at '/var/www/public/cacti/resource/script_server/class_qos.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php -q /var/www/public/cacti/scripts/ss_qos_plug.php class *.*.*.* comm 2 index'
+ Executing script query '/usr/bin/php -q /var/www/public/cacti/scripts/ss_qos_plug.php class *.*.*.* comm 2 query index'
....
Poller :

Code: Select all

Script Server: /var/www/public/cacti/scripts/ss_qos_plug.php ss_qos_plug class *.*.*.* comm 2 get cbQosCMDropByte 2.class-default
RRD: /var/www/public/cacti/rra/routeur_cisco_1_cmpostpolicybyte_76.rrd
112 items, 16 rows in the two cases. There is no difference between the results.
When the ss_qos_plug.php is running and when I change to qos_plug.php, there is no problem, Cacti continue to graph, the poller cache is correctly rebuilt.

But in the other direction, when I rebuild poller cache, nothing happens (the poller requests disappear), so I have to delete Data Sources and create new graphs with old rrd files (to keep history).

User avatar
TheWitness
Developer
Posts: 14804
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

#8 Post by TheWitness » Mon Jun 11, 2007 11:20 pm

The "plller" quote you showed is actually the "poller cache". So from that, it would, in fact, appear to be being added. However, it is likely not running for some reason. Have you tested outside of the poller yet:

The scneario would be as follows:

Code: Select all

cd /var/www/html/cacti
php -q script_server.php
Response would be "Scrpt Server Started, Parent is cmd.php"

Then enter:

Code: Select all

/var/www/public/cacti/scripts/ss_qos_plug.php ss_qos_plug class *.*.*.* comm 2 get cbQosCMDropByte 2.class-default
Response should be, what you expect, on 1 line not empty lines. Then type

Code: Select all

quit
To exit.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

dam11
Posts: 4
Joined: Wed May 30, 2007 2:39 am
Location: Biarritz, France

#9 Post by dam11 » Tue Jun 12, 2007 3:36 am

I already followed this scenario and the result seems to be right, no empty line, no other character, just the requested value.

That's the cacti log for the two scripts :
CMDPHP: Poller[0] Host[2] DS[77] SERVER: /var/www/public/cacti/scripts/ss_qos_plug.php ss_qos_plug class *.*.*.* comm 2 get cbQosCMPrePolicyByte 2.class-default, output: 1492297591
CMDPHP: Poller[0] Host[6] DS[109] CMD: /usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 get cbQosCMPrePolicyByte 2.class-default, output: 1492323609

User avatar
TheWitness
Developer
Posts: 14804
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

#10 Post by TheWitness » Tue Jun 12, 2007 7:19 am

So, everything "should" be working. Do you see any issues when you run "php -q poller.php" from a command line? If you get that information in your log, then the only thing to break the graph would be an rrdupdate issue that you would be able to see by running "php -q poller.php".

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

dam11
Posts: 4
Joined: Wed May 30, 2007 2:39 am
Location: Biarritz, France

#11 Post by dam11 » Wed Jun 13, 2007 7:31 am

Thanks fo your answers, I will continue my investigation...

roxy
Posts: 17
Joined: Wed May 04, 2016 7:56 am

Re: [HOWTO] Testing the PHP Script Server

#12 Post by roxy » Mon Apr 03, 2017 5:13 am

Hi,

I have a system on Cacti 0.8.8a in VM environment. I have created a clone of the same and upgraded Cacti from 0.8.8a to 0.8.8d on it. After upgrade every thing is working fine except few script server queries. I am getting NAN value on all the graphs that are getting data from these script server queries. On my Cacti 0.8.8a server when I tested poller cache query manually I got correct result against a get query (see below).
[[email protected] cacti]$php script_server.php
PHP Script Server has Started - Parent is cmd
/tools/cacti-0.8.8a/scripts/ss_globalStats.php ss_globalStats TEST-01 2413 get ActiveEpsBearer global
608896
quit
PHP Script Server Shutdown request received, exiting
But when I tried same test on new Cacti version on clone system.
PHP Script Server has Started - Parent is cmd
/tools/cacti-0.8.8d/scripts/ss_globalStats.php ss_globalStats TEST-01 2413 get ActiveEpsBearer global

quit
PHP Script Server Shutdown request received, exiting
608966You have mail in /var/spool/mail/root
So here result of get is coming after "quit", don't know why. This has resulted NAN value on all the graphs.
Is there any problem with my below code?

Please help me to troubleshoot this issue.

Code: Select all

        } elseif ($cmd == "get") {
                $arg = $arg1;
                $index = $arg2;

                foreach ( $arrmeasInfo as $measInfo ) {

                        //print_r(${$measInfo.'_values'});

                        if ( isset(${$measInfo.'_types'}[$arg]) ) {
                                print ${$measInfo.'_values'}[${$measInfo.'_types'}[$arg]][$index];
                        }
                }
        } else {
        }
I am using below:

Cacti 0.8.8d
Spine 0.8.8a [0.8.8d did not worked after compilation so I have used old spine 0.8.8a as per suggestion from a Cacti forum]
Plugin Architecture Version: 3.1
Cacti Multipoller server 0.8.8d

roxy
Posts: 17
Joined: Wed May 04, 2016 7:56 am

Re: [HOWTO] Testing the PHP Script Server

#13 Post by roxy » Mon May 08, 2017 9:15 am

It has been resolved now after changing the print command with return. It was working on Cacti 0.8.8a but now need to use return for "get" function in the server script on Cacti 0.8.8d or Cacti 0.8.8e. Now this issue is resolved.

Post Reply