| Project | LXD |
| Status | Implemented |
| Author(s) | @monstermunchkin |
| Approver(s) | @stgraber @elmo |
| Release | 4.19 |
| Internal ID | LX007 |
Abstract
Add a built-in metric exporter which provides metrics from instances.
Rationale
Currently, stats/metrics are only provided by the /1.0/instances/<instance>/state endpoint. Monitoring software however cannot easily deal with this kind of output. Adding a built-in metric exporter will provide metrics for all instances. Furthermore, users who wish to visualize these metrics can easily do so by using grafana for example.
Specification
Design
Metrics will be available at /1.0/metrics which is where Prometheus for example scrapes the data from. The new endpoint will be accessible by anyone trusted by LXD. Additionally, a metrics type certificate would only allow access to /1.0 and /1.0/metrics. The metrics list would also support filtering by project should the client certificate be project-restricted.
LXD wil gather metrics every time the /1.0/metrics endpoint is called. For VMs, the request will be forwarded to the lxd-agent which will return the metrics. The metrics will show all running instances, and will be distinguishable through the project, name, and type tags. Furthermore, they will be prefixed with lxd_. An example:
lxd_memory_Active_bytes{project="default",name="c1",type="container"} 1024
lxd_memory_Active_bytes{project="foo",name="c1",type="virtual-machine"} 2048
Here’s the list of supported metric names:
lxd_cpu_seconds_total{cpu="<cpu>", mode="<mode>"}lxd_disk_read_bytes_total{device="<dev>"}lxd_disk_reads_completed_total{device="<dev>"}lxd_disk_written_bytes_total{device="<dev>"}lxd_disk_writes_completed_total{device="<dev>"}lxd_filesystem_avail_bytes{device="<dev>",fstype="<type>"}lxd_filesystem_free_bytes{device="<dev>",fstype="<type>"}lxd_filesystem_size_bytes{device="<dev>",fstype="<type>"}lxd_memory_Active_anon_byteslxd_memory_Active_byteslxd_memory_Active_file_byteslxd_memory_Cached_byteslxd_memory_Dirty_byteslxd_memory_HugepagesFree_byteslxd_memory_HugepagesTotal_byteslxd_memory_Inactive_anon_byteslxd_memory_Inactive_byteslxd_memory_Inactive_file_byteslxd_memory_Mapped_byteslxd_memory_MemAvailable_byteslxd_memory_MemFree_byteslxd_memory_MemTotal_byteslxd_memory_RSS_byteslxd_memory_Shmem_byteslxd_memory_Swap_byteslxd_memory_Unevictable_byteslxd_memory_Writeback_byteslxd_network_receive_bytes_total{device="<dev>"}lxd_network_receive_drop_total{device="<dev>"}lxd_network_receive_errs_total{device="<dev>"}lxd_network_receive_packets_total{device="<dev>"}lxd_network_transmit_bytes_total{device="<dev>"}lxd_network_transmit_drop_total{device="<dev>"}lxd_network_transmit_errs_total{device="<dev>"}lxd_network_transmit_packets_total{device="<dev>"}lxd_procs_total
For filesystem metrics, if the filesystem type name is known it will be listed with fstype. Otherwise this tag will contain the hexadecimal value of the filesystem.
API changes
The following new endpoint will be added to LXD
- GET
/1.0/metrics
The lxd-agent will gain the following new endpoint
- GET
/1.0/metrics
It will gather metrics and report them back to LXD in JSON format.
CLI changes
No CLI changes.
Database changes
No database changes.
Upgrade handling
No upgrade handling.
Further information
The provided metrics will honor OpenMetrics (https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md).

