zabbix(moniter)

最後更新: 2018-04-13

目錄

 


Package

 

Client: Centos6 (epel)

  • zabbix20                      - Base package; Contains zabbix_sender and zabbix_get
  • zabbix20-agent             - Contains zabbix_agent, zabbix_agentd

Server: Ubuntu-14.04

  • zabbix-frontend-php      - Frontend fitting a server implementation
  • zabbix-server-mysql      - A server implementation
  • zabbix-agent

 


Client(agent)

 

Firewall port:

10050/tcp

選用什麼 Package Source:

zabbix repos

rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX

# Centos 7

rpm -Uv http://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7...

 * Old version 's OS 可以用這方法安裝

EPEL repos

加 epel 的方式詳見 http://datahunter.org/centos_repository#epel

Agent 安裝:

epel 包: zabbix22-agent

# Dependencies: zabbix22, 所以會安裝它

yum install zabbix22-agent

zabbix 包:

# 在 Debian 上安裝

apt-get install libcurl3-gnutls

wget http://repo.zabbix.com/../zabbix/zabbix-agent_2.2.16-1+squeeze_i386.deb

dpkg -i zabbix-agent_2.2.16-1+squeeze_i386.deb

file:

  • /etc/logrotate.d/zabbix-agent
  • /etc/rc.d/init.d/zabbix-agent
  • /etc/rc.d/init.d/zabbix-agentd   <--  monitoring of various server parameters

config:

/etc/zabbix_agentd.conf

bin:

/usr/sbin/zabbix_agentd

check version

zabbix_agentd --version

Zabbix Agent (daemon) v2.2.1 (revision 40808) (09 December 2013)
Compilation time: Jan 28 2014 16:50:01

Config agent

 

zabbix_agentd 参數

-c, --config <config-file>

-p, --print

Print known items and exit

agent.hostname                                [s|Zabbix server]
agent.ping                                    [u|1]
agent.version                                 [s|2.2.23]
system.localtime[utc]                         [u|1574133995]
system.run[echo test]                         [m|ZBX_NOTSUPPORTED]
...

Remark

    s   Text

    u   Unsigned integer

    d   Number with a decimal part

    m   Not  supported.

      - querying an item that only works in the active mode

      - an item that requires multiple collected values

      - Permission issues or incorrect user parameters

-t, --test <item key>

zabbix_agentd -t agent.version

agent.version                                 [s|2.2.23]

zabbix_agentd 設定

/etc/zabbix/zabbix_agentd.conf

# Basic
PidFile=/var/run/zabbix/zabbix_agentd.pid

#### log
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
# Unit: MByte
LogFileSize=1
# 0 - no debug, 1 - critical, 2 - error
# 3 - warnings, 4 - for debugging
DebugLevel=3

#### Remote Commands
EnableRemoteCommands=0
LogRemoteCommands=1

#### Passive checks (0 => disables)
# No spaces allowed.
Server=127.0.0.1,192.168.123.254
ListenPort=10050
ListenIP=0.0.0.0
# pre-forked instances of zabbix_agentd
StartAgents=1

#### active checks (加了"#", 那 "active mode" 就會不行)
#ServerActive=127.0.0.1         # IP:port
#Hostname=Zabbix server         # Unique, Case sensitive. "#" 了它自動會用 cli hostname
                                # must match hostname as configured on the server

#### Other Config
Include=/etc/zabbix/zabbix_agentd.d/

Active Client Auto Registration:

# Active Client Auto Registration
ServerActive=10.0.0.1

Startup:

service zabbix-agentd restart

chkconfig zabbix-agentd on

Testing:

[1] Start 後會有的 process:

ps aux | grep zabbix

/usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
/usr/sbin/zabbix_agentd: collector [idle 1 sec]
/usr/sbin/zabbix_agentd: listener #1 [waiting for connection]   # 由 StartAgents 設定
/usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
/usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
/usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]          # 由 ServerActive 控制

