Skip to content

Commit

Permalink
Update README Samples
Browse files Browse the repository at this point in the history
  • Loading branch information
MCOfficer committed Apr 15, 2020
1 parent a574645 commit a4348d8
Showing 1 changed file with 86 additions and 50 deletions.
136 changes: 86 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A small tool to analyze RAM usage of large amounts of docker containers.

```
container-stats 0.1.0
container-stats 0.2.1
MCOfficer <[email protected]>
A small tool to analyze RAM usage of large amounts of docker containers.
Expand Down Expand Up @@ -39,69 +39,105 @@ $ cargo build [--release]
List all containers:
```
$ sudo ./container-stats
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| memory | pid | name | id |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| 4.4 GB | 149498 | /sample-container-1 | 2b13f54b6493cb396ae5122a343053a84a2af5aab1c79eb2f5a58b6a9bb234ca |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| 4.8 GB | 60271 | /some-slightly-longer-sample-container | 3dd1f8261c053f9ee5908033bd8798a60120e8e0423c74d83bd8dceda22bd157 |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| 3.5 GB | 28350 | /sample-container-2 | 245c06ad91274c40a7f4e0090d5f74112b74818a4d237b5485962f142e74ac1c |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| 3.9 GB | 73631 | /some-pretty-damn-long-sample-container-name | 61f2cb9dc16d047f42152dde98c00e5a9f9e2a8ba305adfbf38252af3586e07a |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
| 17.2 GB | 195327 | /sample-container-three | 1b05272735bf083e1b148169130f620505dbc2fcff3c4fc6f8f46e49a4efa676 |
+----------+--------+----------------------------------------------------------+------------------------------------------------------------------+
```

Same, but machine-readable:
```
$ sudo ./container-stats --json
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| memory | average_percent_cpu | name | id |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| 4.4 GB | 0.054178316 | /sample-container-1 | 2b13f54b6493cb396ae5122a343053a84a2af5aab1c79eb2f5a58b6a9bb234ca |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| 4.8 GB | 0.001549211 | /some-slightly-longer-sample-container | 3dd1f8261c053f9ee5908033bd8798a60120e8e0423c74d83bd8dceda22bd157 |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| 3.5 GB | 0.705093403 | /sample-container-2 | 245c06ad91274c40a7f4e0090d5f74112b74818a4d237b5485962f142e74ac1c |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| 3.9 GB | 3.454540209 | /some-pretty-damn-long-sample-container-name | 61f2cb9dc16d047f42152dde98c00e5a9f9e2a8ba305adfbf38252af3586e07a |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
| 17.2 GB | 1.430940032 | /sample-container-three | 1b05272735bf083e1b148169130f620505dbc2fcff3c4fc6f8f46e49a4efa676 |
+----------+---------------------+----------------------------------------------------------+------------------------------------------------------------------+
```

---

The containers on my machine as i write this:
```
$ sudo ./container-stats
+----------+---------------------+-----------------+------------------------------------------------------------------+
| memory | average_percent_cpu | name | id |
+----------+---------------------+-----------------+------------------------------------------------------------------+
| 7.5 MB | 0.007575758 | /cranky_perlman | 319e4cebf66e3c90e8eed555242f6628fbb6888e862435e4e9be0fd05a5e4c2e |
+----------+---------------------+-----------------+------------------------------------------------------------------+
| 128.8 MB | 0.0152870985 | /portainer | 60c914b19bf7d81019d5f3bb28b201297ead82be87b14d96c259c23612d0d515 |
+----------+---------------------+-----------------+------------------------------------------------------------------+
```

... but one of them is secretly a CPU hog! *(`--top` checks all processes in the container, but is also much slower)*
```
$ sudo ./container-stats --top
+----------+---------------------+-----------------+------------------------------------------------------------------+
| memory | average_percent_cpu | name | id |
+----------+---------------------+-----------------+------------------------------------------------------------------+
| 22.5 MB | 199.53616 | /cranky_perlman | 319e4cebf66e3c90e8eed555242f6628fbb6888e862435e4e9be0fd05a5e4c2e |
+----------+---------------------+-----------------+------------------------------------------------------------------+
| 128.8 MB | 0.015279379 | /portainer | 60c914b19bf7d81019d5f3bb28b201297ead82be87b14d96c259c23612d0d515 |
+----------+---------------------+-----------------+------------------------------------------------------------------+
```

And in case you want to further process it with a script:
```
$ sudo ./container-stats --top --json
[
{
"memory": 128278528,
"memory": 22499328,
"average_percent_cpu": 199.51184,
"name": "/cranky_perlman",
"id": "319e4cebf66e3c90e8eed555242f6628fbb6888e862435e4e9be0fd05a5e4c2e"
},
{
"memory": 128811008,
"average_percent_cpu": 0.015256125,
"name": "/portainer",
"id": "60c914b19bf7d6101975f39928b201297ead82be87b14d96c259c23612d0d515"
"id": "60c914b19bf7d81019d5f3bb28b201297ead82be87b14d96c259c23612d0d515"
}
]
```

Show the RSS usage of all containers, combined
```
$ sudo ./container-stats -m rss -t
Total: 114.3 GB (114328526848 B)
```
(To learn about the difference between RSS and VSZ, see https://stackoverflow.com/questions/7880784)

---

The total memory usage of all containers starting with `/sample-`:
The total VSZ usage of all containers starting with `/sample-`:
```
$ sudo ./container-stats -t -r "^/sample-"
Total: 106.4 GB (106439839744 B)
```

Show the RSS usage of all containers, combined:
```
$ sudo ./container-stats -m rss -t
Total: 114.3 GB (114328526848 B)
```
*(To learn about the difference between RSS and VSZ, see https://stackoverflow.com/questions/7880784)*

---

All containers, grouped by their prefixes, sorted by memory usage:
```
$ sudo ./container-stats --group-by-prefix -s
+----------+------------+-------------+
| memory | containers | fix |
+----------+------------+-------------+
| 239.3 GB | 18 | /fatfix |
+----------+------------+-------------+
| 133.1 GB | 10 | /prefix1 |
+----------+------------+-------------+
| 106.4 GB | 24 | /prefix2 |
+----------+------------+-------------+
| 88.3 GB | 7 | /fix |
+----------+------------+-------------+
| 35.8 GB | 10 | /boring |
+----------+------------+-------------+
| 26.1 GB | 6 | /foofix |
+----------+------------+-------------+
| 14.7 GB | 4 | /barfix |
+----------+------------+-------------+
| 11.3 GB | 3 | /prefix4 |
+----------+------------+-------------+
| 127.9 MB | 1 | /tiny |
+----------+------------+-------------+
+----------+---------------------+------------+------------+
| memory | average_percent_cpu | containers | fix |
+----------+---------------------+------------+------------+
| 239.3 GB | 2.685421 | 37 | /fatfix |
+----------+---------------------+------------+------------+
| 133.1 GB | 18.31371 | 10 | /prefix1 |
+----------+---------------------+------------+------------+
| 106.4 GB | 17.382954 | 11 | /prefix2 |
+----------+---------------------+------------+------------+
| 88.3 GB | 6.465111 | 12 | /fix |
+----------+---------------------+------------+------------+
| 14.8 GB | 2.9222221 | 4 | /boring |
+----------+---------------------+------------+------------+
| 11.3 GB | 1.2392704 | 12 | /foofix |
+----------+---------------------+------------+------------+
| 10.6 GB | 3.7951217 | 5 | /barfix |
+----------+---------------------+------------+------------+
| 4.3 GB | 4.833365 | 4 | /prefix3 |
+----------+---------------------+------------+------------+
| 128.2 MB | 0.019668292 | 1 | /tinyfix |
+----------+---------------------+------------+------------+
```

0 comments on commit a4348d8

Please sign in to comment.