Server Availability Monitor
SAM is intented to monitor all of your services to be sure that they are working. It's a command line tool that checks servers all the time.
- Before usage
- Supported services
- Typical workflow
- Servers managing
- Reporters
- Logging
- Server configuration details
- Advanced settings
- Monitor output
Before usage
Installation a phar
The simpliest way to install SAM is just download a phar from releases page, make it executable and put it in one of folders listed in your $PATH:
chmod +x sam.phar
sudo mv sam.phar /usr/local/bin/sam
Installation via composer
The preferred way to install SAM is via composer:
-
global installation (additional instructions):
composer global require wapmorgan/server-availability-monitor
-
local installation:
composer require wapmorgan/server-availability-monitor
Further I will use commands for SAM installed globally, but if you've installed it locally, just replace sam
command with vendor/bin/sam
.
Full help
All sub-commands is described in help:
sam list
What server types does it support?
Typical workflow
- Add servers for monitoring. It will ask for some additional information like type of server, hostname, port and other depending on type.
$ sam manage:add
Please select your type of server (defaults to http)
[0] http
[1] mysql
[2] postgresql
[3] memcache
[4] redis
[5] gearman
[6] rabbitmq
> 1
Provide IP-address or hostname of server to monitor: 127.0.0.1
Provide port of server: 3306
Username to access DB: root
Password for username to access DB: root
Please select name of server (default to mysql1):
Successfully added to servers list
- Configure check period
$ sam report:config checkPeriod
Current value: 10
Please provide new value: 7
Successfully updated
email for failure reports
$ sam report:config email
Select transport system for email:
[0] disable
[1] sendmail
[2] SMTP
> 1
Provide From field: abc@gmail.com
Provide To field: admin@gmail.com
Testing sending
and enable logging
$ sam report:config log
Enable or disable logging of check results (disabled now):
[0] disable
[1] enable
> 1
Successfully updated
- Run monitor
$ sam monitor
If any server is down, it will print an error and send a report to configured email:
$ sam monitor
Check at Mon, 12 Jun 2017 02:29:25 +0300: 1 error
compaster.pro reported error
If you want more information, launch monitor with verbosity option:
$ sam monitor -v
Check at Mon, 12 Jun 2017 02:29:27 +0300: 1 error
compaster.pro reported error: Http server reports 301 code when expecting 302
Servers managing
-
Updating server configuration
$ sam manage:edit http1
or with one call
$ sam manage:edit http1 resultCode 302
-
Deleting server from monitoring list
$ sam manage:delete http1
-
Print all servers configured for monitoring
$ sam manage
Reporters
EmailReporter
EmailReporter sends you an email when one of services fails.
It is configurable by
$ sam report:config email
NotifyReporter
NotifyReporter reports a problem with a notification on your desktop via notify-send
command when it's available in your system.
Logging
SAM supports logging of check results.
To configure this feature call
$ sam report:config log
Logger stores information about availability every hour for every server. If any check during a hour fails, the whole hour will be marked as failed. Log file is very lite-weight! It needs only 5 bytes to store information about check results of 1 server per day.
To see log you can use log
command. It supports full and short form.
Full log form
In full form it shows check results for given day, month, year and all time summary. By default it shows log for current date. You can change it with --day=
, --month=
and --year=
options.
$ sam log docker-cms
+------------+----------+
| All log | 2017 |
+------------+----------+
| docker-cms | + |
+------------+----------+
| All checks passed |
+------------+----------+
+--------------+----------+
| Log for 2017 | 6 |
+--------------+----------+
| docker-cms | + |
+--------------+----------+
| All checks passed |
+--------------+----------+
+-----------------+----------+
| Log for 2017-06 | 19 |
+-----------------+----------+
| docker-cms | + |
+-----------------+----------+
| All checks passed |
+-----------------+----------+
+--------------------+----+----+----+----+----+----+----+---+---+---+----+
| Log for 2017-06-19 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
+--------------------+----+----+----+----+----+----+----+---+---+---+----+
| docker-cms | + | + | + | + | + | + | + | + | + | + | + |
+--------------------+----+----+----+----+----+----+----+---+---+---+----+
| All checks passed |
+--------------------+----+----+----+----+----+----+----+---+---+---+----+
Short log form
In short form (additional -s
or --short
option) you can select what information you want to see:
- no options for day log
-
--all-days
option for month log -
--all-months
option for year log -
--all-years
option for all time log
By default it shows log for current date. You can change it with --day=
, --month=
and --year=
options.
$ sam log -s docker-cms
+-------------------+--------------------+
| docker-cms | Log for 2017-06-19 |
+-------------------+--------------------+
| All checks passed | +++++++++++ |
+-------------------+--------------------+
Server configuration details
For all servers hostname/ip and port are required parameters.
Http
For http server it can check result code of result. Typically it should be 200 (for most cases) or 302 / 301 (for redirecting pages).
MySQL
For mysql server you should provide username/password for any user of DB. It will try to connect to DB.
PostgreSQL
For pgsql server you should provide username/password for any user of DB. Also you can specify different name for a database than a username name. It will try to connect to this DB.
Memcache
For memcache server there are no additional parameters.
Redis
For redis server there are no additional parameters.
Gearman
For gearman server there are no additional parameters.
RabbitMQ
For rabbitmq server you should provide username/password for any user of service.
Advanced settings
Also, you can change following settings:
- checkTimeOut - maximum time consumed to check one service. By default is 3 sec.
- emailPeriod - minimum time until SAM send you next email report after the first one.
$ sam report:config SETTING
Monitor output
You can configure what sam
command should output to terminal. By default, it outputs something only if one of servers is unavailable.
If you want, you can make SAM output more information:
- with
-v
option it will print advanced message of server unavailability or the success message. - with
-vv
option it will print all configuration and progress of checking.