|
| 1 | +--- |
| 2 | +title: "Disk IO - cgroup - container" |
| 3 | +description: "Documentation for DiskIoCgroupContainerProvider of the Green Metrics Tool" |
| 4 | +date: 2025-07-07T15:52:00+00:00 |
| 5 | +weight: 205 |
| 6 | +--- |
| 7 | + |
| 8 | +### What it does |
| 9 | + |
| 10 | +It reads the total amount of read and written bytes from disk devices by the cgroup of the container. More information about cgroups can be found [here](https://www.man7.org/linux/man-pages/man7/cgroups.7.html). |
| 11 | + |
| 12 | +### Classname |
| 13 | + |
| 14 | +- `DiskIoCgroupContainerProvider` |
| 15 | + |
| 16 | +### Metric Name |
| 17 | + |
| 18 | +- `disk_io_cgroup_container` |
| 19 | + |
| 20 | +### Input Parameters |
| 21 | + |
| 22 | +- args |
| 23 | + - `-s`: container-ids separated by commas |
| 24 | + - `-i`: interval in milliseconds (optional, default: 1000 ms) |
| 25 | + |
| 26 | +Example measuring two containers with an interval of 100 ms: |
| 27 | + |
| 28 | +```bash |
| 29 | +./metric-provider-binary -i 100 -s 7f38a4c25fb8f9d5f8651d6ed986b3658dba20d1f5fec98a1f71c141c2b48f4b,c3592e1385d63f9c7810470b12aa00f7d6f7c0e2b9981ac2bdb4371126a0660a |
| 30 | +``` |
| 31 | + |
| 32 | +### Output |
| 33 | + |
| 34 | +This metric provider prints to Stdout a continuous stream of data. The format of the data is as follows: |
| 35 | + |
| 36 | +`TIMESTAMP RBYTES WBYTES CONTAINER-ID` |
| 37 | + |
| 38 | +Where: |
| 39 | + |
| 40 | +- `TIMESTAMP`: Unix timestamp, in microseconds |
| 41 | +- `RBYTES`: The cumulative amount of bytes read from disk since container start |
| 42 | +- `WBYTES`: The cumulative amount of bytes written to disk since container start |
| 43 | +- `CONTAINER-ID`: The container ID that this reading is for |
| 44 | + |
| 45 | +Any errors are printed to Stderr. |
| 46 | + |
| 47 | +### How it works |
| 48 | + |
| 49 | +The provider assumes that you have [cgroups v2](https://www.man7.org/linux/man-pages/man7/cgroups.7.html) enabled on your system. |
| 50 | + |
| 51 | +It reads from the cgroup's `io.stat` file which provides per-device I/O statistics for the container. |
| 52 | + |
| 53 | +The provider: |
| 54 | + |
| 55 | +- parses the `io.stat` file to extract `rbytes` and `wbytes` values |
| 56 | +- filters out virtual devices that don't represent actual disk I/O: |
| 57 | + - Memory devices (major 1) |
| 58 | + - Floppy disk controllers (major 2) |
| 59 | + - Loopback devices (major 7) |
| 60 | + - SCSI CD-ROM (major 11) |
| 61 | + - ALSA sound devices (major 116) |
| 62 | + - Xen virtual block devices (major 202) |
| 63 | +- only counts whole disk devices (minor number divisible by 16) |
| 64 | +- sums up the read and write bytes across all real disk devices |
| 65 | + |
| 66 | +#### Device filtering |
| 67 | + |
| 68 | +The provider filters out virtual and non-disk devices to focus on actual disk I/O operations that consume energy. It checks the major device numbers against a list of known virtual devices and excludes them from the calculations. |
| 69 | + |
| 70 | +If partition devices are encountered (minor number not divisible by 16), the provider will exit with an error as this should not happen in a properly configured container environment. |
| 71 | + |
| 72 | +#### Attribution of disk I/O |
| 73 | + |
| 74 | +The disk I/O is attributed directly to each container based on the cgroup accounting. This provides accurate per-container disk usage without double-counting or attribution issues. |
| 75 | + |
| 76 | +Since containers share the same underlying disk devices, the measurements represent the actual bytes read from and written to the physical storage by each container's processes. |
0 commit comments