Get started with Monitoring
Publish a custom metric, put an alarm on it, check a URL from outside, read the result, and delete what you made, in about ten minutes.
Replace https://example.com/ with a URL of your own, and alarm-id and check-id with the ids the create steps return. Nothing here touches a machine.
Prerequisites
- Permission for
monitoring:PutMetricData,monitoring:PutMetricAlarm,monitoring:CreateCheck,monitoring:GetCheckResults,monitoring:DeleteAlarmsandmonitoring:DeleteChecks. - In the console, also
monitoring:DescribeAlarmsto open Alarms andmonitoring:DescribeChecksto open Uptime and the check's page; without them the list pages show an access-denied notice and the check's page is not found. - For the CLI steps, the dcloud CLI, signed in. For the API steps, an access key.
Step 1: Publish a datapoint
A custom series exists from its first datapoint on. The points you keep are metered storage.
Not available in Console. The console charts custom metrics but does not publish them.
dcloud monitoring custom-metrics put --namespace Shop \
--metric-data '{"metricName":"orders_placed","value":1}'POST /monitoring/api/custom-metrics
{ "namespace": "Shop", "metricData": [{ "metricName": "orders_placed", "value": 1 }] }The answer is { "success": true, "data": { "accepted": 1, "rejected": [] } }. Under Monitoring, Custom metrics, the
namespace Shop now lists the series orders_placed.
Step 2: Alarm on the series
The alarm fires when fewer than one order is placed in a five-minute period.
Not available in Console. The console creates alarms on machines and other resources only, not on custom series.
dcloud monitoring alarms create --name "No orders" --resource-type custom \
--resource-id Shop --metric orders_placed --statistic sum --comparator "<" \
--threshold 1 --period-seconds 300POST /monitoring/api/alarms
{ "name": "No orders", "resourceType": "custom", "resourceId": "Shop", "metric": "orders_placed",
"statistic": "sum", "comparator": "<", "threshold": 1, "periodSeconds": 300 }The answer is 201 with the alarm in INSUFFICIENT_DATA. It is evaluated every minute; read its
state and the reason with dcloud monitoring alarms get alarm-id. While the evaluated
period has no datapoint it stays INSUFFICIENT_DATA: a missing datapoint never counts as fewer
than one (see How alarms work).
Step 3: Check a URL
- Open Monitoring, then Uptime, and choose Create check.
- For Name, enter Example.
- For URL, enter https://example.com/.
- Choose Create check.
The check appears in the list in the pending state.
dcloud monitoring checks create --name Example --url https://example.com/POST /monitoring/api/checks
{ "name": "Example", "url": "https://example.com/" }The check runs within a minute, then every five minutes. If the answer is 409 with "… is already
checked … times a minute by …", other checks already request that host as often as the platform
allows; use a URL of your own.
Step 4: Read the result
- In Uptime, choose the check's row.
- The page shows the state and why, and under Response time the share of runs that succeeded and the response times. Latest results lists each run from each location.
dcloud monitoring checks results check-idGET /monitoring/api/checks/check-id/resultsAfter its first run the check is up, regional or still pending; it becomes down only after
two failed runs in a row (see How uptime checks work).
Clean up
Delete the alarm and the check. The custom series cannot be deleted: with no new datapoints, its minute points are removed after 15 days and the series after 15 months.
- In Alarms, open the action menu of the alarm No orders, choose Delete alarm, then Delete.
- In Uptime, open the action menu of the check, choose Delete check, then Delete.
dcloud monitoring alarms delete alarm-id
dcloud monitoring checks delete check-idDELETE /monitoring/api/alarms/alarm-idDELETE /monitoring/api/checks/check-idNext steps
- Create an alarm on a machine
- Publish custom metrics
- Create a status page