Accessing metrics through code
There are situations where you’d want to access metrics about a deployment programmatically. For example, you might want to have a continuous integration script that checks the health of a deployment.
To access the metrics through code:
Ask Improbable customer support via the helpdesk (for customers with a service agreement) or the forums to set up a metrics service account for you. They’ll send you a username and password to use with HTTP basic authentication.
Craft a Prometheus query. To do this:
- Look at what metrics are available.
- Look at the Prometheus query examples and syntax.
Run your query in code. Exactly how this looks will depend on your environment, but to get you started, see this example which uses curl below.
project="your_project"
deployment="your_deployment"
refresh_token="your_refresh_token"
query="spatialos_worker_connected::sum{project=\"$project\", dpl=\"$deployment\", worker_type=\"MyCSharpWorker\"}"
curl -G "https://monitoring.service.improbable.io/@proxyhost/metrics.monitoring.spatial.improbable.io/api/v1/query" \
--user "longshot_user:$refresh_token" \
--data-urlencode "query=$query"