Git Product home page Git Product logo

sfcheewill / cmonitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from f18m/cmonitor

0.0 1.0 0.0 7.91 MB

A Docker/LXC, database-free, lightweight container performance monitoring solution, perfect for ephemeral containers (e.g. containers used for DevOps automatic testing). Can also be used with InfluxDB and Grafana.

Home Page: https://f18m.github.io/cmonitor

License: GNU General Public License v2.0

Makefile 3.02% C 5.47% Python 25.15% C++ 66.06% Dockerfile 0.29%

cmonitor's Introduction

Build Status Copr build status Docker Version

cmonitor - lightweight container monitor

A Docker, LXC, database-free, lightweight container performance monitoring solution, perfect for ephemeral containers (e.g. containers used for DevOps automatic testing). Can also be used with InfluxDB and Grafana to monitor long-lived containers in real-time.

The project is composed by 2 tools:

  1. a lightweight agent (80KB, native binary; no JVM, Python or other interpreters needed) to collect actual CPU/memory/disk statistics (Linux-only) and store them in a JSON file;
  2. a simple Python script to convert the generated JSON to a self-contained HTML page.

The agent is actually a cgroup-aware statistics collector; cgroups (i.e. Linux Control Groups) are the basic technology used to create containers (you can read more on them here); this project is thus aimed at monitoring your LXC/Docker container performances but can equally monitor physical servers.

This project supports only Linux x86_64 architectures.

Table of contents of this README:

Features

This project collects performance data about:

  • per-CPU-core usage;
  • memory usage;
  • network traffic (PPS and MB/s or Mbps);
  • disk load;
  • average Linux load;
  • CPU usage as reported by the cpuacct (CPU accounting) cgroup;
  • memory usage as reported by the memory cgroup;
  • disk usage as reported by the blkio cgroup;

Moreover the project allows you to easily post-process collected data and produce a self-contained HTML page which allows to visualize all the performance data easily using Google Charts.

Yet-Another-Monitoring-Project?

You may be thinking "yet another monitoring project" for containers. Indeed there are already quite a few open source solutions, e.g.:

All these are very complete solutions that allow you to monitor swarms of containers, in real time. The downside is that all these projects require you to setup an infrastructure (usually a time-series database) that collects in real-time all the statistics and then have some powerful web platform (e.g. Graphana) to render those time-series. All this is fantastic for persistent containers.

This project instead is focused on providing a database-free, lightweight container performance monitoring solution, perfect for ephemeral containers (e.g. containers used for DevOps automatic testing). The idea is much simpler:

  1. you collect data for your container (or, well, your physical server) using a small collector software (written in C++ to avoid Java virtual machines, Python interpreters or the like!) that saves data on disk in JSON format;
  2. you save the JSON file, convert it to a self-contained HTML page;
  3. you can archive that HTML file, send it by email, put in a tarball or whatever you like the most: no dependencies at all are required to visualize it later!

How to install

RPM

If you use an LXC/Docker container based on a Centos/RHEL/Fedora distribution you can log into the container (or change its Dockerfile) and just install the RPM right away from the COPR repository:

yum install -y yum-plugin-copr
yum copr enable -y f18m/cmonitor
yum install -y cmonitor

Ubuntu

If you use an LXC/Docker container based on a Ubuntu distribution you can similarly install from my Ubuntu PPA using the following commands:

add-apt-repository ppa:francesco-montorsi/cmonitor
apt-get install cmonitor

Docker

If you want to simply use a out-of-the-box Docker container to monitor your baremetal performances you can run:

docker pull f18m/cmonitor

which downloads the Docker image for this project from Docker Hub. See below for examples on how to run the Docker image.

How to use

Step 1: collect stats

The RPM installs a single utility, cmonitor_collector inside your container; launch it like that:

cmonitor_collector -s 3 -m /home

to produce in the /home folder a JSON with CPU/memory/disk/network stats for the container sampling all supported performance statistics every 3 seconds. Whenever you want you can either:

  • inject that JSON inside InfluxDB (mostly useful for persistent containers that you want to monitor in real-time); see section "Connecting with InfluxDB and Grafana" below;
  • or use the cmonitor_chart utility to convert that JSON into a self-contained HTML file (mostly useful for ephemeral containers); see below for practical examples.

Step 2: plot stats collected as JSON

To plot the JSON containing the collected statistics, simply launch the cmonitor_chart utility installed together with the RPM/Debian package, with the JSON collected from cmonitor_collector:

cmonitor_chart --input=/path/to/json-stats.json --output=<optional HTML output filename>

Note that to save space/bandwidth you can also gzip the JSON file and pass it gzipped directly to cmonitor_chart.

