Zabbix Automatic discovery monitoring Docker stats and top status

Source: Internet
Author: User
Tags dname docker ps

Dcoker Monitoring


First you need to take out the name of Docker, loop execution Docker stats The data out of the reorder after the numeric conversion to/tmp/under name name

[Root@localhost scripts]# Cat docker_host_status.sh
#!/bin/bash
# -------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
# Notice
# After this state would docker stats reorder append to a file
# Auto Discovery Docker stats Container Name--no-stream Execution time
###############################################################################
Docker_name= '/usr/bin/docker ps-a|grep-v ' CONTAINER ID ' |awk ' {print $NF} '
For e in ${docker_name};d o
/usr/bin/docker stats $e--no-stream |awk ' nr==2{a=$1;b=$2;c=$3$4;d=$6$7;e=$9$10;f=$12$13;g=$14$15;h=$17$18;j=$8} End{print "CONTAINER" a "\ n" "CPU" B "\" "Memusage" C "\" "LIMIT" D "\" "NETI-0" E "\" NETI-1 "F" \ "" BLOCKI-0 "G" \ n "" BLOCKI-1 "h" \ "MEM" J} ' |awk-f '% ' {print} ' |awk ' {a=/gib/?$2*1024*1024*1024: (/m[i)? b/?$2*1024*1024: (/[kk][bb]/?$2*1024: (/b\>/?$2*1:$2))}{print $1,a} ' >/tmp/. $e. txt
Done
This script needs to be cycled and placed in a scheduled task every minute

*/1 * * * */usr/bin/sh/etc/zabbix/scripts/docker_host_status.sh
Docker Name Auto Discovery script

[Root@localhost scripts]# Cat docker_name.py
#!/usr/bin/python
# -------------------------------------------------------------------------------
# Filename:docker_name
# revision:1.1
# date:201608018
# Author:mark
# email:usertzc@163.com
# Website:www.linuxea.com
# -------------------------------------------------------------------------------
# Notice
# Automatic Discovery Instance Name
###############################################################################
Import OS
Import JSON
T=os.popen ("" "" "/usr/bin/docker ps-a|grep-v" CONTAINER ID "|awk ' {print $NF} '" ")
Docknam = []
For dname in T.readlines ():
R = Os.path.basename (Dname.strip ())
Docknam + = [{' {#DOCKERNAME} ': R}]
Print json.dumps ({' Data ':d ocknam},sort_keys=true,indent=4,separators= (', ', ': '))
#docker Userparameter

userparameter=docker_status,/etc/zabbix/scripts/docker_name.py
Userparameter=docker_server[*],/usr/bin/docker Top "$" |grep "$" |grep-v root |wc-l
Userparameter=docker_host[*],awk '/$2\>/{print $$2} '/tmp/. $. txt
It should be noted here that Docker is run with root by default, in the use of Docker PS or Docker stats need to be the same as the Docker users, I modified the profile here, the zabbix-agent changed to run as root, Zabbix-agent firewall rules require pointing IP and port to Zabbix-server, please be aware
Allowroot=1
User=root

In addition, other services are found and may need to be manually added

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.