1. Overall idea
Overall objective of this implementation is to monitor some parameters of Linux PC such as "RAM usage" , "Mysql" like services and update the status of them to Gadgetkeeper. We can configure some email alerts on Gadgetkeeper to send notifications if the RAM usage is too high or Mysql service is down. This concept can be extended to monitor any other services on the Linux PC and Gadgetkeeper can be configured to send notifications for each event. On this tutorial we have discuss how to monitor RAM usage and how to monitor MySql service state using Gadgetkeeper.
2. Setup Gadgetkeeper
Create the "linux-box" thing first.
Then create the "name" and "uptime" properties as follows.
name property to store the "host name"
uptime property store the "linux box uptime"
Now we need to create "free" event(This event handle the free space of the RAM)
Now create the "highRamUsageAlert" trigger to send notification when RAM usage is high.
1) select the "linux-box" from the drop down list for "Thing"
2) select "free" from the drop down list for "Event"
Click on "Edit Script" button and add the following action script. You can change the threshold value as required in the action script. We have used 100 (Mb) for this example. This trigger will send an email notification to the given email account when the free RAM space is less than 100Mb.
Now create the "mysqlServiceStatus" event as follows. This will care the Mysql service status.
Finally create the "mysqlServiceAlert" Trigger as follows and click on "Edit Script" button and use the following action script. This will send email notification when the MySql service is down.
Still we need the API key for this communication. So create the API key as follows.
3. Setup the script on Linux box
Its time to setup the script on linux box to collect all relevant information and send to Gadgetkeeper. We can easily use REST API for this data communication as follows. In the given script it collect following information and send to Gadgetkeeper.
- System date/time
- System name
- System uptime
- Free RAM space(Mb)
- MySql service status (If down 0 else 1)
Open the "rest_linux_box.sh" script and paste the following code in that file.
4. Test the script with Gadgetkeeper
Set the permission and run the script as follows.
5. Response
The script response will looks like this..
Add a cron job to send these data to Gadgetkeeper periodically.
You can easily monitor any service on the Linux box as shown above. Simply test the service status with a command and send it to Gadgetkeeper as shown above script. Configure the Gadgetkeeper for each service as discussed on step 2.
Above setup will send notification to the mail account at 2 status.
- When the free RAM is less than 100Mb.
- When the MySql service is down.