New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
PHP+SSH server uptime monitor
Hi All,
I have been googling but didnt found what I'm looking for. Maybe my keywords not good enough,but I have tried many.
What I'm looking for is that a php script for monitoring remote server uptime by utilising SSH. Using password or key file. No installing agents on the remote server.
If you have suggestion or links for any existing script or tutorial,would be appreciated.
Thanks.
Comments
2 numbers: uptime in seconds, idle time (total cores)
No SSH
Thanks @sergiodelatorre
but i'm looking to get uptime of remote server,not local.
Not exactly what you want, but might worth a shot
http://bash.cyberciti.biz/monitoring/get-system-information-in-html-format/
Note: I've never tested it
thanks @jebat_ks
already have a look at that...but its bash script.....
Assuming passwordsless ssh login
thanks @sergiodelatorre
great....by passwordless,it's using key file...but,where should I put this key file...? and how about if there are multiple key file for multiple host...?
Jebat and Shamli is like Malaysian name to me.
Good question
You should generate the key with
Where user is the user executing the php script. It could be apache (mod_php or php-cgi), the user configured in the php-fpm pool...
I've never done this before, try it and tell us
PS: You can specify the key path with -i option, but you must be careful with permissions
@budi1413 I'm malaysian...not sure about Jebat......=)
@sergiodelatorre generating the key is not an issue for me...I'm usually use putty to generate them....but,for executing the php script to authenticate ssh connection using key file,where do I need to place them(the private key)....?
SSH keys are stored in /home/user/.ssh
If you run su - user, the private key should be saved under the relative user .ssh directory
The public key must be added to /home/user/.ssh/authorized_keys
Only one question, why you don't put the first php script in the remote server? It's easier and safer
@sergiodelatorre I dont want to have any agent or php or apache or anything except ssh running on the remote server(for this monitoring purpose)...is it possible to have ssh key file location in the script..? or append the key in the script..?
Another solution: Cronjob in the remote server (5min), creating a static html file and sending to localhost (or wherever). It's safer
@sergiodelatorre a good idea....I can use the link provided by @jebat_ks...
@Shamli just curious I'm a big fan of uptime monitoring scripts and services..And so without offering my own opinion wanted to see what you are planning to do for notifications- possible SMS alerts and so forth. Have you thought beyond just the script yet about these things?
Hi @natestamm that's also in my head...but not for now....i'm looking for this kind of monitoring to avoid having any overhead on the remote server,or to avoid issue if there are any problem with the agent on the remote server.....
for now,i'm looking to make this ssh check into existing monitoring script....if there are none available....for notifications,later,maybe....=)
This kind of thing really isn't hard to make, I'm using exactly that setup for my monitoring, just make sure you restrict your remote SSH users to only the commands necessary for monitoring. I moved on to running a bash script locally and outputting to a file then transferring the file to the monitoring server otherwise it can take some time to poll the servers.
You can look into observium all it requires is SNMPd running on your remote servers and eliminates the need to A. write your own script, B. mess with key based authentication and such and it provides nifty graphs.
Maybe you're going to find something here: http://lowendtalk.com/discussion/17958/2013-review-server-status-monitor-script-tool-from-let/p1
Why dont you run uptime on remote server then passed variable via wget postdata to central php script ?
@nunim great idea...but i'm looking for something simple to setup on new server....create user->set key based auth->monitor from remote.....
@Spirit looking at them....
@drserver if possible,i dont want to have anything run on the remote server....all from central server...
Not sure if it was said in one of the posts above, I admit to not reading them properly.
My suggestion would be a cronjob on the monitoring server executing a script that fetches the information about the remote server and outputs to file on the monitoring server. Then process needed information on the monitoring server.
No need to let php handle the ssh connection, could end up with unresponsive site if not handled correct.