Yes, the metrics and monitors that Mackerel manages can be downloaded using the API or CLI tool.
- Downloading in CSV format from the web console is not supported.
- Both the API and CLI tool are output in JSON format.
- See the document linked below for how to install and use the CLI tool.
Here are some useful links and command samples on how to retrieve metrics and monitors.
- How to retrieve metrics with the API
- How to retrieve metrics with the CLI tool (mkr)
- How to retrieve monitors with the API
- How to retrieve monitors with the CLI tool (mkr)
How to retrieve metrics with the API
- See the API documents linked below for details regarding the Get Metrics API.
- Refer to the document below to view the names of system metrics posted by mackerel-agent.
- For the names of custom metrics for plugins, refer to the host details screen or graph definition screen. (See the "Defining Graph Schema" section for graph definitions)
- Below is an example of how to retrieve the metric loadavg1 with the curl command.
$ curl \ -s https://api.mackerelio.com/api/v0/hosts//metrics?name=loadavg1&from=&to= \ -H 'Content-Type: application/json' \ -H 'X-Api-Key: ' \ -X GET {"metrics":[{"time":1617163080,"value":0.27},{"time":1617163140,"value":0.13}, ...]}
How to retrieve metrics with the CLI tool (mkr)
- Metrics can be retrieved with mkr metrics or mkr fetch.
- Below is an example of how to retrieve the metric loadavg1 with the mkr metrics command.
$ mkr metrics --host <HostID> --name loadavg1 --from <unixtime> --to <unixtime> [ { "time": 1617163080, "value": 0.27 }, : ]
How to retrieve monitors with the API
- See the API documents linked below for details regarding the Get Monitor Configurations API.
- To retrieve a particular monitor configuration using the Get Monitor Configurations API, specify one of the following values for monitorId.
- The id of the respective monitoring rule included in the API response.
- The "monitor= xxxxxxx" value located in the URL when accessing the monitor’s details screen from the Web console.
- For check monitoring, you can view the monitorId set for each host using the List Monitoring Statuses API.
- Below is an example of how to retrieve a monitor with the curl command.
$ curl \ -s https://api.mackerelio.com/api/v0/monitors/<monitorId> \ -H 'Content-Type: application/json' \ -H 'X-Api-Key: <API Key>' \ -X GET {"monitor":{"duration":1,"maxCheckAttempts":3,"critical":95,"isMute":false,"metric":"cpu%","excludeScopes":[],"name":"CPU %","warning":80,"id":"xxxxxxxx","scopes":[],"type":"host","operator":">"}}
How to retrieve monitors with the CLI tool (mkr)
- Monitors can be retrieved with mkr monitors pull.
- This only applies to monitors configured from the Web Console.
- The monitors.json file is created in the directory where the command was executed.
- Check monitoring requires direct management of mackerel-agent.conf.
- In addition to pull, mkr monitors also supports diff and push.
- Below is an example of how to retrieve a monitor with mkr command.
$ mkr monitors pull info Monitor rules are saved to 'monitors.json' (6 rules).