Skip to content

Commit 2779136

Browse files
authored
Feature/cgroups v2 (#23)
Feature/cgroups v2 (#23) * add support for "cpu" and "memory" cgroup controllers v2 * bump major version of cmonitor_collector and cmonitor_tools from 1.8-5 to 2.0-0 * add new data collected from kernel of Fedora35 * backward incompat change: change cgroups v1 memory stats replacing the "total_" prefix with "stat." to make them more similar to cgroups v2 stats * add major version check in cmonitor_chart and cmonitor_statistics to avoid troubles when mixing by mistake recordings obtained with version 1.8-5 and version 2.0-0 * regenerate all examples
1 parent 86368fd commit 2779136

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5171
-3389
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ collector/src/tests/centos7-Linux-3.10.0-x86_64/sample*/sample-timestamp
2727
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/result*.json
2828
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/sample*
2929
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/current-sample
30+
collector/src/tests/fedora35-Linux-5.14.17-x86_64/result*.json
31+
collector/src/tests/fedora35-Linux-5.14.17-x86_64/sample*
32+
collector/src/tests/fedora35-Linux-5.14.17-x86_64/current-sample

Constants.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ RPM_TARBALL_DIR:=/tmp/cmonitor/tarball
1212
# IMPORTANT: other places where the version must be updated:
1313
# - debian/changelog -> to release a new Ubuntu package
1414
# See also https://github.com/f18m/cmonitor/wiki/new-release
15-
CMONITOR_VERSION:=1.8
16-
CMONITOR_RELEASE:=5
15+
CMONITOR_VERSION:=2.0
16+
CMONITOR_RELEASE:=0
1717

1818
ifeq ($(DOCKER_LATEST),1)
1919
DOCKER_TAG=latest

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,17 @@ with per-thread granularity.
9595

9696
## Supported Linux Kernels
9797

98-
This project currently supports only cgroups v1. Work is in progress to support cgroups v2.
99-
However for the time being it means you can use `cmonitor-collector` utility on:
100-
* Fedora 30 and earlier releases
101-
* Ubuntu 21.04 and earlier releases
102-
* All other Linux distributions where the following command returns an empty response:
103-
104-
```
105-
grep cgroup2 /proc/filesystems
106-
```
98+
Since version 2.0 this project supports both cgroups v1 and cgroups v2.
99+
This means that the "cmonitor_collector" utility can run on any Linux kernel regardless of its version and its boot options
100+
(since boot options may alter the cgroups technology in use).
107101

108102
Note that `cmonitor-collector` utility is currently unit-tested against:
109-
* Centos 7 Linux 3.10.0 kernel
103+
* Centos 7 (Linux kernel v3.10.0)
104+
* Ubuntu 20.04 (Linux kernel v5.4.0)
105+
* Fedora 35 (Linux kernel v5.14.17)
110106

111107
Other kernels will be tested in near future. Of course pull requests are welcome to extend coverage.
108+
See [tests folder](collector/src/tests) for more details.
112109

113110
## How to install
114111

@@ -231,21 +228,28 @@ Example results:
231228
#### Monitoring a Docker container launching cmonitor_collector on the baremetal
232229

233230
In this case you can simply install cmonitor as RPM or APT package following instructions in [How to install](#section-id-65)
234-
and then launch the cmonitor_collector utility as any other Linux daemon, specifying the name of the cgroup associated with
231+
and then launch the `cmonitor_collector` utility as any other Linux daemon, specifying the name of the cgroup associated with
235232
the docker container to monitor.
233+
Finding out the cgroup associated with a Docker container can require some detailed information about your OS / runtime configuration;
234+
for example you should know whether you're using cgroups v1 or v2 and which Docker cgroup driver are you using (cgroupfs or systemd);
235+
please see the [official Docker page](https://docs.docker.com/config/containers/runmetrics/#find-the-cgroup-for-a-given-container)
236+
for more details.
236237
In the following example a [Redis](https://hub.docker.com/_/redis) docker container is launched with the name 'userapp' and its
237-
CPU, memory, network and disk usage are monitored launching a cmonitor_collector instance:
238+
CPU, memory, network and disk usage are monitored launching a `cmonitor_collector` instance:
238239

239240
```
240241
docker run --name userapp --detach redis:latest
241242
242243
DOCKER_ID=$(docker ps -aq --no-trunc -f "name=userapp")
243244
245+
CGROUP_NAME=docker/${DOCKER_ID} # when 'cgroupfs' driver is in use
246+
CGROUP_NAME=system.slice/docker-${DOCKER_ID}.scope # when 'systemd' driver is in use
247+
244248
# here we exploit the following fact: the cgroup of each Docker container
245-
# is always named 'docker/container-ID'
249+
# is always named 'docker/container-ID'... at least when using Moby engine
246250
cmonitor_collector \
247251
--num-samples=until-cgroup-alive \
248-
--cgroup-name=docker/${DOCKER_ID} \
252+
--cgroup-name=${CGROUP_NAME} \
249253
--collect=cgroup_threads,cgroup_cpu,cgroup_memory --score-threshold=0 \
250254
--custom-metadata=cmonitor_chart_name:userapp \
251255
--sampling-interval=3 \
@@ -444,4 +448,4 @@ This fork supports only Linux x86_64 architectures; support for AIX/PowerPC (pre
444448

445449
## License
446450

447-
Just like the [original project](http://nmon.sourceforge.net), this project is licensed under [GNU GPL
451+
Just like the [original project](http://nmon.sourceforge.net), this project is licensed under [GNU GPL 2.0](LICENSE)

TODO.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
## TODO collector-side
22

3-
- Add 'blkio' cgroup data collection
4-
- Add benchmarks to see if fscanf() is actually slower compared to string2int() to optimize CPU usage
3+
- Add memory.pressure and cpu.pressure collection for cgroups v2
4+
- Start using "fmt-devel" to get very fast formatting support, see https://github.com/fmtlib/fmt
5+
since the collector is mostly dealing with string/integer operations
6+
- Write Gbenchmark to compare
7+
* FILE* fopen()
8+
* open() syscall
9+
* std::ifstream
10+
since buffering is not interesting to our usecase... currently collector is using all of 3 solutions above
11+
could not find any on the web!
12+
- Add 'io' cgroup v2 data collection
513
- Add support for UDP data tx to InfluxDB
614

715
## TODO chart-side
@@ -18,7 +26,7 @@
1826
CMonitorHeaderInfo
1927

2028
- add more sampled data for CMonitorCGroup, for several kernels
21-
- test more configurations for CMonitorCGroup
29+
- test more configurations for CMonitorCGroup, like dockers having no memory limit or no cpu limits
2230
- Test deployment on supported Linux distributions
2331
- Add LXC examples
2432

collector/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ cmonitor_musl: # build cmonitor inside a Docker from Alpine distro, to build a c
129129
# for docker builds, we strip them away to reduce docker size:
130130
docker run --rm -it -v "${ROOT_DIR}":"/opt/src" -e "MUSL_BUILD=1" \
131131
radupopescu/musl-builder \
132-
sh -c "cd /opt/src/collector && gcc --version && make clean && make && make strip"
132+
sh -c "cd /opt/src/collector && apk add gtest-dev && gcc --version && make clean && make -j && make strip"
133133

134134
docker_image: cmonitor_musl
135135
@cp -fv bin/musl/cmonitor_collector docker

collector/src/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
THIS_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
66
ROOT_DIR:=$(shell readlink -f $(THIS_DIR)/../..)
77

8+
# IMPORTANT: we do require c++11, i.e. GCC 4.8.1 or higher;
9+
# Centos7 which is one of the oldest-supported distributions provides gcc 4.8.5 so we
10+
# cannot move to e.g. c++14/17/20 yet
811
CXXFLAGS=-Wall -Werror -Wno-switch-bool -std=c++11 -DVERSION_STRING=\"$(RPM_VERSION)-$(RPM_RELEASE)\"
912

1013
ifeq ($(DEBUG),1)
@@ -35,7 +38,10 @@ MEMCHECK_COMMON_OPTS:=--tool=memcheck --track-origins=yes --malloc-fill=AF --fre
3538

3639

3740
OBJS = \
38-
$(OUTDIR)/cgroups.o \
41+
$(OUTDIR)/cgroups_config.o \
42+
$(OUTDIR)/cgroups_cpuacct.o \
43+
$(OUTDIR)/cgroups_memory.o \
44+
$(OUTDIR)/cgroups_processes.o \
3945
$(OUTDIR)/header_info.o \
4046
$(OUTDIR)/logger.o \
4147
$(OUTDIR)/main.o \

0 commit comments

Comments
 (0)