Permalink
Browse files

Tabbed interface; Workers status

  • Loading branch information...
1 parent 787810e commit f2075d1e14891201e3aa6b85f27932a1a44012e5 @yugene committed Jul 5, 2011
View
@@ -12,16 +12,20 @@
* $cfgServers[$i]['name'] = 'Gearman server 1';
* ++ $i;
*
- * $cfgServers[$i]['address'] = '192.168.1.1:80';
+ * $cfgServers[$i]['address'] = '192.168.1.1:7003';
* $cfgServers[$i]['name'] = 'Gearman server 2';
* ++ $i;
*/
$i = 0;
$cfgServers = array();
-$cfgServers[$i]['address'] = '';
-$cfgServers[$i]['name'] = '';
+$cfgServers[$i]['address'] = '192.168.31.195:4730';
+$cfgServers[$i]['name'] = 'localhost';
+++ $i;
+
+$cfgServers[$i]['address'] = '192.168.31.195:4730';
+$cfgServers[$i]['name'] = 'asrv110528';
++ $i;
?>
View
@@ -45,6 +45,9 @@ class GA_ServerList
const SORT_JOBS_IN_QUEUE = 'in_queue';
const SORT_JOBS_RUNNING = 'jobs_running';
const SORT_WORKERS = 'capable_workers';
+ const SORT_IP = 'ip';
+ const SORT_FD = 'fd';
+ const SORT_ID = 'id';
const SORT_ASC = 'asc';
const SORT_DESC = 'desc';
@@ -74,7 +77,7 @@ public function setOptions(array $options)
{
$this->_filterName = (string) $options['filterName'];
}
- if (isset($options['sort']) && in_array($options['sort'], $this->_getSortAvailable()))
+ if (isset($options['sort']))
{
$this->_sort = (string) $options['sort'];
}
@@ -249,7 +252,54 @@ public function getFunctionData()
}
}
- $data = $this->_sortFunctionData($data);
+ $data = $this->_sortData($data, $this->_getSortAvailableFunctions());
+
+ return $data;
+ }
+
+ /**
+ * Returns information about workers connected to Gearman server
+ *
+ * @return array
+ */
+ public function getWorkersData()
+ {
+ $data = array();
+
+ foreach ($this->_servers as $serverIndex => $server)
+ {
+ if (! empty($this->_filterServers) && ! in_array($serverIndex, $this->_filterServers))
+ {
+ continue;
+ }
+
+ try
+ {
+ $gearmanManager = new Net_Gearman_Manager($server['address']);
+
+ $workers = $gearmanManager->workers();
+
+ $gearmanManager->disconnect();
+ unset($gearmanManager);
+
+ foreach ($workers as $worker)
+ {
+ if (strlen($this->_filterName) == 0 ||
+ stripos($worker['ip'], $this->_filterName) !== false ||
+ stripos(join('$#!', $worker['abilities']), $this->_filterName) !== false)
+ {
+ $worker['server'] = $server['name'];
+ $data[] = $worker;
+ }
+ }
+ }
+ catch (Exception $e)
+ {
+ $this->_addError($e->getMessage());
+ }
+ }
+
+ $data = $this->_sortData($data, $this->_getSortAvailableWorkers());
return $data;
}
@@ -259,7 +309,7 @@ public function getFunctionData()
*
* @return array
*/
- protected function _getSortAvailable()
+ protected function _getSortAvailableFunctions()
{
$sortAvailable = array(
self::SORT_SERVER,
@@ -273,14 +323,31 @@ protected function _getSortAvailable()
}
/**
+ * Returns available sort column
+ *
+ * @return array
+ */
+ protected function _getSortAvailableWorkers()
+ {
+ $sortAvailable = array(
+ self::SORT_SERVER,
+ self::SORT_IP,
+ self::SORT_FD,
+ self::SORT_ID
+ );
+
+ return $sortAvailable;
+ }
+
+ /**
* Sort Gearman functions data
*
* @param array $data
* @return array
*/
- protected function _sortFunctionData(array $data)
+ protected function _sortData(array $data, $colsAvailable)
{
- if (in_array($this->_sort, $this->_getSortAvailable()))
+ if (in_array($this->_sort, $colsAvailable))
{
$sortCol = array();
View
@@ -2,6 +2,10 @@ body {margin:0;}
body.left {background:#d0dce0; padding:20px;}
body.content {background:whiteSmoke; padding:10px;}
+ul.topmenu {list-style-type:none; margin:0; padding:0;}
+ul.topmenu li {border-bottom:1px solid black; float:left;}
+.tab {background-color:#e5e5e5; border:1px solid #d5d5d5; border-bottom:0; border-top-left-radius:7px; border-top-right-radius:7px; display:block; margin:1px; padding:2px 10px; white-space:nowrap;}
+
a:link, a:visited, a:active {color:blue; text-decoration:none;}
.logo {font-size:14; padding-bottom:15px; text-align:center; text-transform:uppercase;}
View
@@ -2,6 +2,16 @@
require_once('_init.php');
+if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('queue', 'workers', 'servers')))
+{
+ $action = $_REQUEST['action'];
+}
+else
+{
+ $action = 'queue';
+}
+
+$view->action = $action;
$view->display('filter.tpl.php');
?>
View
@@ -2,6 +2,16 @@
require_once('_init.php');
+if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('queue', 'workers', 'servers')))
+{
+ $action = $_REQUEST['action'];
+}
+else
+{
+ $action = 'queue';
+}
+
+$view->action = $action;
$view->gearmanClassExists = class_exists('Net_Gearman_Manager', true);
$view->display('index.tpl.php');
View
@@ -0,0 +1,36 @@
+<?php
+
+require_once('_init.php');
+
+$options = array();
+$pageUri = "{$_SERVER['PHP_SELF']}?";
+
+if (isset($_REQUEST['filterServers']) && is_array($_REQUEST['filterServers']))
+{
+ $options['filterServers'] = $_REQUEST['filterServers'];
+ foreach ($options['filterServers'] as $filterServer)
+ {
+ $pageUri .= 'filterServers[]=' . intval($filterServer) . '&';
+ }
+}
+if (isset($_REQUEST['filterName']) && strlen(trim($_REQUEST['filterName'])) > 0)
+{
+ $options['filterName'] = $_REQUEST['filterName'];
+ $pageUri .= "filterName=" . urlencode($_REQUEST['filterName']) . '&';
+}
+if (isset($_REQUEST['sort']) && strlen(trim($_REQUEST['sort'])) > 0)
+{
+ $options['sort'] = $_REQUEST['sort'];
+}
+
+$serverList = new GA_ServerList($options);
+$serverList->addServers($cfgServers);
+
+$view->versionData = $serverList->getVersionData();
+$view->functionData = $serverList->getFunctionData();
+$view->errors = $serverList->getErrors();
+$view->pageUri = $pageUri;
+
+$view->display('queue.tpl.php');
+
+?>
View
@@ -0,0 +1,30 @@
+<?php
+
+require_once('_init.php');
+
+$options = array();
+$pageUri = "{$_SERVER['PHP_SELF']}?";
+
+if (isset($_REQUEST['filterServers']) && is_array($_REQUEST['filterServers']))
+{
+ $options['filterServers'] = $_REQUEST['filterServers'];
+ foreach ($options['filterServers'] as $filterServer)
+ {
+ $pageUri .= 'filterServers[]=' . intval($filterServer) . '&';
+ }
+}
+if (isset($_REQUEST['sort']) && strlen(trim($_REQUEST['sort'])) > 0)
+{
+ $options['sort'] = $_REQUEST['sort'];
+}
+
+$serverList = new GA_ServerList($options);
+$serverList->addServers($cfgServers);
+
+$view->versionData = $serverList->getVersionData();
+$view->errors = $serverList->getErrors();
+$view->pageUri = $pageUri;
+
+$view->display('servers.tpl.php');
+
+?>
@@ -0,0 +1,2 @@
+</body>
+</html>
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <link rel="stylesheet" type="text/css" href="css/style.css" />
+</head>
+<body class="content">
+
+ <div>
+ <ul class="topmenu">
+ <li><a class="tab" target="_parent" href="index.php?action=queue">Queue</a></li>
+ <li><a class="tab" target="_parent" href="index.php?action=workers">Workers</a></li>
+ <li><a class="tab" target="_parent" href="index.php?action=servers">Servers</a></li>
+ </ul>
+ </div>
+ <br style="clear:both;" />
+
+ <?php foreach ($this->errors as $error) { ?>
+ <br />
+ <div class="error"><?php echo htmlspecialchars($error); ?></div>
+ <?php } ?>
View
@@ -9,7 +9,7 @@
Gearman Monitor
</div>
- <form id="filterForm" action="content.php" target="contentFrame">
+ <form id="filterForm" action="<?php echo $this->action; ?>.php" target="contentFrame">
<input type="hidden" name="sort" id="filterSort" value="name" />
<input type="hidden" name="dir" id="filterDir" value="asc" />
View
@@ -5,8 +5,8 @@
</head>
<?php if ($this->gearmanClassExists) { ?>
<frameset cols="250,*" rows="*" id="mainFrame">
- <frame frameborder="0" id="filterFrame" name="filterFrame" src="filter.php" />
- <frame frameborder="0" id="contentFrame" name="contentFrame" src="content.php?sort=<?php echo GA_ServerList::SORT_NAME; ?>" />
+ <frame frameborder="0" id="filterFrame" name="filterFrame" src="filter.php?action=<?php echo $this->action; ?>" />
+ <frame frameborder="0" id="contentFrame" name="contentFrame" src="<?php echo $this->action; ?>.php?sort=<?php if ($this->action != 'queue') { echo GA_ServerList::SORT_SERVER; } else { echo GA_ServerList::SORT_NAME; } ?>" />
<noframes>
<body>Frame-capable browser required</body>
</noframes>
View
@@ -0,0 +1,31 @@
+<?php include('content_header.tpl.php'); ?>
+
+ <h2>Queue</h2>
+
+ <table>
+ <thead>
+ <tr>
+ <th><?php $this->fnSortCol($this->pageUri, 'Server', GA_ServerList::SORT_SERVER); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Function', GA_ServerList::SORT_NAME); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Jobs in queue', GA_ServerList::SORT_JOBS_IN_QUEUE); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Jobs running', GA_ServerList::SORT_JOBS_RUNNING); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Workers registered', GA_ServerList::SORT_WORKERS); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php $i = 0; foreach ($this->functionData as $functionItem) { ?>
+ <tr class="<?php echo ($i % 2 ? "even" : "odd"); ?>">
+ <td><?php echo htmlspecialchars($functionItem['server']); ?></td>
+ <td><?php echo htmlspecialchars($functionItem['name']); ?></td>
+ <td class="ra"><?php echo $functionItem['in_queue']; ?></td>
+ <td class="ra"><?php echo $functionItem['jobs_running']; ?></td>
+ <td class="ra">
+ <?php if ($functionItem['capable_workers'] == 0 && $functionItem['in_queue'] > 0) { ?><img src="images/s_warn.png" /><?php } ?>
+ <?php echo $functionItem['capable_workers']; ?>
+ </td>
+ </tr>
+ <?php $i ++; } ?>
+ </tbody>
+ </table>
+
+<?php include('content_footer.tpl.php'); ?>
View
@@ -0,0 +1,22 @@
+<?php include('content_header.tpl.php'); ?>
+
+ <h2>Gearman servers</h2>
+
+ <table>
+ <thead>
+ <tr>
+ <th>Server</th>
+ <th>Version</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php $i = 0; foreach ($this->versionData as $serverIndex => $serverVersion) { ?>
+ <tr class="<?php echo ($i % 2 ? "even" : "odd"); ?>">
+ <td><?php echo htmlspecialchars($this->servers[$serverIndex]['name']); ?></td>
+ <td class="ra"><?php echo $serverVersion; ?></td>
+ </tr>
+ <?php $i ++; } ?>
+ </tbody>
+ </table>
+
+<?php include('content_footer.tpl.php'); ?>
View
@@ -0,0 +1,34 @@
+ <?php include('content_header.tpl.php'); ?>
+
+ <h2>Workers</h2>
+
+ <table>
+ <thead>
+ <tr>
+ <th><?php $this->fnSortCol($this->pageUri, 'Server', GA_ServerList::SORT_SERVER); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'IP', GA_ServerList::SORT_IP); ?></th>
+ <th>Functions</th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Descriptor', GA_ServerList::SORT_FD); ?></th>
+ <th><?php $this->fnSortCol($this->pageUri, 'Id', GA_ServerList::SORT_ID); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php $i = 0; foreach ($this->workersData as $workerItem) { ?>
+ <tr class="<?php echo ($i % 2 ? "even" : "odd"); ?>">
+ <td><?php echo htmlspecialchars($workerItem['server']); ?></td>
+ <td><?php echo $workerItem['ip']; ?></td>
+ <td>
+ <ul>
+ <?php foreach ($workerItem['abilities'] as $ability) { ?>
+ <li><?php echo $ability; ?></li>
+ <?php } ?>
+ </ul>
+ </td>
+ <td class="ra"><?php echo $workerItem['fd']; ?></td>
+ <td class="ra"><?php echo $workerItem['id']; ?></td>
+ </tr>
+ <?php $i ++; } ?>
+ </tbody>
+ </table>
+
+<?php include('content_footer.tpl.php'); ?>
Oops, something went wrong.

0 comments on commit f2075d1

Please sign in to comment.