Jump to content

[PHP, MYSQL] quick stats


jcroom

Recommended Posts

I was bored. </story>

 

This will show you:

# of servers you have

# of suspended game servers

# of active game servers

total # of game servers

total # of slots you host

 

http://smokin-servers.com/files/quickstats/quickstats.zip

 

include.php:

 

<?php



$link = mysql_connect('IPADDRESS', 'USERNAME', 'PASSWORD');
if (!$link) {
die('Not connected : ' . mysql_error());
}


$db_selected = mysql_select_db('DATABASENAME', $link);
if (!$db_selected) {
die ('Can\'t Find DB : ' . mysql_error());
}



// hi
$totalservers = mysql_query("SELECT COUNT(SERVER_ID) FROM tc_servers");
$ts = mysql_result($totalservers, 0);
$suspended = mysql_query("SELECT COUNT(SERVICE_ID) FROM tc_services WHERE STARTUP_TYPE = 3");
$sus = mysql_result($suspended, 0);
$active = mysql_query("SELECT COUNT(SERVICE_ID) FROM tc_services WHERE STARTUP_TYPE = 1");
$act = mysql_result($active, 0);
$totalgservers = mysql_query("SELECT COUNT(SERVICE_ID) FROM tc_services");
$tg = mysql_result($totalgservers, 0);
$totalslots = mysql_query("SELECT SUM(SLOTS) FROM tc_services");
$tsc = mysql_result($totalslots, 0);
// 

?>

 

index.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TCAdmin Quick Stats</title>
</head>
<?php include 'include.php'; ?>
<body>
<p>TCAdmin Quick Stats</p>


<br />
<table width="200" height="42" border="1">
 <tr>
   <td>Total # of Servers: </td>
 </tr>
 <tr>
   <td><div align="center"><?php echo $ts; ?></div>
   </td>
 </tr>
</table>
<br />
<table width="235" border="1">
 <tr>
   <td width="166"><div align="center">Suspended Game Servers:</div></td>
   <td width="53"><div align="center"><?php echo $sus; ?></div></td>
 </tr>
 <tr>
   <td><div align="center">Active Game Servers:</div></td>
   <td><div align="center"><?php echo $act; ?></div></td>
 </tr>
 <tr>
   <td><div align="center">Total # of Game Servers</div></td>
   <td><div align="center"><?php echo $tg; ?></div></td>
 </tr>
</table>
<br />
<table width="168" border="1">
 <tr>
   <td width="101">Total Slot Count</td>
   <td width="51"><div align="center"><?php echo $tsc; ?></div></td>
 </tr>
</table>
<p> </p>
</body>
</html>

 

edit: oh yea make sure you change the login and database info in include.php.

Link to comment
Share on other sites

  • 2 months later...

Hi Guys,

 

I too found this thread of interest, i've used this as a base for the current players quick check which i have implemented on our site to give us the number of current players accurate to 30 minutes. The variable $cur will contain the number of users currently connected.

 

<?php

$link = mysql_connect('SERVER', 'USERNAME', 'PASSWORD');
if (!$link) {
die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('DATABASE', $link);
if (!$db_selected) {
die ('Can\'t Find DB : ' . mysql_error());
}

$minute = date('i');
if ($minute > '30') { $rounded = '30'; } else { $rounded = '00'; }
$now = date('Y-m-d H:');

$current = mysql_query("SELECT SUM(AVERAGE_PLAYERS) FROM tc_service_performance WHERE PERF_DATE='$now$rounded'");
$cur = mysql_result($current, 0);

?>

 

Hope this comes in handy for anybody interested.

 

Cheers,

 

Phil

Link to comment
Share on other sites

The above seems to be working but how do I enable logging of average slots within TCA? I've looked all over the place, "Collect Game Server Performance Data" is enabled.

 

I don't think TCA does averages itself, rather they are calculated on-the-fly using the counts and time period.

Link to comment
Share on other sites

Hi Dan,

 

That php i have included above gets it from the tc_service_performce table, if you check that table you will notice that it collects and stores the data at 30 minute intervals, so lets say you wanted to check previous times for the slot counts you would just need to modify the $cur value.

 

I have made it do it does the current half hour, but you can set that to any value you like through a form, but the format for the variable $cur MUST be:

 

YYYY-MM-DD HH:MM

eg. 2009-05-13 09:26

 

Hope that helps!

 

Phil

Link to comment
Share on other sites

Hey Dan,

 

You need to ensure you have 'Game Server Performance Data' enabled in:

System Settings -> Plugins -> GameMonitor Configuration

 

I'm assuming if you dont have that enabled you also don't use the auto-restart/branding/slot check count enabled either? Thats within the same plugin.

 

Cheers,

 

Phil

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use