Monitor diskspace with cURL

Monitor disk space with cURL and send alerts to Operational when free storage falls below threshold.

What is disk space monitoring with cURL

Monitoring disk space helps ensure your servers do not run out of storage and keep applications running smoothly.

Using cURL to send alerts lets you automate notifications when space is low.

How Operational helps with disk space monitoring

Operational provides a simple API to ingest events from any tool or script. You can send disk space alerts directly to your operational dashboard.

Setting up Operational

  1. Go to app.operational.co and sign up for a free account.
  2. Create a new project or select an existing one.
  3. In your project settings, find your API key.
  4. Copy the API key for use in your scripts.

Example: Sending disk space alerts with cURL

curl -X POST https://events.operational.co/v1/ingest -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" --data '{
  "name": "Low disk space",
  "avatar": "💽",
  "content": "Disk space is below threshold on server1: only 5% remaining"
}'

This command sends a low disk space alert to Operational when storage runs low.

If you prefer an entire bash script:

#!/bin/bash

# Set your API key here
API_KEY="YOUR_API_KEY"

# Path to check
CHECK_PATH="/var/www"

# Threshold percentage
THRESHOLD=10

# Get available disk space as a percentage (removes the % sign)
USAGE=$(df -h "$CHECK_PATH" | awk 'NR==2 {print $5}' | sed 's/%//')

# If usage is 90% or more, disk space is less than 10%
if [ "$USAGE" -ge $((100 - THRESHOLD)) ]; then
  curl -X POST https://events.operational.co/v1/ingest \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    --data "{
      \"name\": \"Low disk space\",
      \"avatar\": \"💽\",
      \"notify\": \"true\",
      \"content\": \"Disk space is below threshold on $(hostname): only $((100 - USAGE))% remaining\"
    }"
fi

Going further, you can also set a crontab that runs this script every day.

Conclusion

Monitoring disk space with cURL and Operational saves time and prevents outages. Operational handles your alerts in one dashboard and sends push notifications to your device.

Learn more on https://operational.co Try ready-to-paste cURL code snippets inside the Playground: https://operational.co/playground