using ss_get_mysql_stats.php with script server doesn't work

Bug #1350602 reported by Steven Barre
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Monitoring Plugins
New
Undecided
Unassigned

Bug Description

The cacti script server calls

call_user_func_array($function, $parameter_array);

thus passing in each argument to the function.

but function ss_get_mysql_stats( $options ) only expects one array of options, not separate options.

Revision history for this message
Steven Barre (slashterix) wrote :

Doing this to the function seems to fix it, but I'm sure this is an ugly hack.

function ss_get_mysql_stats( $options ) {
   # Process connection options.
   global $debug, $mysql_user, $mysql_pass, $cache_dir, $poll_time, $chk_options,
          $mysql_port, $mysql_ssl, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca,
          $heartbeat, $heartbeat_table, $heartbeat_server_id, $heartbeat_utc;

   # If called from the script server, reparse the args
   if (!is_array($options)) {
      $options = parse_cmdline(func_get_args());
   }

   # Chech for the cnf files
   if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) {
      require('/etc/cacti/' . basename(__FILE__) . '.cnf');
      debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf');
   }
   elseif ( file_exists(__FILE__ . '.cnf' ) ) {
      require(__FILE__ . '.cnf');
      debug('Found configuration file ' . __FILE__ . '.cnf');
   }

   $user = isset($options['user']) ? $options['user'] : $mysql_user;
   $pass = isset($options['pass']) ? $options['pass'] : $mysql_pass;
   $host = $options['host'];
   $port = isset($options['port']) ? $options['port'] : $mysql_port;
   $heartbeat_server_id = isset($options['server-id']) ? $options['server-id'] : $heartbeat_server_id;

Revision history for this message
Steven Barre (slashterix) wrote :

Also, this is catching execution from the script server, which is why I had to re-do the including of the cnf file.

# ============================================================================
# To make this code testable, we need to prevent code from running when it is
# included from the test script. The test script and this file have different
# filenames, so we can compare them. In some cases $_SERVER['SCRIPT_FILENAME']
# seems not to be defined, so we skip the check -- this check should certainly
# pass in the test environment.
# ============================================================================
if ( !array_key_exists('SCRIPT_FILENAME', $_SERVER)
   || basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME']) ) {

Revision history for this message
Steven Barre (slashterix) wrote :

I also think this code needs to be part of the function, and not external.

# Split the result up and extract only the desired parts of it.
   $wanted = explode(',', $options['items']);

since the script server will complain if the returned text is too long

Revision history for this message
Steven Barre (slashterix) wrote :

So I managed to fix this, but my fix is pretty ugly. I've attached my fixed version as well as the CPU graph for my caci box after switching all my MySQL Data Inputs to script server and setting the number of script servers to 8.

Before:
09/12/2014 08:58:08 PM - SYSTEM STATS: Time:186.9363 Method:spine Processes:1 Threads:8 Hosts:148 HostsPerProcess:148 DataSources:11111 RRDsProcessed:10376

After:
09/12/2014 09:40:16 PM - SYSTEM STATS: Time:14.4797 Method:spine Processes:1 Threads:8 Hosts:148 HostsPerProcess:148 DataSources:11111 RRDsProcessed:10376

Revision history for this message
Steven Barre (slashterix) wrote :
Revision history for this message
Michael S. Moody (michael-sykosoft) wrote :

I'm not able to replicate your success on this. While I haven't yet applied your fix, setting script server to true in the file doesn't seem to break anything. Whereas, even with script servers set to 8, and such, my CPU usage is still incredibly high. Thoughts?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.