[2] telnet 127.0.0.1 10050

Trying 192.168.88.196...
Connected to 192.168.88.196.
Escape character is '^]'.
亂打一D野
ZBXDZBX_NOTSUPPORTEDConnection closed by foreign host.

[3] zabbix_get

zabbix_get -s 127.0.0.1 -k "system.uptime"

63289

 


Passive checks & Active checks

 

passive checks

A passive check is a simple data request. Zabbix server or proxy asks for some data (for example, CPU load) and

Zabbix agent sends back the result to the server. The agent will listen on any TCP port.

active checks

    1. Agent opens a TCP connection

    2. Agent asks for the list of checks (frequency of asking: RefreshActiveChecks)

    3. Server responds with a list of items (item key, delay)

    4. Agent parses the response

    5. TCP connection is closed

    6. Agent starts periodical collection of data

    7. The agent then periodically sends the new values to the server

 



Server

 

Centos Package:

zabbix server:
zabbix
zabbix-server    
    zabbix-server-mysql

  • /usr/share/zabbix-server-mysql/images.sql.gz
  • /usr/share/zabbix-server-mysql/data.sql.gz
  • /usr/share/zabbix-server-mysql/schema.sql.gz

Web:
    zabbix-web
    zabbix-web-mysql

不同 DB 可以應該的 Host 數量:

  • SQLite(20 Hosts):
  • mysql(500 Hosts)(InnoDB engine is required.):

安裝

# 1 DB

yum install mysql-server mysql

Create DB:

/usr/bin/mysqladmin -u root password 'new-password'

                            OR

/usr/bin/mysql_secure_installation

mysql> create database zabbix character set utf8;
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '???';
mysql> flush privileges;

# mysql -u zabbix zabbix -p ??? < /usr/share/doc/zabbix-server-mysql-???/create/schema.sql
# mysql -u zabbix zabbix -p ??? < /usr/share/doc/zabbix-server-mysql-???/create/images.sql
# mysql -u zabbix zabbix -p ??? < /usr/share/doc/zabbix-server-mysql-???/create/data.sql

Checking:

mysql> use zabbix;
mysql> show tables;
mysql> quit;

# 2 設定

/etc/zabbix/zabbix.conf.php

.....................................
DBName=zabbix
DBUser=zabbix
DBSocket=/var/run/mysqld/mysqld.sock
DBPassword=??????????

/etc/default/zabbix-server

START=yes
CONFIG_FILE="/etc/zabbix/zabbix_server.conf"

/etc/zabbix/zabbix_server.conf

# agent 是連這個 port 的
ListenPort=10051

LogFile=/var/log/zabbix-server/zabbix_server.log
# log 本身會自己 rotation 的, 單位: MB
LogFileSize=1

AlertScriptsPath=/etc/zabbix/alert.d/

FpingLocation=/usr/bin/fping

............................

其他所需 packages

  • ssh-askpass
  • fping

 


Web UI 設定 (php frontend Setting)

 

Package:

zabbix-frontend-php

Frontend:

