Frage

I'm creating an game server list, and I want to measure uptime for certain server (to be specific, uptime should be displayed in percents).

I have configured a cronjob for my script, which is checking every 5 minutes if server is up or down, so I can easly get the server status.

I need an idea on how can I measure each server uptime basing on the above data. I'd have to save down and up time for each server every one minute the script is executing?

War es hilfreich?

Lösung

If you don't care about many details and you just want the up and down time. Then you could save 2 numbers in a file, one being the current percentage and the other being the current number of measures the script took.

For example: '96 800'.

Then, whenever the script is executed, use this formula, assuming that the percentage (96) is X, the number of saves is Y (800) and the current measure is Z (0 or 1)

X=X/100;
X=(X*Y+Z)/(Y+1);  //You get the new value of the percentage, X. Be careful as they need to be long values.
Y=Y+1;    //And the current number of interactions.
X=X*100;

That's of course just pseudo code and won't work straight away, it's just to give you an idea of one way to do it. You must also include a way of reading a file and saving it wherever you want of your page that contains those 2 numbers.

As Jamie stated, this is assuming that crontime is still working despite of the server is down.

PS, you could also add a system from other server to check this server uptime, but it would need to be statistically calculated (and error tends to 0 when many other servers are added, but that'd be too difficult) as you'd need to take into account the other server's uptime also...

Andere Tipps

You could parse the /proc/uptime file. It is a textual file on Linux (which you should read sequentially), giving the uptime of the server machine:

   % cat /proc/uptime 
   129657.69 506917.57

More details in the proc(5) man page.

PS. No real disk IO is involved when reading /proc/ filesystem (with pseudo-files). So reading it is really fast.

Are you talking about the Apache server or the entire computer server? If you're only monitoring Apache:

If you want to monitor the entire system, cronjobs might be a bit futile since they won't be running if their host OS is down. In this case, the server logs should contain all the information you need.

your question is not clear.If you want to get remote server uptime stat, SSH is an option.schedule cron in one server for a script which will remotely check uptime for others.

If your "game servers" are running in actual unix or linux virtual machines, a better idea might be to measure the ACTUAL server uptime.

In Unix-like operating systems, you have a command called uptime:

[ghoti@pc ~]$ uptime
 6:37PM  up 10 days,  1:26, 52 users, load averages: 0.26, 0.35, 0.34
[ghoti@pc ~]$ 

If you have the ability to execute shell commands from PHP, then you can capture this output to a variable in PHP and parse it to determine the actual server uptime. Record this wherever you like, but one of the favourite ways is using RRDTool graphs. RRD is the database format, then you can use tools like Munin or Cacti to build the graphs. Might be more interesting than just the uptime as a number!

On the other hand, if you'd also like the ability to automatically notify people when their servers go offline, and you want the flexibility to monitor ANY kind of service (HTTP, SMTP, Unreal Server, whatever), have a look at tools like Nagios or Icinga.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top