private static function countStats($streamers, $sort_by_load = false) { $streamers = array_map(function ($streamer) { $streamer['sessions'] = StreamServer::getStreamerSessions($streamer['id']); $streamer['load'] = StreamServer::getLoad($streamer['id'], $streamer['sessions']); return $streamer; }, $streamers); if ($sort_by_load) { $streamers = self::sortByLoad($streamers); } return $streamers; }
public function getLinksForMonitoring($status = FALSE) { $result = Mysql::getInstance()->select('ch_links.*, itv.name as ch_name')->from('ch_links')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 0)); if ($status) { $result->where(array('ch_links.status' => (int) ($status == 'up'))); } $monitoring_links = $result->orderby('ch_id')->get()->all(); $result = Mysql::getInstance()->select('ch_links.*, streamer_id, ch_link_on_streamer.id as streamer_link_id, itv.name as ch_name')->from('ch_links')->join('ch_link_on_streamer', 'link_id', 'ch_links.id', 'INNER')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 1, 'ch_links.use_load_balancing' => 1)); if ($status) { $result->where(array('ch_links.status' => (int) ($status == 'up'))); } $balanser_monitoring_links_raw = $result->orderby('ch_id')->get()->all(); $servers_map = StreamServer::getIdMap(); $balanser_monitoring_links = array(); foreach ($balanser_monitoring_links_raw as $link) { if (empty($servers_map[$link['streamer_id']])) { continue; } if ($link['use_http_tmp_link'] == 1 && $link['wowza_tmp_link'] == 0) { $colon_pos = strpos($servers_map[$link['streamer_id']]['address'], ":"); if ($colon_pos === false) { $address = $servers_map[$link['streamer_id']]['address']; } else { $address = substr($servers_map[$link['streamer_id']]['address'], 0, $colon_pos); } $link['url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['url']); $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['monitoring_url']); } else { $link['url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['url']); $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['monitoring_url']); } $link['id'] = 's' . $link['streamer_link_id']; $balanser_monitoring_links[] = $link; } $monitoring_links = array_merge($monitoring_links, $balanser_monitoring_links); $monitoring_links = array_map(function ($cmd) { $cmd['monitoring_url'] = trim($cmd['monitoring_url']); if (!empty($cmd['monitoring_url']) && preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['monitoring_url'], $match)) { $cmd['url'] = $match[1]; } else { if (preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['url'], $match)) { $cmd['url'] = $match[1]; } } if ($cmd['flussonic_tmp_link']) { $cmd['type'] = 'flussonic_health'; } elseif ($cmd['nginx_secure_link']) { try { $cmd['type'] = 'nginx_secure_link'; $cmd['url'] = Itv::getNginxSecureLink($cmd['url']); } catch (ItvLinkException $e) { return false; } } else { $cmd['type'] = 'stream'; } return $cmd; }, $monitoring_links); return array_values(array_filter($monitoring_links)); }
if ($censored) { $checked = 'checked'; } if ($base_ch) { $checked_base = 'checked'; } if ($bonus_ch) { $checked_bonus = 'checked'; } if ($hd) { $checked_hd = 'checked'; } $stream_servers = StreamServer::getAll(); $links = Mysql::getInstance()->from('ch_links')->where(array('ch_id' => (int) $arr['id']))->orderby('priority')->get()->all(); $links = array_map(function ($link) use($stream_servers) { $streamers_map = StreamServer::getStreamersIdMapForLink($link['id']); $link['stream_servers'] = array_map(function ($server) use($streamers_map) { if (!empty($streamers_map[$server['id']])) { $server['selected'] = 1; $server['monitoring_status'] = $streamers_map[$server['id']]['monitoring_status']; } else { $server['selected'] = 0; $server['monitoring_status'] = 0; } return $server; }, $stream_servers); return $link; }, $links); } } else { if (!empty($_POST)) {
Mysql::getInstance()->use_caching(array('streaming_servers.id=' . intval($_GET['id'])))->delete('streaming_servers', array('id' => intval($_GET['id']))); header("Location: stream_servers.php"); exit; } elseif (isset($_GET['status'])) { Admin::checkAccess(AdminAccess::ACCESS_CONTEXT_ACTION); Mysql::getInstance()->use_caching(array('streaming_servers.id=' . intval($_GET['id'])))->update('streaming_servers', array('status' => $_GET['status']), array('id' => intval($_GET['id']))); header("Location: stream_servers.php"); exit; } } if (@$_GET['edit'] && !empty($id)) { $action_name = 'edit'; $action_value = _('Save'); $edit_streamer = StreamServer::getById($id); } $streamers = StreamServer::getAll(); $zones = Mysql::getInstance()->from('stream_zones')->orderby('name')->get()->all(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> body { font-family: Arial, Helvetica, sans-serif; font-weight: bold; } td { font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-decoration: none;
<td class="td_stat"><?php echo $cur_records; ?> </td> </tr> </table> </td> <td class="other" width="160" valign="top" style="background-color: whiteSmoke"> <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td class="td_stat" height="" colspan="2"></td> </tr> <tr> <?php $stream_servers = StreamServer::getAllActive(true); $streamer_sessions = array_reduce($stream_servers, function ($sessions, $streamer) { return $sessions + $streamer['sessions']; }, 0); ?> <td class="td_stat"><?php echo mb_strtolower(_('Stream servers'), 'UTF-8'); ?> :</td> <td class="td_stat"><?php echo $streamer_sessions; ?> </td> </tr> <tr>