function main($server_cfg) { $options = get_options($server_cfg); foreach ($options['games'] as $game) { zpm_preamble($game); $game_cfg = load_game_config($game); if (!$game_cfg) { error_log("Daily job: Failed to load config for {$game}\n", 3, sprintf($server_cfg['log_file'], $game)); continue; } // log_file and logger object are used by all child functions. $game_cfg['log_file'] = sprintf($server_cfg['log_file'], $game); $game_cfg['logger'] = new Logger($server_cfg, $game_cfg); $job = $options['job']; //instance detail report per game if ($job == "both" or $job == "report") { InstanceReport::generate_detail_report($server_cfg, $game_cfg, $options['timeslot'], $options['period']); } zpm_postamble($game); } //instance summary report for all games $job = $options['job']; if ($job == "both" or $job == "report") { InstanceReport::generate_summary_report($server_cfg, $options['timeslot'], $options['period']); } }
function main($server_cfg) { $options = get_options(); if (isset($options['g']) && $options['g'] !== '') { $game_names = explode(",", $options['g']); } else { $game_names = $server_cfg['game_list']; } foreach ($game_names as $game) { zpm_preamble($game); $game_cfg = load_game_config($game); $retval = null; // refs will start failing in 5.3.x if not declared $cleanup = "/usr/local/zperfmon/bin/clean.sh -g " . $game_cfg['name'] . " > /dev/null "; $output = system($cleanup, $retval); if ($retval != 0) { error_log("Couldn`t cleanup game {$game}", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } $arrays_to_id = get_array_id_map($server_cfg, $game_cfg); foreach ($arrays_to_id as $array => $id) { $game_cfg = load_game_config($game, $id); $cleanup = "/usr/local/zperfmon/bin/clean.sh -g " . $game_cfg['name'] . " > /dev/null "; $output = system($cleanup, $retval); if ($retval != 0) { error_log("Couldn`t cleanup game {$game}", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } } zpm_postamble($game); } }
function main($server_cfg) { $options = get_options($server_cfg); foreach ($options['games'] as $game) { zpm_preamble($game); $game_cfg = load_game_config($game); if (!$game_cfg) { error_log("Daily job: Failed to load config for {$game}\n", 3, sprintf($server_cfg['log_file'], $game)); continue; } // log_file and logger object are used by all child functions. $game_cfg['log_file'] = sprintf($server_cfg['log_file'], $game); $game_cfg['logger'] = new Logger($server_cfg, $game_cfg); $job = $options['job']; if ($job == "both" or $job == "daily") { process_daily($server_cfg, $game_cfg, $options['timeslot'], $options['period']); } //performance report /* if ($job == "both" or $job == "report") { generate_report($server_cfg, $game_cfg, $options['timeslot'], $options['period']); }*/ zpm_postamble($game); } }
function main($server_cfg) { $options = get_options(); if (isset($options['g']) && $options['g'] !== '') { $game_names = explode(",", $options['g']); } else { $game_names = $server_cfg['game_list']; } foreach ($game_names as $game_name) { zpm_preamble($game_name); try { $game_cfg = load_game_config($game_name); //$game_cfg = $game_cfg[$game_name]; $now = time(); $query_period = $now - 5 * 60; // 5 minutes ago if (isset($game_cfg['splunk_url'])) { $splunk_url = $game_cfg['splunk_url']; $splunk_user = $game_cfg['splunk_user']; $splunk_pass = $game_cfg['splunk_password']; $splunk_queries = $game_cfg['splunk_queries']; $splunk_collector = new SplunkCollector($splunk_url, $splunk_user, $splunk_pass); $splunk_store = new SplunkAdapter($game_cfg); foreach ($splunk_queries as $query_name => $query) { $results = $splunk_collector->run_query($query, $query_period); if (is_array($results)) { $count = $results[0]["count"]; $splunk_store->store_splunk_count($now, $query_name, $count); } else { echo "Could not fetch {$query_name} for {$game_name}\n"; } } } } catch (Exception $e) { } zpm_postamble($game_name); } }
function main($server_cfg) { $options = get_options(); if (isset($options['g']) && $options['g'] !== '') { $game_names = explode(",", $options['g']); } else { $game_names = $server_cfg['game_list']; } $time_slots = null; if (!empty($options['t'])) { $time_slots = $options['t']; } $timestamp = $_SERVER['REQUEST_TIME']; $current_time_slot = (int) ($timestamp / (30 * 60)); foreach ($game_names as $game_name) { zpm_preamble($game_name); // MODIFIED!!!! Create and mount next two timeslots !!! $game_cfg = load_game_config($game_name); if (!$game_cfg) { error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } $target_dir = sprintf($server_cfg['root_upload_directory'], $game_cfg["name"]); $target_dir = $target_dir . "/%s/" . $server_cfg["profile_upload_directory"]; $dir_name_array = create_directory($target_dir, $current_time_slot, $server_cfg, $game_cfg); if ($dir_name_array === null) { error_log("Directory creation failed for the game " . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } if ($dir_name_array === 0) { error_log("No Ram disk Exist!!!" . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } //creating new games and getting the list of web arrays to process data for $rs = new RightScale($server_cfg, load_game_config($game_name)); $rs->make_array_games(); $array_ids = $rs->get_arrays_to_serve(); // // Wrap processing for each game inside a file lock // $game_lock_file = sprintf($server_cfg["zperfmon_lock_file"], $game_name); $game_lock_handle = grab_lock($game_lock_file, $server_cfg, $game_cfg); if (!$game_lock_handle) { error_log("Could not get exclusive lock for \"{$game_name}\"\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg); continue; } //processing parent game try { // // process uploaded data // run_cron_for_game($server_cfg, $game_cfg, $time_slots); } catch (Exception $e) { error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } // loop to process data for each web array foreach ($array_ids as $array) { try { $game_cfg = load_game_config($game_name, $array); if (!$game_cfg) { error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } // // process uploaded data // run_cron_for_game($server_cfg, $game_cfg, $time_slots); } catch (Exception $e) { error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } } // compress for parent game // This implementation forces us to always pass a timeslot // while calling this script. otherwise compression will fail. $game_cfg = load_game_config($game_name); compress_unziped_profiles($server_cfg, $game_cfg, $time_slots); // Now compress the array games foreach ($array_ids as $array) { $game_cfg = load_game_config($game_name, $array); compress_unziped_profiles($server_cfg, $game_cfg, $time_slots); } // cleanup the lock drop_lock($game_lock_handle, $game_lock_file); zpm_postamble($game_name); //MODIFIED!!!! if ($dir_name_array != 0) { delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg); } } }
function run_upload_processing($server_cfg) { date_default_timezone_set('UTC'); $current_timestamp = $_SERVER['REQUEST_TIME']; $options = getopt("g:t:a"); if (isset($options['g']) && $options['g'] !== '') { $game_names = explode(",", $options['g']); } else { $game_names = $server_cfg['game_list']; } $time_slots = null; if (empty($options['t'])) { $time_slots = (int) ($current_timestamp / 1800); $time_slots = "{" . $time_slots . "}"; } else { $time_slots = $options['t']; } foreach ($game_names as $game_name) { zpm_preamble($game_name); $game_cfg = load_game_config($game_name); // Process each array of the game $rsObj = new RightScale($server_cfg, $game_cfg); $rsObj->make_array_games(); process_uploads($server_cfg, $game_cfg, $time_slots, $rsObj); zpm_postamble($game_name); } }
} $conf_vars = explode(",", $var_string); if (count($conf_vars) == 0) { // ignore } else { if (count($conf_vars) == 1) { if (isset($server_cfg[$conf_vars[0]])) { $value = $server_cfg[$conf_vars[0]]; $value = getValue($value, false, $space_seperated); echo $value; } } else { $need_comma = False; echo "{"; foreach ($conf_vars as $var) { $value = $server_cfg[$var]; $value = getValue($value, true, $space_seperated); if ($need_comma) { echo ","; } else { $need_comma = True; } echo "\"{$var}\":{$value}"; } echo "}"; } } } main($server_cfg, $argv); zpm_postamble("");