#!/usr/bin/env php $partitions_to_keep) { $partitions_to_delete = cacti_sizeof($tables) - $partitions_to_keep; $partitions = array(); foreach($tables as $table) { $tname = $table[0]; $parts = explode('_v', $tname); $partitions[] = $parts[1]; } sort($partitions); $i = 0; while($i < $partitions_to_delete) { $remove_table = $table_name . '_v' . $partitions[$i]; if (db_table_exists($remove_table)) { cacti_log("NOTE: Dropping old partition $table_name", false, 'DSSTATS'); db_execute("DROP TABLE $remove_table"); } $i++; } } } function dsstats_create_partition_from_table($table_name, $suffix) { if (db_table_exists($table_name)) { cacti_log("NOTE: Creating new partition $table_name", false, 'DSSTATS'); if (db_table_exists('dsstats_temp_table')) { db_execute('DROP TABLE dsstats_temp_table'); } db_execute("CREATE TABLE dsstats_temp_table LIKE $table_name; RENAME TABLE $table_name TO $table_name$suffix, dsstats_temp_table TO $table_name"); } } /** * display_version - displays version information */ function display_version() { $version = get_cacti_cli_version(); print "Cacti Data Source Statistics Poller, Version $version " . COPYRIGHT_YEARS . PHP_EOL; } /** * display_help - generic help screen for utilities */ function display_help() { display_version(); print PHP_EOL . 'usage: poller_dsstats.php [--force] [--debug]' . PHP_EOL . PHP_EOL; print 'Cacti\'s Data Source Statics poller. This poller will periodically' . PHP_EOL; print 'to calculate Data Source statistics for Cacti and works in conjunction' . PHP_EOL; print 'with Cacti\'s performance boosting poller as required.' . PHP_EOL . PHP_EOL; print 'System Controlled:' . PHP_EOL; print ' --type - The type and subtype of the dsstats process' . PHP_EOL; print ' --child - The thread id of the child process' . PHP_EOL . PHP_EOL; print 'Optional:' . PHP_EOL; print ' --force - Force the execution of a update process' . PHP_EOL; print ' --debug - Display verbose output during execution' . PHP_EOL . PHP_EOL; } /** * sig_handler - provides a generic means to catch exceptions to the Cacti log. * * @param $signo - (int) the signal that was thrown by the interface. * * @return - null */ function sig_handler($signo) { global $type, $thread_id; switch ($signo) { case SIGTERM: case SIGINT: cacti_log('WARNING: DSStats Poller terminated by user', false, 'dsstats'); /* tell the main poller that we are done */ if ($type == 'master') { set_config_option('dsstats_poller_status', 'terminated - end time:' . date('Y-m-d G:i:s')); } if (strpos($type, 'master') !== false) { dsstats_kill_running_processes(); } unregister_process('dsstats', $type, $thread_id, getmypid()); exit(1); break; default: /* ignore all other signals */ } }