#!/usr/bin/env php $partitions_to_keep) { $partitions_to_delete = cacti_sizeof($tables) - $partitions_to_keep; $partitions = []; foreach ($tables as $table) { $tname = $table['TABLE_NAME']; $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(string $table_name, string $suffix) : void { 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() : void { $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() : void { display_version(); print PHP_EOL . 'usage: poller_dsstats.php [--force] [--debug]' . PHP_EOL . PHP_EOL; print 'Cacti\'s Data Source Statistics 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 int $signo - the signal that was thrown by the interface. * * @return void */ function sig_handler($signo) : void { 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 (str_contains($type, 'master')) { dsstats_kill_running_processes(); } unregister_process('dsstats', $type, $thread_id, (int) getmypid()); exit(1); default: // ignore all other signals } }