Real-World Examples
Example 1: Cron Job Monitoring
Scenario: You have a daily backup script that runs at 2 AM and should complete within 30 minutes.
Setup:
- Interval: 1440 minutes (24 hours)
- Grace Period: 30 minutes
- Expected check-in: Around 2:30 AM daily
Implementation:
#!/bin/bash
# backup_script.sh
rsync -av /data/ /backup/
if [ $? -eq 0 ]; then
curl -X POST "https://silentcanary.com/checkin/YOUR_TOKEN" \
-d "message=Backup completed successfully - $(du -sh /backup/ | cut -f1) backed up"
else
# Backup failed - don't check in, let SilentCanary alert
echo "Backup failed"
exit 1
fi
Example 2: Web Service Health Check
Scenario: Monitor a critical web service that should be checked every 5 minutes.
Setup:
- Interval: 5 minutes
- Grace Period: 2 minutes
- Smart Alerts: Enabled with high sensitivity
Implementation (Python):
import requests
import time
import json
def health_check():
try:
# Check your service
response = requests.get('https://your-service.com/health', timeout=10)
if response.status_code == 200:
# Service is healthy, check in with status
check_in_data = {
"message": f"Service healthy - Response time: {response.elapsed.total_seconds():.2f}s"
}
requests.post('https://silentcanary.com/checkin/YOUR_TOKEN',
json=check_in_data)
else:
# Service returned error - don't check in
print(f"Service unhealthy: {response.status_code}")
except Exception as e:
print(f"Health check failed: {e}")
# Run every 5 minutes
while True:
health_check()
time.sleep(300) # 5 minutes
Example 3: Database Maintenance Task
Scenario: Weekly database cleanup that runs every Sunday at 3 AM.
Setup:
- Interval: 10080 minutes (7 days)
- Grace Period: 60 minutes
- Alert Type: Email + Slack
Implementation (SQL + curl):
-- db_cleanup.sql
DELETE FROM logs WHERE created_at < DATE_SUB(NOW(), INTERVAL 90 DAY);
DELETE FROM temp_files WHERE created_at < DATE_SUB(NOW(), INTERVAL 7 DAY);
OPTIMIZE TABLE logs, temp_files;
-- Shell script
#!/bin/bash
ROWS_DELETED=$(mysql -u user -p database < db_cleanup.sql 2>&1 | grep -o '[0-9]* rows affected' | head -1)
curl -X POST "https://silentcanary.com/checkin/YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"message\": \"DB cleanup completed - $ROWS_DELETED\"}"
Example 4: IoT Device Monitoring
Scenario: Monitor IoT sensors that should report data every 10 minutes.
Setup:
- Interval: 10 minutes
- Grace Period: 5 minutes
- Smart Alerts: Enabled to detect irregular patterns
Implementation (Arduino/ESP32):
#include <WiFi.h>
#include <HTTPClient.h>
void sendSensorData() {
float temperature = readTemperature();
float humidity = readHumidity();
HTTPClient http;
http.begin("https://silentcanary.com/checkin/YOUR_TOKEN");
http.addHeader("Content-Type", "application/json");
String message = "Temp: " + String(temperature) + "°C, Humidity: " + String(humidity) + "%";
String payload = "{\"message\":\"" + message + "\"}";
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
Serial.println("Check-in successful");
} else {
Serial.println("Check-in failed");
}
http.end();
}
void loop() {
sendSensorData();
delay(600000); // 10 minutes
}
Example 5: API Integration Patterns
Different ways to send messages:
1. Simple GET request with message:
curl "https://silentcanary.com/checkin/YOUR_TOKEN?message=Task completed successfully"
2. POST with form data:
curl -X POST https://silentcanary.com/checkin/YOUR_TOKEN \
-d "message=Processed 1,234 records in 5.2 seconds"
3. POST with JSON:
curl -X POST https://silentcanary.com/checkin/YOUR_TOKEN \
-H "Content-Type: application/json" \
-d '{"message": "System status: All services operational"}'
4. From JavaScript/Node.js:
fetch('https://silentcanary.com/checkin/YOUR_TOKEN', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: `Processed ${recordCount} records, ${errorCount} errors`
})
});
Pro Tips:
- Include meaningful information in your messages (processing time, record counts, error status)
- Use Smart Alerts for processes with variable timing
- Set appropriate grace periods based on normal execution time variance
- Consider using different canaries for different criticality levels