/usr/share/zabbix/*php

PHP configuration

/etc/apache2/conf-enabled/zabbix.conf

Alias zabbix /usr/share/zabbix/
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value date.timezone Asia/Hong_Kong
php_value mbstring.func_overload = 2

Apache Setting

<Directory /usr/share/zabbix/>
        Options FollowSymLinks
        DirectoryIndex index.php
        AddType application/x-httpd-php .php
</Directory>

GUI Install

http://<host_ip>/zabbix/setup.php

chmod 777 zabbix/

web 介紹建立 zabbix.conf.php

chmod 751 zabbix/

Permission:

-rw-r--r--  1 www-data www-data   424 Jun 16 18:00 zabbix.conf.php

1. 安裝 webui

yum install zabbix-web-mysql

http://192.168.88.197/zabbix/

PHP extensions:

                              Current value    Required
PHP version                    5.3.3  5.1.6     OK
PHP option memory_limit        128M   128M        OK
PHP option post_max_size       16M    16M         OK
PHP option upload_max_filesize 2M     2M          OK
PHP option max_execution_time  300    300         OK
PHP option max_input_time      300    300         OK
PHP time zone                  Asia/Hong_Kong     OK
PHP databases support          MySQL
                               SQLite3    OK
PHP bcmath                     yes        OK
PHP mbstring                   yes        OK
PHP sockets                    yes        OK
PHP gd                         2.0.34  2.0        OK
PHP gd PNG support             yes         OK
PHP gd JPEG support            yes         OK
PHP gd FreeType support        yes         OK
PHP libxml                     2.7.6   2.6.15     OK
PHP xmlwriter                  yes         OK
PHP xmlreader                  yes         OK
PHP ctype                      yes         OK
PHP session                    yes         OK
PHP session auto start         no          OK
PHP gettext                    yes         OK

2. Configure DB connection

# 要用 與 zabbix 同一個 DB

# 否則執行 zabbix 會有:

mysql_free_result() expects parameter 1 to be resource, boolean given

# Configuration file:

"/etc/zabbix/web/zabbix.conf.php"

3. User A/C

Default 有兩個 user

 - Admin

 - guest

Reset Password:

USE zabbix;
UPDATE users SET passwd=md5('testing') WHERE alias='Admin';

 


zabbix_get - Zabbix get utility

 

getting data from a remote Zabbix agent

-s, --host
-p, --port
-k, --key <item key>

常用的 item:

  • system.uptime
  • proc.num
  • system.cpu.load[percpu,avg5]                   # [] 為非必要內容
  • vm.memory.size[available]

i.e.

zabbix_get -s 127.0.0.1 -k "system.uptime"

63289

 


 

 


zabbix_sender - Zabbix sender utility

 

sending data to a remote Zabbix server.  (Zabbix trapper 會收它發來的 Data(Allowed hosts))

# Specify host name as registered in Zabbix frontend. (一定要是 hostname)

-s, --host <host>

 


Log file

 

/var/log/zabbix-server/zabbix_server.log

 


Web UI Usage:

Default Login:

admin / zabbix

Password reset:

修正 mysql 內的 table "users"

echo -n new_pw | md5sum

UPDATE `zabbix`.`users` SET `passwd` = 'md5_pw' WHERE `users`.`userid` =1;

Basic Usage:

Configuration -> Hosts -> "Host" tab

Status:
    Click "Status" ==> "Not monitored" -> "Monitored"

"Templates" tab

Availability:
    Agent interfaces(IP, Port)

 


看圖:

Monitoring -> Graphs -> Select "Host" & Select "Graph"

 


Templates

  • FTP Service
  • HTTP Service
  • HTTPS Service
  • IMAP Service
  • POP Service
  • POP Service
  • SSH Service
  • SMTP Service
  • ICMP Ping

Template OS Linux (有 Graphs(5))

 

templates

Applications: CPU, OS, Filesystems, Memory
Items: CPU iowait time, CPU idle time

 


FAQ:

<1>

'Guest' user is a special default user.

If you are not logged in, you are accessing Zabbix with “guest” permissions. By default, “guest” has no permissions on Zabbix objects.

<2>

Zabbix server is not running

echo 0 > /selinux/enforce

 


Iteams

 

system.cpu.load[<cpu>,<mode>]

i.e.

Graphs: CPU load 是用它的

system.cpu.load[percpu,avg1]

percpu = Total load divided by online CPU count = normalized CPU load

system.cpu.util[<cpu>,<type>,<mode>]

cpu - <CPU number> or all (default)

type - possible values:

idle, nice, user (default), system (default for Windows), iowait, interrupt, softirq, steal

mode - possible values: avg1 (one-minute average, default), avg5, avg15

 


UserParameter

 

UserParameter=<key>,<shell command>

zabbix_agentd.conf

postfix:

grep version:

UserParameter=postfix.pfmailq,mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'

awk version:

UserParameter=postfix.pfmailq,mailq | awk 'END{ if ($5 == "") print 0; else print $5 }'

qmail:

awk version:

UserParameter=postfix.pfmailq,sudo qmailctl queue | awk 'FNR==1{print $4}'

Permission: /etc/sudoers

zabbix          ALL=(root)      NOPASSWD:       /usr/sbin/qmailctl

test

# Local test:

zabbix_get -s 127.0.0.1 -k "postfix.pfmailq"

 


Email

 

email 沒有 login 能力

Administration -> Media types

 


Troubleshoot:

 

Total Memory graph shows [no data]

 


Time period specification

 

# You can specify more than one time period using a semicolon (;) separator:

d-d,hh:mm-hh:mm;d-d,hh:mm-hh:mm...

Empty time specification equals to 01-07,00:00-24:00

notifications (Configuration → Actions)

Period (seconds)    Time period for increase of escalation step.

Triggers

Configuration → Hosts, Triggers in the row, Create trigger

Multiple PROBLEM events generation

you can set that an event is generated upon every 'Problem' evaluation of the trigger.

A trigger may have the following values:

  • PROBLEM
  • OK
  • UNKNOWN
server is unreachable
trigger expression cannot be evaluated
trigger expression has been recently changed

Operator

  • #     Not equal
  • &     Logical AND

prev

Returns previous value. Parameter is ignored (Same as last(#2))

last

Last (most recent) value  

last(#num)

Parameter: #num - Nth value

last(0)    - equal to last(#1)

last(#3)  - third most recent value

last(0,86400) will return the most recent value one day ago.

sum

sum(#5)     # Sum of all values in no more than the last 5 values

sum(600)    # Sum of all values in no more than the latest 600 seconds

avg

avg (sec|#num,<time_shift>)

time_shift parameter

'300'           # seconds

'1d'              # day

 


Simple checks(tcp)

 

for remote agent-less checks of services

usage:

net.tcp.service[service,<ip>,<port>]

Return value

  • 0 - service is down
  • 1 - service is running

i.e.

net.tcp.service[http]

net.tcp.service[ftp,,2121]

opts:

ip - IP address (default is 127.0.0.1)
service - ssh, ntp, ldap, smtp, ftp, http, pop, nntp, imap, tcp, https, telnet

Expression:

{server:net.tcp.service[smtp].sum(#5)}<2

Timeout processing

Zabbix will not process a simple check longer than the Timeout seconds defined in the Zabbix server configuration file.

zabbix_server.conf

# Specifies how long we wait for agent, SNMP device or external check
# range: 1-30

Timeout=3

 


zabbix_server.conf

 

 


Discovery

 

Linux Template 應該有兩個 discovery:

 - Network interface discovery

 - Mounted filesystem discovery

Checking: filesystem

zabbix_get -s x.x.x.x -k vfs.fs.discovery

{
        "data":[
                {
                        "{#FSNAME}":"\/",
                        "{#FSTYPE}":"rootfs"},
                {
                        "{#FSNAME}":"\/",
                        "{#FSTYPE}":"ext3"}

....

zabbix_get -s x.x.x.x -k 'vfs.fs.size["/",pfree]'

Checking: Network

zabbix_get -s x.x.x.x -k net.if.discovery

{
    "data": [{
            "{#IFNAME}": "enp2s0"
        }, {
            "{#IFNAME}": "vnet0"
        }, {
            "{#IFNAME}": "virbr0-nic"
        }, {
            "{#IFNAME}": "br0"
        }, {
            "{#IFNAME}": "virbr0"
        }, {
            "{#IFNAME}": "lo"
        }
    ]
}

 

 


zabbix "Go to"

 

zabbix: 2.2.2

/usr/share/zabbix/js/menupopup.js

if (options.hasGoTo) {

    // 新加 以下 link
    // Graphs
    gotos[gotos.length] = {
        label: t('Graphs'),
        url: new Curl('charts.php?hostid=' + options.hostid).getUrl()
    };

    // Settings
        gotos[gotos.length] = {
            label: t('Settings'),
            url: new Curl('hosts.php?form=update&hostid=' + options.hostid).getUrl()
    };

}

 


Trigger functions

 

Trigger functions allow to reference collected values, current time and other factors.

{<server>:<key>.<function>(<parameter>)}<operator><constant>

operator:

/   *    -   +   <    >   #  =  &    |

Time based functions:

Trigger status (expression) is recalculated every time Zabbix server receives new value, if this value is part of this expression.
If time based functions are used in the expression, it is recalculated every 30 seconds by a zabbix timer process.

CPU activity at night time

Use of function time():

i.e.

# 在 backup period 不理 overload

{Template OS Linux:system.cpu.util[,iowait].avg(5m)}>50 &
{Template OS Linux:system.hostname.time(0)}<010000 &
{Template OS Linux:system.hostname.time(0)}>060000

另一個方法是用 sum 來實現:

# Sum of the last 5 values
sum(#5)

# Sum of all values within 600 seconds
sum(600)

#    Not equal. The operator is defined as:

A#B ? (A<=B-0.000001) | (A>=B+0.000001)

 


Check 舊系統的 Disk Usage

 

# agent setting

UserParameter=disk.usage,df -h | grep "/home" | awk '{print $5}' | cut -d '%' -f 1

# Test from Server

zabbix_get -s IP -k "disk.usage"

# Server Web Panel Setting

Items:

Name: Disk Usage
Type: Zabbix agent
Key: disk.usage
Data type: Decimal
Unit: %
Update interval(in sec): 600
Description: Old server disk usage

Triggers:

{HOSTNAME:disk.usage.last(0)}>95

 

 


Cust. Graph

 

Graph function:

  • all - all (minimum, average and maximum)
  • min - minimum only
  • avg - average only
  • max - maximum only

Graph type:

  • Normal - normal graph, values displayed as lines
  • Stacked - stacked graph, filled areas displayed
  • Pie - pie graph
  • Exploded - “exploded” pie graph, portions displayed as “cut out” of the pie

Draw style:

  • Line
  • Filled region (不透明)
  • Dot
  • Dashed line (虛線)
  • Gradient line (透明 area)

 

 


Windows Agent

 

# Configuring agent

A single instance can use the default configuration file "c:\zabbix_agentd.conf" or

a configuration file specified in the command line.

LogFile=c:\zabbix_agentd.log
LogFileSize=1
# Incoming connections will be accepted only from the hosts listed here.
Server=127.0.0.1
ListenPort=10050
EnableRemoteCommands=0
Hostname=XXX

# Installing / Uninstalling agent as Windows service

zabbix_agentd.exe --install

zabbix_agentd.exe --config <your_configuration_file> --install

zabbix_agentd.exe --uninstall

zabbix_agentd.exe --config <your_configuration_file> --uninstall

# Starting / Stopping agent

zabbix_agentd.exe --start

zabbix_agentd.exe [4548]: service [Zabbix Agent] started successfully

zabbix_agentd.exe --stop

# Example

cd C:\Program Files\zabbix_agents_3.2.0.win\bin\win64

zabbix_agentd.exe --config "C:\Program Files\zabbix_agents_3.2.0.win\conf\zabbix_agentd.win.conf" --install

zabbix_agentd.exe [5600]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [5600]: event source [Zabbix Agent] installed successfully

 


Doc

 

https://www.zabbix.com/wiki

https://www.zabbix.com/documentation

item key:

https://www.zabbix.com/documentation/2.2/manual/config/items

 

Creative Commons license icon Creative Commons license icon