Coder Social home page Coder Social logo

docker_check's Introduction

docker_check.py

Docker_check.py is a nagios compatible plugin to check docker containers stats..

Installation & Usage:

The current version don't need any arguments to be used all you need to do is:

Install the Python3 library for the Docker Engine API:

pip3 install docker

Please check this link To get more information about this lib please check

Get the script to the right path in the Docker server:

curl https://raw.githubusercontent.com/elacheche/docker_check/master/docker_check.py > /usr/lib/nagios/plugins/docker_check.py
chmod +x /usr/lib/nagios/plugins/docker_check.py

Add nagios user to docker group:

sudo usermod -a -G docker nagios

Configure the monitoring server:

In this section I'll illustrete how to setup the script to be used by Icinga2 via the by_ssh plugin.. Icinga2 is a Nagios fork, so the plugin is supposed to work with any Nagios fork, the sconfig files and syntax may change from a frok to an other

Check command definition:

Edit /etc/icinga2/conf.d/commands.conf and add:

object CheckCommand "check_docker_by_ssh" {
        import "by_ssh"
        vars.by_ssh_command = "/usr/lib/nagios/plugins/docker_check.py"
}

The script response time for 8 running containers is almost 30 seconds, please execute the script manually to make sure it don't exceeds 60 seconds, if it does, please add the following to the CheckCommand, replacing the values (in seconds) by the good ones:

        vars.by_ssh_timeout = 120 // Custom SSH connextion Timeout
        timeout = 120 // Custom execution Timeout

Add service to Icinga:

Edit /etc/icinga2/conf.d/services/sshServices.conf and add:

apply Service "docker_check_by_ssh" {
  import "generic-service"
  check_command = "check_docker_by_ssh"
  assign where (host.address || host.address6) && host.vars.os == "Linux" && host.name != NodeName && "docker" in host.vars.services
}

To not apply the docker_check script for all hosts we'll limit it to hosts that have a service called docker.

Configure the hosts:

Edit /etc/icinga2/conf.d/hosts/foo.bar.com.conf and add/change:

object Host "My Docker Server" {
  import "generic-host"
  address = "foo.bar"
  vars.os = "Linux"
  vars.services = ["docker"]
}

Apply changes:

Check if everything is OK:

service icinga2 checkconfig

If so, restart Icinga:

service icinga2 restart

Otherwise fix the issues.

Preview:

Script output:

The script output should be similar to this:

OK | furious_ritchie_mem_pct=0.02% furious_ritchie_cpu_pct=0.0% furious_ritchie_net_in=91137 furious_ritchie_net_out=648 furious_ritchie_disk_in=1003520 furious_ritchie_disk_out=0 elated_booth_mem_pct=1.53% elated_booth_cpu_pct=1.73% elated_booth_net_in=556163 elated_booth_net_out=30239 elated_booth_disk_in=4423680 elated_booth_disk_out=58605568 

Grafana:

This is a preview of the results I got with some testing containers (not the ones from the previous output), Icinga2 get checks from the script, Graphite get the data from Icinga then Grafana visualise them via Graphite.

Status from Grafana

docker_check's People

Contributors

elacheche avatar yulius-fxpal avatar

Watchers

 avatar  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.