How to Get Notified When Your Site Goes Down using Geekflare API

The High Cost of Downtime

Your website crashing can devastate business revenue and reputation. Over 90% of companies cannot sustain normal operations with an extended outage. It also erodes customer loyalty – 67% will switch companies after just one bad experience.

Cyber threats, software failures and human errors trigger over 50% of downtime incidents. Without quick detection, losses rapidly compound from missed sales, penalties, and diagnostic costs reaching an average of $300,000 per hour.

Clearly, getting immediate alerts allows you to respond quickly to minimize disruption. This is where Geekflare‘s "Is Website Up" API delivers immense value…

Geekflare API Monitors Site Availability 24/7

Geekflare offers a robust suite of solutions engineered for developer productivity. Their Is Website Up API checks the live availability of any site URL by pinging it from dozens of global locations.

It returns fast and reliable status codes like:

{
  "message": "Site is up and reachable from London"  
}

or

{
   "message": "Site is down"
}

Allowing you to programmatically monitor uptime. Even better, by integrating notifications you get alerted the moment performance degrades.

Let‘s walk through how to setup automatic email alerts…

Step 1 – Get Your Geekflare API Key

First, create a free Geekflare account which provides access to their API dashboard.

Here you‘ll find your personal API key required for making authenticated API calls. Think of it like a password or token.

Save this key in your code or environment variables for usage later.

Pro Tip: Restrict the API key scope and enable 2FA for production use to prevent abuse

Step 2 – Check Site Status with the API

With key ready, we can now look at the Is Website Up docs to understand parameters and sample code snippets.

Let‘s try out the Python example:

import requests
import os

API_KEY = os.getenv("GEEKFLARE_API_KEY") 

api_url = "https://api.marketingscoop.com/up"
site_url = "https://www.example.com"

headers = {‘x-api-key‘: API_KEY}
data = {‘url‘: site_url}

response = requests.post(api_url, headers=headers, json=data)
status = response.json()["message"]
print(status)

When executed it pings the defined URL printing availability. We get programmatic access to monitor any site dynamically.

Now let‘s expand this to notify you…

Step 3 – Trigger Email Alerts on Failures

The Is Website Up API returns clear status messages allowing simple notifications:

if status == "Site is down":
  send_alert_email()

We need to define the send_alert_email() function using an SMTP library like yagmail:

import yagmail

def send_alert_email():
  contents = f"Your site {site_url} is DOWN!"

  yag = yagmail.SMTP(my_email) 
  yag.send(to=my_email, subject="Site Outage Detected", contents=contents)

  print("Alert email sent!")

Bringing this together:

# Import dependencies 

response = api_call()
status = get_status(response)

if status == "Site is down":
  send_alert_email() 

Now instant notifications are triggered during incidents!

For this to be truly effective, we should automate ongoing checks…

Step 4 – Schedule Automated Cron Jobs

Rather than manually invoking the script, we can use Cron to execute on a fixed recurring schedule like every 5 minutes.

  1. Open crontab editor with crontab -e
  2. Add job */5 * * * * python /path/to/script.py
  3. Save the file to activate monitoring

This runs every 5 mins automatically in the background detecting and alerting you of any downtime instantly!

Real-Time Monitoring Dashboard with Grafana

While email works, incorporating API response data into visual dashboards takes uptime visibility to the next level.

Grafana lets you build beautiful graphs, charts, and alerts focused on observability.

Luckily there is existing Geekflare API integration support. Just install the plugin, add your API key, configure the site URL as a variable and you can instantly chart performance metrics over time!

See code and screenshots »

Now not only can you get notifications, but also visually track availability history identifying patterns and improvements.

This reveals bigger picture reliability insights beyond the pass/fail alerts. Other options like Datadog, Kibana and New Relic provide similar capabilities.

Proactively Improve Resilience

While fast incident response is great, proactive preparedness beats reactive scrambling when problems ultimately strike:

🔻 Redundancy across regions, clouds, and networks improves tolerance if one area sees disruption. Route 53 or load balancers enable automatic failover achieving high availability.

🔻 Monitoring gives visibility detecting degrading performance before it becomes an outage through metrics like latency budgets and system resources.

🔻 Testing with gamedays or chaos engineering reveals weakness ahead of real-world events allowing them to be addressed.

🔻 Automated Remediations instantly roll back changes, replenish capacity, restart components etc saving precious minutes.

Blending intelligent policy, rigorous testing and automation handles many failure scenarios before customers are ever impacted.

Key Takeaways

We covered how Geekflare‘s Is Website Up API provides invaluable monitoring of site availability from across the globe.

By integrating notifications, you get alerted immediately during downtime to minimize disruption. Automation reduces overhead while giving comprehensive historical tracking.

Hopefully this gives you high confidence to implement robust checks guarding against the costly damage website crashes inflict on business.

What other methods have you found useful for staying ahead of outages before they interrupt customers? I welcome any feedback or questions in the comments below!