Get notified when the server’s memory usage crosses a certain threshold

"Only a life lived for others is a life worthwhile." – Albert Einstein

Get notified when the server’s memory usage crosses a certain threshold

System administration is very crucial in managing servers. most when we have demanding applications running on a server we will want to keep track of the system usage at all times. While system administrators can require a lot of knowledge in setting up things, Reaction Engine & its reaction rules have a lot to offer in this area to make things easier for everyone – novices, and experts alike.

Let us see how we can set things up so that we can get a smartphone notification when our server’s memory usage exceeds 80%.

1. Install & Enable Reaction Engine

Make sure you have the reaction module installed on your rayjas distribution and enabled.

2. Enable Generic Notifier and Configure Telegram parameters

Once you are done, save and exit.

3. Create a Rule To trigger a Telegram message

Now let us create a simple rule that will listen to the STATS channel and trigger a notification request via the notifier module.

The following reaction-rule is meant to listen to the STATS channel. When the stats data arrives the trigger evaluator will extract the memory percentage value from it and compare it against our defined threshold (80). If the value is greater than 80, the response is triggered once to get the notifier module to send a message over telegram.

{
	"id": "report-high-memeory-usage",
	"description": "Rule to notify high memory usage",
	"listen-to": "/stats",
	"enabled": false,
	"trigger": {
		"on-payload-object": {
			"key": "data.system.memory.percent",
			"on-content": "80",
			"on-condition": "greaterthan"
		},
		"evaluator": "SimpleRuleEvaluator"
	},
	"response":{
		"behaviour": {
			"type": "once"
		},
		"intent": "simple_telegram_notify",
		"parameters": {
			"telegram":{
				"bot_token": "BOT_TOKEN",
				"chat_id": ["CHAT_ID"]
			}
		}
	}	
}

Note 1: You need to replace BOT_TOKEN with the actual token you received from BotFather and CHAT_ID as discovered to enable messages to your telegram client.

Note 2 : chat_id is an array. that means you can have multiple CHAT_IDs in there to deliver messages to multiple users at once privately. Or you can have a single CHAT_ID of a channel/group if the users are a member of that channel/group.

4. Restart Rayjas Service

After making any changes to the JSON configuration files, make sure to double-check the JSON’s validity and then restart rayjas service for changes to take effect.