Add pagination fuctionality to log page
authorYugo Nagata <nagata@sraoss.co.jp>
Wed, 24 Jul 2013 23:06:37 +0000 (08:06 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Wed, 24 Jul 2013 23:06:37 +0000 (08:06 +0900)
bootstrap.php
innerLog.php
lang/en.lang.php
lang/ja.lang.php
screen.css
status.php
templates/elements/status_js.tpl
templates/innerLog.tpl

index bff53ddb0513a0464b3f803ec63fb6159cffbc33..24385c4da4f3f980b47239f51eeb2676694c861a 100644 (file)
@@ -39,4 +39,5 @@ define('PCP_TIMEOUT', 10);
 
 define('PGPOOL_WAIT_SECONDS', 10);
 define('REFRESH_LOG_SECONDS', 2000);
+define('EACH_LOG_LINES', 50);
 define('NO_ARGS', ' ');
index 9bac2fe5134e3f41a26900b9a57a37dd0c609763..7b8dcaeecf173fae7465b166bdf44a80d8c3d4c5 100644 (file)
@@ -29,38 +29,77 @@ if (!isset($_SESSION[SESSION_LOGIN_USER])) {
     exit();
 }
 
+$logAction = (isset($_GET['logAction']) && $_GET['logAction'] ?
+    $_GET['logAction'] : 'all');
+$logOffset = (isset($_GET['logOffset']) && $_GET['logOffset'] ?
+    $_GET['logOffset'] : 0);
+$logEnd = (isset($_GET['logEnd']) && $_GET['logEnd'] ?
+    $_GET['logEnd'] : 0);
+
 $pgpoolLog = _PGPOOL2_LOG_FILE;
 if ($pgpoolLog == '') {
     $logDir = readLogDir();
     $pgpoolLog = "$logDir/pgpool.log";
 }
 
-$logFile = @file($pgpoolLog);
-if ($logFile == FALSE) {
+$logFileAll = @file($pgpoolLog);
+if ($logFileAll == FALSE) {
     $errorCode = 'e8001';
     $tpl->assign('errorCode', $errorCode);
     $tpl->display('innerError.tpl');
     exit();
 }
+$logTotalLines = count($logFileAll);
 
-$logSplitFile = array();
-for ($i = 0; $i < count($logFile); $i++) {
-    $words = explode(" ", $logFile[$i]);
-    $words = array_merge(array_diff($words, array("")));
+switch ($logAction) {
+    case 'latest':
+        $logEnd = $logTotalLines;
+        $logOffset = $logTotalLines - EACH_LOG_LINES;
+        break;
+    case 'prev':
+        $logEnd = $logOffset;
+        $logOffset = $logOffset - EACH_LOG_LINES;
+        break;
+    case 'next':
+        $logOffset = $logEnd;
+        $logEnd = $logEnd + EACH_LOG_LINES;
+        break;
+    case 'all':
+    default:
+        $logEnd = $logTotalLines;
+        $logOffset = 0;
+        break;
+}
 
-    $logFile[$i] = array('timestamp' => $words[0]. ' '. $words[1],
-                         'level'     => $words[2],
-                         'pid'       => $words[3]. ' '. $words[4],
-                         'message'   => ''
-                         );
+$logOffset = min(max($logOffset, 0), $logTotalLines);
+$logEnd = min(max($logEnd, 0), $logTotalLines);
+if ($logOffset == $logEnd) {
+    $logEnd = $logTotalLines;
+    $logOffset = 0;
+}
 
+$logFile = array();
+for ($i = $logOffset; $i < $logEnd; $i++) {
+    $words = explode(" ", $logFileAll[$i]);
+    $words = array_merge(array_diff($words, array("")));
+    $logLine = array('timestamp' => $words[0]. ' '. $words[1],
+                     'level'     => $words[2],
+                     'pid'       => $words[3]. ' '. $words[4],
+                     'message'   => ''
+                     );
     for ($j = 5; $j < count($words); $j++) {
-        $logFile[$i]['message'] .= ' '. $words[$j];
+        $logLine['message'] .= ' '. $words[$j];
     }
-    $logFile[$i]['message'] = trim($logFile[$i]['message']);
+    $logLine['message'] = trim($logLine['message']);
+    $logFile[] = $logLine;
 }
 
-$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS);
 $tpl->assign('logFile', $logFile);
+$tpl->assign('logTotalLines', $logTotalLines);
+$tpl->assign('logAction', $logAction);
+$tpl->assign('logOffset', $logOffset);
+$tpl->assign('logEnd', $logEnd);
+$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS);
+$tpl->assign('eachLogLines', EACH_LOG_LINES);
 $tpl->display('innerLog.tpl');
 ?>
index 57351584eb0885923c544a8f0e3eb9b8a8d59497..8feb7569a571ba569b003827a67e21d85dbf7635 100644 (file)
@@ -260,7 +260,13 @@ $message = array(
     'strLog' => 'Log',
     'strLogin' => 'Login',
     'strLoginName' => 'Login Name',
+    'strLogLatest' => 'Show the Latest',
+    'strLogNext' => 'Next',
     'strLogout' => 'Logout',
+    'strLogPrev' => 'Previous',
+    'strLogReload' => 'Reload',
+    'strLogShowAll' => 'Show the All Lines',
+    'strLogShowLines' => 'Lines',
     'strMasterServer' => 'Master Server',
     'strMasterSlaveMode' => 'Master Slave mode',
     'strMeasures' => 'Measures',
@@ -348,7 +354,7 @@ $message = array(
     'strVIP' => 'Virtual IP',
     'strWdActive' => 'Active',
     'strWdDown' => 'Down',
-    'strWdInit' => 'Not Running',
+    'strWdInit' => 'Not Started',
     'strWdStandby' => 'Standby',
     'strWeight' => 'Weight',
 
index 686b4fb2566dc0f176aee0b6cd04f3ed49636a92..972de53385913325fcb373b3258e3633dfb6f37e 100644 (file)
@@ -251,7 +251,13 @@ $message = array(
     'strLog' => 'ログ',
     'strLogin' => 'ログイン',
     'strLoginName' => 'ログイン名',
+    'strLogLatest' => '最新',
+    'strLogNext' => '次へ',
     'strLogout' => 'ログアウト',
+    'strLogPrev' => '前へ',
+    'strLogReload' => '更新',
+    'strLogShowAll' => '全ての行を表示',
+    'strLogShowLines' => '行を表示',
     'strMasterServer' => 'マスターサーバ',
     'strMasterSlaveMode' => 'マスタースレーブモード',
     'strMeasures' => '対策',
@@ -297,8 +303,8 @@ $message = array(
     'strQueryCache' => 'クエリキャッシュ',
     'strQueryStr' => 'クエリ文字列',
     'strReloadPgpool' => '設定リロード',
-    'strReplicationMode' => 'レプリケーションモード',
     'strReloadPgsql' => '設定リロード',
+    'strReplicationMode' => 'レプリケーションモード',
     'strReset' => 'リセット',
     'strRestart' => '再起動',
     'strRestartOption' => 'pgpool再起動オプション',
index 689506f5daf97949cf6b081816f14b99b6b9af22..6572142678e086e34099b45822850b05703bf377 100644 (file)
@@ -67,7 +67,7 @@ td.pgconfig_msg img {
 /* --------------------------------------------------------------------- */
 
 a:link {
-  color: red;
+  color: red; 
   text-decoration: none;
 }
 a:visited {
@@ -82,6 +82,11 @@ a img {
   border: none;
 }
 
+#div_log a:link, #div_log a:visited {
+  color: orangered;
+  text-decoration: underline;
+}
+
 /* --------------------------------------------------------------------- */
 /* input                                                                 */
 /* --------------------------------------------------------------------- */
index 17f7d4825b35c69c840154cfd45b415d8ea32856..ed7adc26393a3643ec2a730d5de46c787fa8ce07 100644 (file)
@@ -53,7 +53,8 @@ $tpl->assign('pgpoolConf',     _PGPOOL2_CONFIG_FILE);
 $tpl->assign('pcpConf',        _PGPOOL2_PASSWORD_FILE);
 $tpl->assign('refreshTime',    (0 <= _PGPOOL2_STATUS_REFRESH_TIME) ?
                                _PGPOOL2_STATUS_REFRESH_TIME * 1000 : 5000);
-$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS);
+$tpl->assign('refreshTimeLog', (0 <= REFRESH_LOG_SECONDS) ?
+                               REFRESH_LOG_SECONDS * 1000 : 5000);
 $tpl->assign('useSyslog',      useSyslog());
 $tpl->assign('pipe',           (isPipe(_PGPOOL2_LOG_FILE)) ? 1 : 0);
 $tpl->assign('msgStopPgpool',  $message['msgStopPgpool']);
@@ -195,7 +196,7 @@ function _doAction($action, $nodeNumber)
     return $viewPHP;
 }
 
-/** Set node info from pgpool.conf when pgpool isn't active */
+/** Set node info from pgpool.conf when pgpool isn't running */
 function setNodeInfoFromConf()
 {
     global $tpl;
index 1bfbfb6b93397f2deae6d1f1e0faa15c7fc3e03c..a42d1fbfda721610e094047dbc908c0b884654bf 100644 (file)
@@ -3,6 +3,7 @@
 var refreshTime  = "{$refreshTime|escape}";
 var refreshTimeLog  = "{$refreshTimeLog|escape}";
 var view         = "{$viewPHP|escape}";
+var innerParameter = '';
 var msgStartPgpool   = "{$message.msgStartPgpool|escape}";
 var msgStopPgpool    = "{$message.msgStopPgpool|escape}";
 var msgReloadPgpool    = "{$message.msgReloadPgpool|escape}";
@@ -38,14 +39,14 @@ function load()
             if (content == null) { return; }
 
             content.innerHTML  = ret;
-            if (view != "innerLog.php") {
+            if (view == "innerLog.php") {
                 setTimeout("load()", refreshTimeLog);
             } else if (refreshTime > 0) {
                 setTimeout("load()", refreshTime);
             }
         }
     }
-    xmlhttp.open('GET', view, true);
+    xmlhttp.open('GET', view + innerParameter, true);
     xmlhttp.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
     xmlhttp.send("");
 }
@@ -178,6 +179,24 @@ function execRemoveBackend(node_num)
     execute('removeBackend', msgRemoveBackend, node_num);
 }
 
+/* --------------------------------------------------------------------- */
+/* Log Action                                                            */
+/* --------------------------------------------------------------------- */
+
+function execLogAction(logAction)
+{
+    innerParameter = '?logAction=' + logAction +
+                    '&logOffset=' + document.logForm.logOffset.value +
+                    '&logEnd=' + document.logForm.logEnd.value;
+    return reloadLog();
+}
+
+function reloadLog()
+{
+    load();
+    return false;
+}
+
 /* --------------------------------------------------------------------- */
 /* execute pgpool's commands                                             */
 /* --------------------------------------------------------------------- */
index ea7cf04abf0c8150f44ef24c7a2312ebb8f77f97..c9d28017127cc1e8aa1c9a48c22c237c86c4cac7 100644 (file)
     <br clear="all">
 {/if}
 
+<div id="div_log">
+    <form action="status.php" name="logForm" method="post" />
+      <input type="hidden" name="action" value="log"/>
+
+      <input type="hidden" name="logAction" />
+      <input type="hidden" name="logOffset" value="{$logOffset}"/>
+      <input type="hidden" name="logEnd" value="{$logEnd}"/>
+
+      <p>
+      <input type="button" onClick="reloadLog()"
+             value="{$message.strLogReload|escape}"/>
+      {if $logAction == 'all'}
+      <input type="button" onClick="execLogAction('latest')"
+             value="{$message.strLogLatest|escape} {$eachLogLines} {$message.strLogShowLines|escape}"/>
+      {else}
+      <input type="button" onClick="execLogAction('all')"
+             value="{$message.strLogShowAll|escape}"/>
+      {/if}
+      </p>
+      <p>
+      <br />
+      {if $logAction != 'all'}
+          <span>
+          {if $logOffset != 0}
+          <a href="javascript:void(0)"
+             onClick="execLogAction('prev')">{$message.strLogPrev|escape}</a>
+          {/if}
+          {if $logEnd < $logTotalLines}
+          <a href="javascript:void(0)"
+             onClick="execLogAction('next')">{$message.strLogNext|escape}</a>
+          {/if}
+          </span>
+      {/if}
+      <span>
+      {if $logAction == 'all'}
+      (Total {$logTotalLines} lines)
+      {else}
+      ({$logOffset + 1} - {$logEnd}
+      of {$logTotalLines} lines)
+      {/if}
+      </span>
+      </p>
+    </form>
+</div>
+
 <table>
   <thead>
   </thead>