Usage scenarios and HTML result examples

Monitoring the baremetal server (no containers)

In this case you can simply install cmonitor as RPM or APT package following instructions in How to install and then launch the cmonitor collector as any other Linux daemon. Example results:

  1. baremetal1: example of graph generated with the performance stats collected from a physical (baremetal) server running Ubuntu 18.04; note that despite the absence of any kind of container, the cmonitor_collector utility (like just any other software in modern Linux distributions) was running inside the default "user.slice" cgroup and collected both the stats of that cgroup and all baremetal stats (which in this case mostly coincide since the "user.slice" cgroup contains almost all running processes of the server);

  2. baremetal2: This is a longer example of collected statistics (results in a larger file, may take some time to download) generated with 9 hours of performance stats collected from a physical server running Centos7 and with 56 CPUs (!!); the cmonitor_collector utility was running inside the default "user.slice" cgroup so both "CGroup" and "Baremetal" graphs are present;

Monitoring the baremetal server from a Docker container

In this case you can install cmonitor Docker using the official DockerHub image, see Docker; the Docker container will collect all performance stats of the baremetal. Just run it

docker run -d \
    --name=cmonitor-baremetal-collector
    -v /root:/perf \
    f18m/cmonitor

Example results:

  1. docker_collecting_baremetal_stats: example of graph generated with the performance stats collected from a physical server from inside a Docker container; in this case cgroup stat collection was explicitely disabled so that only baremetal performance graphs are present;

Monitoring your Docker container embedding cmonitor inside it

If you can easily modify the Dockerfile of your container, you can embed cmonitor so that it runs inside your container and monitor your dockerized-application. Example of the Dockerfile modified for this purpose:

...
COPY cmonitor_collector /usr/bin/   # first you need to grabthe cmonitor binary for your Docker base image
CMD /usr/bin/cmonitor_collector \
      --sampling-interval=3 \
      --output-filename=mycontainer.json \
      --output-directory /perf ; \
    myapplication
...

Example results:

  1. docker_userapp_with_embedded_collector: example of graph generated with the performance stats collected from inside a Docker container using Ubuntu as base image; this is a practical example where the Docker container is actually deploying something that simulates your target application, together with an embedded cmonitor_collector instance that monitors the performance of the Docker container itself; in this case both cgroup stats and baremetal performance graphs are present.

Monitoring your Docker container from the baremetal

In this case you can simply install cmonitor as RPM or APT package following instructions in How to install and then launch the cmonitor collector as any other Linux daemon, specifying the name of the container it should monitor, e.g.

docker run --name userapp myuserapp-docker-image

# here we exploit the following fact: the cgroup of each Docker container 
# is always named 'docker/container-ID'
cmonitor_collector \
  --sampling-interval=3 \
  --output-filename docker-userapp.json \
  --cgroup-name=docker/$(docker ps --no-trunc -aqf name=userapp)

Example results:

  1. docker_userapp: example of the chart generated by monitoring from the baremetal a simple docker simulating your application, doing some CPU and I/O

Connecting with InfluxDB and Grafana

The cmonitor_collector can be connected to an InfluxDB deployment to store collected data (this can happen in parallel to the JSON default storage). This can be done by simply providing the IP and port of the InfluxDB instance when launching the collector:

cmonitor_collector --remote-ip=1.2.3.4 --remote-port=8086

The InfluxDB instance can then be used as data source for graphing tools like Grafana which allow you to create nice interactive dashboards like the following one:

Basic Dashboard Example

You can also play with the live dashboard example

To setup easily and quickly the chain "cmonitor_collector-InfluxDB-Grafana" you can checkout the repo of this project and run:

make -C examples regen_grafana_screenshots

which uses Docker files to deploy a temporary setup and fill the InfluxDB with 10minutes of data collected from the baremetal.

Project History

This project started as a fork of Nigel's performance Monitor for Linux, adding cgroup-awareness; but it has quickly evolved to a point where it shares very little code pieces with the original njmon tool.

Some key differences now include:

  • cgroup-aware: several performance cgroup stats are collected by cmonitor_collector and plotted by cmonitor_chart
  • more command-line options for cmonitor_collector;
  • HTML page generated by cmonitor_chart differently organized;
  • cmonitor_collector is able to connect to InfluxDB directly and does not need intermediate Python scripts to transform from JSON streamed data to InfluxDB-compatible stream.

This fork supports only Linux x86_64 architectures; support for AIX/PowerPC (present in original nmon) has been dropped.

License

Just like the original project, this project is licensed under GNU GPL 2.0.

cmonitor's People

Contributors

f18m avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.