Skip to content

Commit

Permalink
Feature/cgroups v2 (#23)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
f18m authored Nov 19, 2021
1 parent 86368fd commit 2779136
Show file tree
Hide file tree
Showing 42 changed files with 5,171 additions and 3,389 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ collector/src/tests/centos7-Linux-3.10.0-x86_64/sample*/sample-timestamp
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/result*.json
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/sample*
collector/src/tests/ubuntu20.04-Linux-5.4.0-x86_64/current-sample
collector/src/tests/fedora35-Linux-5.14.17-x86_64/result*.json
collector/src/tests/fedora35-Linux-5.14.17-x86_64/sample*
collector/src/tests/fedora35-Linux-5.14.17-x86_64/current-sample
4 changes: 2 additions & 2 deletions Constants.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ RPM_TARBALL_DIR:=/tmp/cmonitor/tarball
# IMPORTANT: other places where the version must be updated:
# - debian/changelog -> to release a new Ubuntu package
# See also https://github.com/f18m/cmonitor/wiki/new-release
CMONITOR_VERSION:=1.8
CMONITOR_RELEASE:=5
CMONITOR_VERSION:=2.0
CMONITOR_RELEASE:=0

ifeq ($(DOCKER_LATEST),1)
DOCKER_TAG=latest
Expand Down
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,17 @@ with per-thread granularity.

## Supported Linux Kernels

This project currently supports only cgroups v1. Work is in progress to support cgroups v2.
However for the time being it means you can use `cmonitor-collector` utility on:
* Fedora 30 and earlier releases
* Ubuntu 21.04 and earlier releases
* All other Linux distributions where the following command returns an empty response:

```
grep cgroup2 /proc/filesystems
```
Since version 2.0 this project supports both cgroups v1 and cgroups v2.
This means that the "cmonitor_collector" utility can run on any Linux kernel regardless of its version and its boot options
(since boot options may alter the cgroups technology in use).

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

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

## How to install

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

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

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

## License

Just like the [original project](http://nmon.sourceforge.net), this project is licensed under [GNU GPL
Just like the [original project](http://nmon.sourceforge.net), this project is licensed under [GNU GPL 2.0](LICENSE)
14 changes: 11 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
## TODO collector-side

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

## TODO chart-side
Expand All @@ -18,7 +26,7 @@
CMonitorHeaderInfo

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

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

docker_image: cmonitor_musl
@cp -fv bin/musl/cmonitor_collector docker
Expand Down
8 changes: 7 additions & 1 deletion collector/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
THIS_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ROOT_DIR:=$(shell readlink -f $(THIS_DIR)/../..)

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

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


OBJS = \
$(OUTDIR)/cgroups.o \
$(OUTDIR)/cgroups_config.o \
$(OUTDIR)/cgroups_cpuacct.o \
$(OUTDIR)/cgroups_memory.o \
$(OUTDIR)/cgroups_processes.o \
$(OUTDIR)/header_info.o \
$(OUTDIR)/logger.o \
$(OUTDIR)/main.o \
Expand Down
Loading

0 comments on commit 2779136

Please sign in to comment.