Skip to content

Instantly share code, notes, and snippets.

@timosalm
Last active June 25, 2020 11:11
Show Gist options
  • Save timosalm/2bdf5e7ea137749350e0920f8aadf744 to your computer and use it in GitHub Desktop.
Save timosalm/2bdf5e7ea137749350e0920f8aadf744 to your computer and use it in GitHub Desktop.
Querying Metric Store for PCF via Prometheus-Compatible HTTP Endpoints
#!/usr/bin/env bash
export METRIC_DATA_URL=https://metric-store.run.pivotal.io
export APP_GUID=d554cc6d-2f8c-4950-bb97-3cf8805c9b44
export START_TIME=1592995680
export END_TIME=1593082080
echo -e "Issue a PromQL range query against Metric Store data:\n"
curl -G "${METRIC_DATA_URL}/api/v1/query_range" \
--data-urlencode "query=avg_over_time(cpu{source_id='${APP_GUID}'}[1m])" \
--data-urlencode "start=${START_TIME}" --data-urlencode "end=${END_TIME}" \
--data-urlencode "step=60s" \
-H "Authorization: $(cf oauth-token)"
echo -e "\n-------------------------------------------\n"
echo -e "Retrieve all label names for authorized source ids from the store:\n"
# Note: Non-admins (`doppler.firehose` or `logs.admin`) are not permitted to use this query.
curl -G "${METRIC_DATA_URL}/api/v1/labels" \
-H "Authorization: $(cf oauth-token)"
echo -e "\n-------------------------------------------\n"
echo -e "Issue a PromQL series query against Metric Store data:\n"
# Note: Non-admins (`doppler.firehose` or `logs.admin`) are not permitted to use this query.
curl -G "${METRIC_DATA_URL}/api/v1/series" \
--data-urlencode 'match[]=egress' \
--data-urlencode "start=${START_TIME}" --data-urlencode "end=${END_TIME}" \
-H "Authorization: $(cf oauth-token)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment