Today, I went through my credit card statements from the past few months in search for unnecessary subscriptions to purge. As a technology lover who’s always keen to try the latest and greatest, I don’t always remember to cancel subscriptions before the end of their respective free trial periods.

After half an hour of purging, I was able to remove $80/month worth of subscription services I don’t really use anymore! Most of the subscriptions I got rid of were related to servers, server management, and server monitoring.

What a surprise…

With $80/month of savings achieved, I dug further to see what else I could cut. I found a few more server monitoring services that I actually use for monitoring my block production node on the ICON network. Between UptimeRobot and NodePing, I was paying close to $30/month for monitoring.

I’ve been on a serverless function kick recently, so I decided to try writing a script to replace the core functionalities of UptimeRobot and NodePing. I ended up with the Python script below that makes two requests to the node with a 30 second gap in between, and messages me on Telegram if the node is offline. I’m going to add some more code over the next few days for error and timeout handling, but it works pretty well for now.

import json
import requests
import time
from multiprocessing import Process

def node_check(t):
	time.sleep(t)
	node_url = "http://...:9000/api/v1/avail/peer"
	r = requests.get(node_url)
	json_data = json.loads(r.text)
	is_service_online = json_data['status']
	is_service_available = json_data['service_available']
	if is_service_available == False or "is online" not in is_service_online:
		send_tg_message()

def send_tg_message():
	tg_bot_url = f"https://api.telegram.org/bot.../"
	chat_id = "..."
	response_message_data = {
        "chat_id": chat_id,
        "text": "RHIZOME P-Rep node (...) is offline.",
    }
	requests.post(f'{tg_bot_url}sendMessage', json=response_message_data)

def main(request):
	p = Process(target=node_check(0))
	p.start()
	p2 = Process(target=node_check(30))
	p2.start()
	p.join()
	p2.join()

I deployed the script to Google Cloud Function, and scheduled it to run once per minute with Google Cloud Scheduler. While this solution obviously doesn’t cover all the features of paid monitoring services, it’s definitely good enough for my needs – and it’s completely free.

Google Cloud Platform’s free tier allows for 2 million Cloud Function invocations and three Cloud Scheduler jobs per month. This monitoring system will cost me ~45,000 function invocations per month with a single cron job, so I’m well within the free tier. Yay for saving money!