How to send a metric from a shell script with curl
curl is all you need, which makes this the quickest way to watch cron jobs, backups and deploy scripts. Using -G with --data-urlencode builds the query string safely.
Before you start
Create a metric in Umlogger and copy its ingest key (pmk_…) from the metric's page. Choose count for things that happen, or value for measurements (which one?). The examples read the key from an environment variable.
Count an event
For example, at the end of a backup script. Each request adds 1.
curl -fsS --max-time 5 -G "https://data.umlogger.com/api/m" \ --data-urlencode "key=$UMLOGGER_BACKUPS_KEY" \ --data-urlencode "value=1"
Record a value
Send a measurement to a value metric, such as how full the disk is. This works on Linux and macOS.
USED=$(df -P / | awk 'NR==2 {print $5+0}')
curl -fsS --max-time 5 -G "https://data.umlogger.com/api/m" \
--data-urlencode "key=$UMLOGGER_DISK_KEY" \
--data-urlencode "value=$USED"Record how long a job took
Time the job and send the seconds.
START=$(date +%s) /opt/scripts/nightly-import.sh curl -fsS --max-time 5 -G "https://data.umlogger.com/api/m" \ --data-urlencode "key=$UMLOGGER_IMPORT_TIME_KEY" \ --data-urlencode "value=$(( $(date +%s) - START ))"
Backfill old data
Add a timestamp with a time zone (ISO 8601).
curl -fsS --max-time 5 -G "https://data.umlogger.com/api/m" \ --data-urlencode "key=$UMLOGGER_BACKUPS_KEY" \ --data-urlencode "value=1" \ --data-urlencode "timestamp=2026-11-30T03:00:00Z"
Tips
- In a script with set -e, add || true after curl so a failed metric doesn’t stop the script.
- Then add a “no data” alert on the metric to hear when the job stops running.
- Want to hear when the numbers stop arriving? Add an alert.
Questions
Which key do I use?
Use the metric's own ingest key (pmk_…), shown on the metric's page in Umlogger. It can only add samples to that one metric. Keep it in an environment variable or a secret store rather than in your code. If it leaks, replace it from the metric's page; the old key stops working immediately and your data stays.
How many samples can I send?
Up to 120 requests per minute per key. For busier events, add them up and send the total: a count metric adds up its samples, so one request with value=25 counts as 25 events.
Should my metric be a count or a value?
Use a count for things that happen (signups, orders, errors): Umlogger adds the samples up per hour or day. Use a value for measurements (response time, queue length, MRR): Umlogger averages them.
Other languages
Python · Node.js · Go · PHP · GitHub Actions · Full API reference