This topic describes how to configure event and metric monitors for your applications using PCF Metrics’ Beta monitors-api
endpoint.
Note: You must have the appropriate permissions to view or manage application monitors in PCF Metrics.
You can use the following cURL and API commands to view event and metric monitors.
To view monitors using cURL, run the following command:
curl -H “Authorization: $(cf oauth-token)” -vvv -G “https://monitors-api.sys.DOMAIN/api/v1/$(cf app APP_NAME –guid)/monitors” | jq
Where:
DOMAIN
is your domain
APP_NAME
is the name of your app
To view monitors via API, run the following command:
GET https://monitors-api.sys.DOMAIN/api/v1/APP_GUID/monitors
Where:
DOMAIN
is your domain
APP_GUID
is the GUID of your app
You can use the following cURL and API commands to delete event and metric monitors.
To delete monitors using cURL, run the following command:
curl -H “Authorization: $(cf oauth-token)” -vvv -G “https://monitors-api.sys.DOMAIN/api/v1/$(cf app APP_NAME –guid)/monitors/MONITOR_GUID” -X DELETE
Where:
DOMAIN
is your domain
APP_NAME
is the name of your app
MONITOR_GUID
is the GUID of your app
To delete monitors via API, run the following command:
DELETE https://monitors-api.sys.DOMAIN/api/v1/APP_GUID/monitors/MONITOR_GUID
Where:
DOMAIN
is your domain
APP_GUID
is the GUID of your app
MONITOR_GUID
is the GUID of your app
You can use the following cURL and API commands to create event and metric monitors.
The following attributes are optional and can be omitted from your commands if not needed:
warning_threshold
critical_webhook_url
critical_json_payload
warning_webhook_url
warning_json_payload
To create monitors using cURL, run the following command:
curl -H “Authorization: $(cf oauth-token)” “https://monitors-api.sys.DOMAIN/api/v1/$(cf app APP_NAME –guid)/monitors” -d ‘{ “metric_name”: “cf.system.latency”,“metric_type”: “gauge”,“metric_unit”: “milliseconds”,“name”: “monitor_name”,“snooze_time_in_minutes”: 1,“threshold_comparator”: “<=”,“critical_threshold”: 100.0,“warning_threshold”: 70.0,“critical_webhook_url”: “critical_webhook_url”,“critical_json_payload”: “critical_json_payload”,“warning_webhook_url”: “warning_webhook_url”,“warning_json_payload”: “warning_json_payload” }’
Where:
DOMAIN
is your domain
APP_NAME
is the name of your app
To create monitors via API, run the following command:
POST https://monitors-api.sys.DOMAIN/api/v1/APP_GUID/monitors
Where:
DOMAIN
is your domain
APP_GUID
is the GUID of your app
And BODY:
{ “name”: “Lathrop CPU”, “metric_name”: “cf.system.cpu”, “metric_type”: “gauge”, “metric_unit”: “percentage”, “snooze_time_in_minutes”: 15, “threshold_comparator”: “>=”, “critical_threshold”: 10, “warning_threshold”: 5, “critical_webhook_url”: "", “critical_json_payload”: "", “warning_webhook_url”: "", “warning_json_payload”: "" }
You can use the following cURL and API commands to view triggered event and metric monitors.
To view triggered monitors using cURL, run the following command:
curl -H “Authorization: $(cf oauth-token)” -vvv -G “https://monitors-api.sys.DOMAIN/api/v1/$(cf app APP_NAME –guid)/triggered_monitors” | jq
Where:
DOMAIN
is your domain
APP_NAME
is the name of your app
To view triggered monitors via API, run the following command:
GET https://monitors-api.sys.DOMAIN/api/v1/APP_GUID/triggered_monitors
Where:
DOMAIN
is your domain
APP_GUID
is the GUID of your app
In addition to configuring monitors directly via API, you can also automate monitors configuration via YAML file.
To automate monitor configuration via YAML file, create a YAML file using the YAML File Format Examples below, then run the following command:
curl -H “Authorization: $(cf oauth-token)” -H “Content-Type: application/yaml” –data-binary “@/PATH-TO-FILE.yml” -k “https://monitors-api.sys.DOMAIN/api/v1/$(cf app APP_NAME –guid)/monitors” -vvv -X PUT
Where:
DOMAIN
is your domain
APP_NAME
is the name of your app
The examples below show the correct format for automating monitor configuration via YAML file.
The following attributes are optional and can be omitted from your YAML file if not needed:
warning_threshold
critical_webhook_url
critical_json_payload
warning_webhook_url
warning_json_payload
The following is an example YAML file for configuring a metric monitor.
The following is an example YAML file for configuring an event monitor.
The following is an example YAML file for configuring multiple monitors.