|
| 1 | +--- |
| 2 | +title: "Network IO - procfs - container" |
| 3 | +description: "Documentation for NetworkIoProcfsContainerProvider of the Green Metrics Tool" |
| 4 | +lead: "" |
| 5 | +date: 2023-08-04T08:49:15+00:00 |
| 6 | +weight: 205 |
| 7 | +--- |
| 8 | + |
| 9 | +### What it does |
| 10 | + |
| 11 | +It reads the total amount of sent and received bytes from the network interfaces |
| 12 | +of a container by entering the container's network namespace and |
| 13 | +reading the information from `/proc/net/dev`. |
| 14 | + |
| 15 | +### Classname |
| 16 | + |
| 17 | +- `NetworkIoProcfsContainerProvider` |
| 18 | + |
| 19 | +### Metric Name |
| 20 | + |
| 21 | +- `network_io_procfs_container` |
| 22 | + |
| 23 | +### Input Parameters |
| 24 | + |
| 25 | +- args |
| 26 | + - `-s`: container-ids seperated by commas |
| 27 | + - `-i`: interval in milliseconds |
| 28 | + |
| 29 | +By default the measurement interval is 100 ms. |
| 30 | + |
| 31 | +```bash |
| 32 | +./metric-provider-binary -i 100 -s 7f38a4c25fb8f9d5f8651d6ed986b3658dba20d1f5fec98a1f71c141c2b48f4b,c3592e1385d63f9c7810470b12aa00f7d6f7c0e2b9981ac2bdb4371126a0660a |
| 33 | +``` |
| 34 | + |
| 35 | +### Output |
| 36 | + |
| 37 | +This metric provider prints to Stdout a continuous stream of data. The format of |
| 38 | +the data is as follows: |
| 39 | + |
| 40 | +`TIMESTAMP READING CONTAINER-ID` |
| 41 | + |
| 42 | +Where: |
| 43 | +- `TIMESTAMP`: Unix timestamp, in microseconds |
| 44 | +- `READING`: The amount of bytes sent and received during the time interval |
| 45 | +- `CONTAINER-ID`: The container ID that this reading is for |
| 46 | + |
| 47 | +Any errors are printed to Stderr. |
| 48 | + |
| 49 | +### How it works |
| 50 | + |
| 51 | +The provider enters the network namespace of each specified container via the |
| 52 | +`setns` system call on the file `/proc/<PROCESS-ID>/ns/net`. |
| 53 | +After entering the namespace the provider reads from `/proc/net/dev` and: |
| 54 | +- parses the output |
| 55 | +- skips all `lo` interfaces |
| 56 | +- sums up the `r_bytes` and `t_bytes` of all other interfaces |
| 57 | +- does NOT count dropped packets (we assume since most of the traffic is internal, |
| 58 | + that a dropped received packet shows up in another interface as sent anyway and |
| 59 | + a dropped sent packet does not attribute much to the energy consumption). |
| 60 | + |
| 61 | +#### Attribution of network traffic |
| 62 | + |
| 63 | +Currently all incoming and outgoing traffic is attributed to every container that |
| 64 | +sends or receives it. |
| 65 | + |
| 66 | +This may lead to unexpected results when you process the results, but is a design |
| 67 | +decision. |
| 68 | + |
| 69 | +In our [Green Metrics Dashboard](https://metrics.green-coding.io) we simply |
| 70 | +accumulate all the network traffic of all containers and then |
| 71 | +apply the [CO2-Formula](https://www.green-coding.io/co2-formulas) on top. |
| 72 | + |
| 73 | +This however assumes that all traffic is with external services. If your |
| 74 | +containers are however only |
| 75 | +communicating with each other and are in production all on one machine, this |
| 76 | +number will not |
| 77 | +represent the real CO2 emissions, but is rather greatly overstating them. |
| 78 | + |
| 79 | +This design decision was made because we cannot know during benchmarking how your |
| 80 | +containers |
| 81 | +would be orchestrated in production. |
| 82 | +They can very well be all on one machine (which would have zero network emissions), |
| 83 | +but they also could be distributed in an internal network |
| 84 | +of a datacenter (which would have only marginal network CO2 emissions) or really |
| 85 | + distributed globally (which would then have the maximum of CO2 emissions). |
| 86 | + |
| 87 | +Since our reporters should give you an optimization baseline we opted for the |
| 88 | +worst-case scenario to report in our Dashboard. |
| 89 | + |
| 90 | +When processing the metrics you own you may well use a different approach given |
| 91 | +your knowledge of the network topology. |
0 commit comments