Monitoring only system resources is not enough, it is possible for our services to fail without any problem with system resources. Example, Nginx could crash, MySQL could stop working etc even when the system is doing fine otherwise.
To be alerted of these, we need to monitor
- Whether a process is running (nginx, mysql etc)
- Whether the service is responding on their respective ports (80,443 for nginx, 3306 for mysql)
So we will create checks for these
In this case, we have two processes that we want to monitor : Nginx and MySQL
Both are already installed on our wordpress
server. If you do not have them, go ahead and install them.
We will use the nagiosfoundation plugin to monitor running processes
sensuctl asset add ncr-devops-platform/nagiosfoundation -r nagiosfoundation
sensuctl entity list
sensuctl entity update wordpress
For Entity Class, press enter.
For Subscriptions, type system,webserver and press enter.
sensuctl check create nginx_service \
--command 'check_service --name nginx' \
--interval 15 \
--subscriptions webserver \
--runtime-assets nagiosfoundation
We should see the event in few seconds
sensuctl event list
Go ahead and stop Nginx and see what happens in sensu
Previously we were checking if the process was running. But this is not enough. It is possible for nginx to be running and still unresponsive. So, we need a check that does an actual http request
We will use https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-http for that
sensuctl asset add sensu-plugins/sensu-plugins-http:6.0.0 -r sensu-plugins-http
We have already added the ruby runtime in the past, if you have not done that, make sure that asset is also added
sensuctl asset add sensu/sensu-ruby-runtime:0.1.0 -r sensu-ruby-runtime
sensuctl check create nginx_http \
--command 'check-http.rb -u http://localhost' \
--interval 15 \
--subscriptions webserver \
--runtime-assets sensu-plugins-http,sensu-ruby-runtime
sensuctl event list
- Create a check to monitor if mysql is running
- Create a check to connect to mysql database