Git Product home page Git Product logo

check-container-stats's Introduction

Pylint pycodestyle Unit tests Release

check-container-stats

About

  • this repository contains a collection of Icinga / Nagios plugins to check Docker / PodMan containers
  • Written for python3
  • Only requires standard python modules, no additional dependencies
  • To be executed i.e. via NRPE on the container host, uses the local "docker"/"podman" binary to query container metrics

Documentation

Usage example

# default usage
./check_container_stats_docker.py -c containername
OK - containername (b343972b5de9) is Up 3 days - CPU: 8.65%, Memory: 10.62 GiB, PIDs: 304 | cpu=8.65%;;;; pids=304;;;; mem=11403138171B;;;;33565169418 net_send=2570000000B;;;; net_recv=2750000000B;;;; disk_read=1580000000B;;;; disk_write=3760000000B;;;;

# With custom socket file location (i.e. for rootless docker or multiple instances of docker daemon on one host)
./check_container_stats_docker.py -c containername --socket 'unix:///run/user/1000/docker.sock'

# Search for a container that matches *<containername>* (default is to only search for exact matches)
./check_container_stats_docker.py -c containername --wildcard

Usage

usage: check_container_stats_docker.py [-h] -c CONTAINER_NAME [-t TIMEOUT]
                                       [-s SOCKET] [--wildcard]
                                       [--cpuwarn CPUWARN] [--cpucrit CPUCRIT]
                                       [--memwarn MEMWARN] [--memcrit MEMCRIT]
                                       [--pidwarn PIDWARN] [--pidcrit PIDCRIT]

Icinga/Nagios plugin which checks health and statistics of a Container

optional arguments:
  -h, --help            show this help message and exit
  -c CONTAINER_NAME, --container CONTAINER_NAME
                        Name of the Container which should be checked
  -t TIMEOUT, --timeout TIMEOUT
                        timeout in seconds
  -s SOCKET, --socket SOCKET
                        Path to Docker socket, sets environment variable
                        DOCKER_HOST
  --wildcard            --container is a wildcard, not an exact match

Thresholds:
  --cpuwarn CPUWARN     warning threshold for CPU usage (in %)
  --cpucrit CPUCRIT     critical threshold for CPU usage (in %)
  --memwarn MEMWARN     warning threshold for memory usage (in Bytes)
  --memcrit MEMCRIT     critical threshold for memory usage (in Bytes)
  --pidwarn PIDWARN     warning threshold for number of processes in container
  --pidcrit PIDCRIT     critical threshold for number of processes in
                        container

Icinga2 service check Icinga2 service check

Contributing

  • You're welcome to open issues or pull requests

check-container-stats's People

Contributors

m-erhardt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

check-container-stats's Issues

Problem with perfdata check_container_stats_podman.py in net usage

Hi,
Your script is working fine, but i've a problem with the perdata of the net usage
One container has not net usage and the out is like this

ID            NAME           CPU %       MEM USAGE / LIMIT  MEM %       NET IO      BLOCK IO           PIDS        CPU TIME    AVG CPU %
b5808b6f2ab5  test_container  1.05%       23.65MB / 10.26GB  0.23%       -- / --     46.24MB / 458.8kB  1           17.32594s   1.05%

I'd find out the problem in the code is here

container_stats['net_send'] = output.split(",")[4].split("/")[0].strip()
container_stats['net_send_byte'] = convert_to_bytes(output.split(",")[4].split("/")[0].strip())
container_stats['net_recv'] = output.split(",")[4].split("/")[1].strip()
container_stats['net_recv_byte'] = convert_to_bytes(output.split(",")[4].split("/")[1].strip())

Is it possible to extend the script, if "--/--" appears in the output, to set it to "0"?
Or a new argument "no-usage" to set the variable to "0"?
Regards
Sascha

Graphana Template

Hello,
can you Post your Graphana (usr/share/icingaweb2/modules/graphite/templates) .ini settings.
Best Regards

Support rootless containers

I tried a few ways using sudo and su, but it seems the cleanest way to support rootless containers is by changing the podman ps and podman stats commands directly in this check script.

Error while running the script

Getting below error while running the script.

===============================================================

File "check_container_stats_podman.py", line 79
result = subprocess.run((f'podman ps -a -f name=^{args.container_name}$ '
^
SyntaxError: invalid syntax

=============================================================

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.