Fetch the repository succeeded.
<?php
/* $Id: mysql_stats.php,v 1.0 2005/06/20 22:52:24 CoLdFuSiOn Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
require "include/bittorrent.php";
dbconn();
loggedinorreturn();
require_once(get_langfile_path());
/**
* Checks if the user is allowed to do what he tries to...
*/
if (get_user_class() < UC_SYSOP)
stderr("Error", "Permission denied.");
$GLOBALS["byteUnits"] = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
$day_of_week = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
$month = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
// See http://www.php.net/manual/en/function.strftime.php to define the
// variable below
$datefmt = '%B %d, %Y at %I:%M %p';
$timespanfmt = '%s days, %s hours, %s minutes and %s seconds';
////////////////// FUNCTION LIST /////////////////////////
/**
* Formats $value to byte view
*
* @param double the value to format
* @param integer the sensitiveness
* @param integer the number of decimals to retain
*
* @return array the formatted value and its unit
*
* @access public
*
* @author staybyte
* @version 1.0 - 20 July 2005
*/
function formatByteDown($value, $limes = 6, $comma = 0)
{
$dh = pow(10, $comma);
$li = pow(10, $limes);
$return_value = $value;
$unit = $GLOBALS['byteUnits'][0];
for ( $d = 6, $ex = 15; $d >= 1; $d--, $ex-=3 ) {
if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex)) {
$value = round($value / ( pow(1024, $d) / $dh) ) /$dh;
$unit = $GLOBALS['byteUnits'][$d];
break 1;
} // end if
} // end for
if ($unit != $GLOBALS['byteUnits'][0]) {
$return_value = number_format($value, $comma, '.', ',');
} else {
$return_value = number_format($value, 0, '.', ',');
}
return array($return_value, $unit);
} // end of the 'formatByteDown' function
/**
* Returns a given timespan value in a readable format.
*
* @param int the timespan
*
* @return string the formatted value
*/
function timespanFormat($seconds)
{
$return_string = '';
$days = floor($seconds / 86400);
if ($days > 0) {
$seconds -= $days * 86400;
}
$hours = floor($seconds / 3600);
if ($days > 0 || $hours > 0) {
$seconds -= $hours * 3600;
}
$minutes = floor($seconds / 60);
if ($days > 0 || $hours > 0 || $minutes > 0) {
$seconds -= $minutes * 60;
}
return (string)$days." Days ". (string)$hours." Hours ". (string)$minutes." Minutes ". (string)$seconds." Seconds ";
}
/**
* Writes localised date
*
* @param string the current timestamp
*
* @return string the formatted date
*
* @access public
*/
function localisedDate($timestamp = -1, $format = '')
{
global $datefmt, $month, $day_of_week;
if ($format == '') {
$format = $datefmt;
}
if ($timestamp == -1) {
$timestamp = time();
}
$date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
$date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
return strftime($date, $timestamp);
} // end of the 'localisedDate()' function
////////////////////// END FUNCTION LIST /////////////////////////////////////
stdhead("数据库状态");
/**
* Displays the sub-page heading
*/
echo '<h1 align=center>' . "\n"
.$lang_mysql_stats['head_mysql_stats']. "\n"
. '</h1>' . "\n";
/**
* Sends the query and buffers the result
*/
$res = @sql_query('SHOW STATUS') or Die(mysql_error());
while ($row = mysql_fetch_row($res)) {
$serverStatus[$row[0]] = $row[1];
}
@mysql_free_result($res);
unset($res);
unset($row);
/**
* Displays the page
*/
//Uptime calculation
$res = @sql_query('SELECT UNIX_TIMESTAMP() - ' . $serverStatus['Uptime']);
$row = mysql_fetch_row($res);
//echo sprintf("Server Status Uptime", timespanFormat($serverStatus['Uptime']), localisedDate($row[0])) . "\n";
?>
<table id="torrenttable" border="1"><tr><td>
<?php
print($lang_mysql_stats['text_running']."<font color=red>". timespanFormat($serverStatus['Uptime'])."</font>" .$lang_mysql_stats['text_started']."<font color=red>" .localisedDate($row[0])) . "</font>\n";
?>
</td></tr></table>
<?php
mysql_free_result($res);
unset($res);
unset($row);
//Get query statistics
$queryStats = array();
$tmp_array = $serverStatus;
foreach($tmp_array AS $name => $value) {
if (substr($name, 0, 4) == 'Com_') {
$queryStats[str_replace('_', ' ', substr($name, 4))] = $value;
unset($serverStatus[$name]);
}
}
unset($tmp_array);
?>
<ul>
<li>
<b><?php echo $lang_mysql_stats['text_server_traffic']?></b> <?php echo $lang_mysql_stats['text_traffic_desc']?>
<br />
<table border="0">
<tr>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th colspan="2" bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_traffic']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perhour']?></th>
</tr>
<tr>
<td bgcolor="#EFF3FF"><?php echo $lang_mysql_stats['form_received']?></td>
<td bgcolor="#EFF3FF" align="right"> <?php echo join(' ', formatByteDown($serverStatus['Bytes_received'])); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo join(' ', formatByteDown($serverStatus['Bytes_received'] * 3600 / $serverStatus['Uptime'])); ?> </td>
</tr>
<tr>
<td bgcolor="#EFF3FF"><?php echo $lang_mysql_stats['form_sent']?></td>
<td bgcolor="#EFF3FF" align="right"> <?php echo join(' ', formatByteDown($serverStatus['Bytes_sent'])); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo join(' ', formatByteDown($serverStatus['Bytes_sent'] * 3600 / $serverStatus['Uptime'])); ?> </td>
</tr>
<tr>
<td bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_total']?></td>
<td bgcolor="lightgrey" align="right"> <?php echo join(' ', formatByteDown($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent'])); ?> </td>
<td bgcolor="lightgrey" align="right"> <?php echo join(' ', formatByteDown(($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent']) * 3600 / $serverStatus['Uptime'])); ?> </td>
</tr>
</table>
</td>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th colspan="2" bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_connections']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perhour']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_percentage']?></th>
</tr>
<tr>
<td bgcolor="#EFF3FF"><?php echo $lang_mysql_stats['form_failed']?></td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format($serverStatus['Aborted_connects'], 0, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($serverStatus['Aborted_connects'] * 3600 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo ($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_connects'] * 100 / $serverStatus['Connections']), 2, '.', ',') . ' %' : '---'; ?> </td>
</tr>
<tr>
<td bgcolor="#EFF3FF"><?php echo $lang_mysql_stats['form_aborted']?></td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format($serverStatus['Aborted_clients'], 0, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($serverStatus['Aborted_clients'] * 3600 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo ($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_clients'] * 100 / $serverStatus['Connections']), 2 , '.', ',') . ' %' : '---'; ?> </td>
</tr>
<tr>
<td bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_total']?></td>
<td bgcolor="lightgrey" align="right"> <?php echo number_format($serverStatus['Connections'], 0, '.', ','); ?> </td>
<td bgcolor="lightgrey" align="right"> <?php echo number_format(($serverStatus['Connections'] * 3600 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="lightgrey" align="right"> <?php echo number_format(100, 2, '.', ','); ?> % </td>
</tr>
</table>
</td>
</tr>
</table>
</li>
<br />
<li>
<?php print("<b>".$lang_mysql_stats['text_server_query']."</b>".$lang_mysql_stats['text_query_desca']. number_format($serverStatus['Questions'], 0, '.', ',').$lang_mysql_stats['text_query_descb']."\n"); ?>
<table border="0">
<tr>
<td colspan="2">
<br />
<table id="torrenttable" border="0" align="right">
<tr>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_total']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perhour']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perminute']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_persecond']?></th>
</tr>
<tr>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format($serverStatus['Questions'], 0, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($serverStatus['Questions'] * 3600 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($serverStatus['Questions'] * 60 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($serverStatus['Questions'] / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th colspan="2" bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_querytype']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perhour']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_percentage']?></th>
</tr>
<?php
$useBgcolorOne = TRUE;
$countRows = 0;
foreach ($queryStats as $name => $value) {
// For the percentage column, use Questions - Connections, because
// the number of connections is not an item of the Query types
// but is included in Questions. Then the total of the percentages is 100.
?>
<tr>
<td bgcolor="#EFF3FF"> <?php echo htmlspecialchars($name); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format($value, 0, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($value * 3600 / $serverStatus['Uptime']), 2, '.', ','); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo number_format(($value * 100 / ($serverStatus['Questions'] - $serverStatus['Connections'])), 2, '.', ','); ?> % </td>
</tr>
<?php
$useBgcolorOne = !$useBgcolorOne;
if (++$countRows == ceil(count($queryStats) / 2)) {
$useBgcolorOne = TRUE;
?>
</table>
</td>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th colspan="2" bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_querytype']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_perhour']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['text_percentage']?></th>
</tr>
<?php
}
}
unset($countRows);
unset($useBgcolorOne);
?>
</table>
</td>
</tr>
</table>
</li>
<?php
//Unset used variables
unset($serverStatus['Aborted_clients']);
unset($serverStatus['Aborted_connects']);
unset($serverStatus['Bytes_received']);
unset($serverStatus['Bytes_sent']);
unset($serverStatus['Connections']);
unset($serverStatus['Questions']);
unset($serverStatus['Uptime']);
if (!empty($serverStatus)) {
?>
<br />
<li>
<b><?php echo $lang_mysql_stats['text_server_status']?></b><br />
<table border="0">
<tr>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_variable']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_value']?></th>
</tr>
<?php
$useBgcolorOne = TRUE;
$countRows = 0;
foreach($serverStatus AS $name => $value) {
?>
<tr>
<td bgcolor="#EFF3FF"> <?php echo htmlspecialchars(str_replace('_', ' ', $name)); ?> </td>
<td bgcolor="#EFF3FF" align="right"> <?php echo htmlspecialchars($value); ?> </td>
</tr>
<?php
$useBgcolorOne = !$useBgcolorOne;
if (++$countRows == ceil(count($serverStatus) / 3) || $countRows == ceil(count($serverStatus) * 2 / 3)) {
$useBgcolorOne = TRUE;
?>
</table>
</td>
<td valign="top">
<table id="torrenttable" border="0">
<tr>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_variable']?></th>
<th bgcolor="lightgrey"><?php echo $lang_mysql_stats['form_value']?></th>
</tr>
<?php
}
}
unset($useBgcolorOne);
?>
</table>
</td>
</tr>
</table>
</li>
<?php
}
?>
</ul>
<?php
stdfoot();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。