How to send a metric from GitHub Actions
Runners already have curl, so a metric is one step. Store the metric’s key as a repository secret (Settings → Secrets and variables → Actions) and pass it in through env.
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 successful deploys
Add this as the last step of your deploy job. A failed request shows a warning but doesn’t fail the job.
- name: Count deploy
env:
UMLOGGER_KEY: ${{ secrets.UMLOGGER_DEPLOYS_KEY }}
run: |
curl -fsS --max-time 10 -G "https://data.umlogger.com/api/m" \
--data-urlencode "key=$UMLOGGER_KEY" \
--data-urlencode "value=1" \
|| echo "::warning::Couldn't send the metric to Umlogger"Track build time
Save the start time in the first step, then send the seconds to a value metric at the end.
- name: Start timer
run: echo "BUILD_START=$(date +%s)" >> "$GITHUB_ENV"
# ... your build steps ...
- name: Record build time
env:
UMLOGGER_KEY: ${{ secrets.UMLOGGER_BUILD_TIME_KEY }}
run: |
curl -fsS --max-time 10 -G "https://data.umlogger.com/api/m" \
--data-urlencode "key=$UMLOGGER_KEY" \
--data-urlencode "value=$(( $(date +%s) - BUILD_START ))" \
|| echo "::warning::Couldn't send the metric to Umlogger"Record GitHub stars every day
A scheduled workflow can record any number once a day. This one sends the repository’s star count to a value metric.
name: Record stars
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
jobs:
stars:
runs-on: ubuntu-latest
steps:
- env:
GH_TOKEN: ${{ github.token }}
UMLOGGER_KEY: ${{ secrets.UMLOGGER_STARS_KEY }}
run: |
STARS=$(gh api "repos/$GITHUB_REPOSITORY" --jq .stargazers_count)
curl -fsS --max-time 10 -G "https://data.umlogger.com/api/m" \
--data-urlencode "key=$UMLOGGER_KEY" \
--data-urlencode "value=$STARS"Tips
- Pass secrets through env, as above, rather than writing ${{ secrets.… }} inside the command itself.
- GitHub may delay scheduled workflows by several minutes, so give a “no data” alert at least a few hours.
- 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 · Bash and curl · Full API reference