├── playbook ├── hosts ├── site.yml └── README.md ├── .gitignore ├── iostat ├── iostat-cron.conf ├── iostat-params.conf ├── dev-discovery.sh ├── iostat-cron.sh ├── README.md └── iostat-check.sh ├── mysql ├── mysql-params.conf ├── mysql-check.sh ├── README.md └── mysql-template.xml ├── nginx ├── nginx-params.conf ├── README.md ├── nginx-check.sh └── nginx-template.xml ├── php-fpm ├── php-fpm-params.conf ├── README.md ├── php-fpm-check.sh └── php-fpm-template.xml ├── jvm ├── jvm-params.conf ├── README.md ├── jvm-check.pl └── jvm-service.pl ├── mysql-v2 ├── mysql-params-v2.conf ├── README.md └── mysql-check-v2.sh ├── README.md └── hadoop ├── hadoop-params.conf ├── README.md ├── create-aggr-item.py ├── hadoop-collector.py ├── hadoop-datanode-template.xml ├── hadoop-tasktracker-template.xml ├── hadoop-basic-template.xml └── hadoop-namenode-template.xml /playbook/hosts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /playbook/site.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .pydevproject 3 | .settings 4 | 5 | playbook/venv 6 | 7 | -------------------------------------------------------------------------------- /iostat/iostat-cron.conf: -------------------------------------------------------------------------------- 1 | * * * * * root /usr/local/zabbix-agent-ops/bin/iostat-cron.sh 2 | -------------------------------------------------------------------------------- /mysql/mysql-params.conf: -------------------------------------------------------------------------------- 1 | UserParameter=mysql[*],/usr/local/zabbix-2.0.3/bin/mysql-check.sh $1 $2 2 | -------------------------------------------------------------------------------- /nginx/nginx-params.conf: -------------------------------------------------------------------------------- 1 | UserParameter=nginx[*],/usr/local/zabbix-agent-ops/bin/nginx-check.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /php-fpm/php-fpm-params.conf: -------------------------------------------------------------------------------- 1 | UserParameter=php-fpm[*],/usr/local/zabbix-agent-ops/bin/php-fpm-check.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /jvm/jvm-params.conf: -------------------------------------------------------------------------------- 1 | UserParameter=jvm.collector[*],/usr/local/zabbix-agent-ops/bin/jvm-check.pl -host "$1" -jvmport "$2" 2 | -------------------------------------------------------------------------------- /iostat/iostat-params.conf: -------------------------------------------------------------------------------- 1 | UserParameter=custom.vfs.dev.discovery,/usr/local/zabbix-agent-ops/bin/dev-discovery.sh 2 | UserParameter=iostat[*],/usr/local/zabbix-agent-ops/bin/iostat-check.sh $1 $2 3 | -------------------------------------------------------------------------------- /mysql-v2/mysql-params-v2.conf: -------------------------------------------------------------------------------- 1 | UserParameter=mysql-v2.discovery,/usr/local/zabbix-agent-ops/bin/mysql-check-v2.sh discovery 2 | UserParameter=mysql-v2.collector[*],/usr/local/zabbix-agent-ops/bin/mysql-check-v2.sh collector "$1" $2 3 | -------------------------------------------------------------------------------- /playbook/README.md: -------------------------------------------------------------------------------- 1 | Ansible Playbook 2 | ================ 3 | 4 | [Ansible][1] provisioning tool. 5 | 6 | Install 7 | ------- 8 | 9 | ```bash 10 | $ virtualenv venv --distribute 11 | $ source venv/bin/activate 12 | $ pip install ansible 13 | ``` 14 | 15 | [1]: http://www.ansibleworks.com/ 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | zabbix-templates 2 | ================ 3 | 4 | Zabbix templates for various services and applications. 5 | 6 | Currently there are: 7 | 8 | * iostat 9 | * Nginx 10 | * php-fpm 11 | * MySQL 12 | * JVM 13 | 14 | There're READMEs for every templates. 15 | 16 | ## TODO 17 | 18 | * Low-level discovery for JVM 19 | * ZooKeeper 20 | * Storm 21 | * Hadoop 22 | -------------------------------------------------------------------------------- /iostat/dev-discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEVICES=`iostat | awk '{ if ($1 ~ "^([shxv]|xv)d[a-z]$") { print $1 } }'` 4 | 5 | COUNT=`echo "$DEVICES" | wc -l` 6 | INDEX=0 7 | echo '{"data":[' 8 | echo "$DEVICES" | while read LINE; do 9 | echo -n '{"{#DEVNAME}":"'$LINE'"}' 10 | INDEX=`expr $INDEX + 1` 11 | if [ $INDEX -lt $COUNT ]; then 12 | echo ',' 13 | fi 14 | done 15 | echo ']}' 16 | 17 | -------------------------------------------------------------------------------- /mysql/mysql-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z $1 ] || [ -z $2 ]; then 4 | exit 1 5 | fi 6 | 7 | HOST_HOST=$1 8 | QUERY_KEY=$2 9 | 10 | if [ "x$QUERY_KEY" = "xReplication_delay" ]; then 11 | 12 | mysql -uroot -ppassword -h127.0.0.1 -P3306 -Dheartbeat_db -e "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(ts) FROM heartbeat ORDER BY id DESC LIMIT 1" | sed '1d' 13 | 14 | else 15 | 16 | mysqladmin -uroot -ppassword -h127.0.0.1 -P3306 extended-status | grep -w "$QUERY_KEY" | awk '{print $4}' 17 | 18 | fi 19 | 20 | -------------------------------------------------------------------------------- /hadoop/hadoop-params.conf: -------------------------------------------------------------------------------- 1 | 2 | UserParameter=hadoop.namenode.collector[*],/usr/local/zabbix-agent-ops/bin/hadoop-collector.py -t namenode -s "$1" 3 | 4 | UserParameter=hadoop.jobtracker.collector[*],/usr/local/zabbix-agent-ops/bin/hadoop-collector.py -t jobtracker -s "$1" 5 | 6 | UserParameter=hadoop.tasktracker.collector[*],/usr/local/zabbix-agent-ops/bin/hadoop-collector.py -t tasktracker -s "$1" --jobtracker-host="$2" --jobtracker-port="$3" 7 | 8 | UserParameter=hadoop.datanode.collector[*],/usr/local/zabbix-agent-ops/bin/hadoop-collector.py -t datanode -s "$1" --namenode-host="$2" --namenode-port="$3" 9 | 10 | -------------------------------------------------------------------------------- /iostat/iostat-cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # Info: 6 | # - cron job to gather iostat data 7 | # - can not do real time as iostat data gathering will exceed 8 | # Zabbix agent timeout 9 | ################################## 10 | # Contact: 11 | # vincent.viallet@gmail.com 12 | ################################## 13 | # ChangeLog: 14 | # 20100922 VV initial creation 15 | ################################## 16 | 17 | # source data file 18 | DEST_DATA=/usr/local/zabbix-agent-ops/var/iostat-data 19 | TMP_DATA=/usr/local/zabbix-agent-ops/var/iostat-data.tmp 20 | 21 | # 22 | # gather data in temp file first, then move to final location 23 | # it avoids zabbix-agent to gather data from a half written source file 24 | # 25 | # iostat -kx 10 2 - will display 2 lines : 26 | # - 1st: statistics since boot -- useless 27 | # - 2nd: statistics over the last 10 sec 28 | # 29 | iostat -kx 10 2 > $TMP_DATA 30 | mv $TMP_DATA $DEST_DATA 31 | 32 | 33 | -------------------------------------------------------------------------------- /iostat/README.md: -------------------------------------------------------------------------------- 1 | Template iostat 2 | =============== 3 | 4 | Show `iostat` result in Zabbix. 5 | 6 | 7 | INSTALL 8 | ------- 9 | 10 | Assume the Zabbix agent directory is /zabbix-agent/. 11 | 12 | ### Install Cron Job 13 | 14 | Since the first output of `iostat` is the statistics since boot time, we need to wait for a period (like 10 seconds) to get the result, which should be done through cron job, otherwise it'll surpass the zabbix agent's timeout. 15 | 16 | Do the following two steps: 17 | 18 | 1. Copy iostat-cron.sh to /zabbix-agent/bin/; 19 | 2. Copy iostat-cron.conf to /etc/cron.d/; 20 | 21 | After a while, you'll see the iostat-data file in /zabbix-agent/var/. 22 | 23 | ### Install User Parameters 24 | 25 | To expose the iostat-data to Zabbix, do the following steps: 26 | 27 | 1. Copy dev-discovery.sh and iostat-check.sh to /zabbix-agent/bin/, the former one is to enable disk device discovery capability. 28 | 2. Copy iostat-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. 29 | 30 | ### Import Template 31 | 32 | Import iostat-template.xml, and link it to a host. 33 | 34 | 35 | CREDITS 36 | ------- 37 | 38 | Some of the scripts are from https://github.com/zbal/zabbix. 39 | 40 | -------------------------------------------------------------------------------- /mysql/README.md: -------------------------------------------------------------------------------- 1 | Template MySQL 2 | ============ 3 | 4 | Show MySQL statistics in Zabbix. 5 | 6 | INSTALL 7 | ------- 8 | 9 | Assume the Zabbix agent is installed in /zabbix-agent/ directory. 10 | 11 | ### Preparatory 12 | 13 | This package uses `mysql` and `mysqladmin` commands to gather information of MySQL. 14 | 15 | ### Install Script and Add User Parameters 16 | 17 | Copy mysql-check.sh to /zabbix-agent/bin/. Copy mysql-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. Restart Zabbix agent. 18 | 19 | Edit mysql-check.sh to configure username and password. 20 | 21 | ### Import Template 22 | 23 | Import mysql-template.xml, and link it to a host. 24 | 25 | HOW IT WORKS 26 | ------------ 27 | 28 | ### mysqladmin 29 | 30 | Most statistics items are from `mysqladmin extended-status`. 31 | 32 | ### Replication Delay 33 | 34 | To detect the replication delay (in sec) of Slave database, we use a dedicated `heartbeat_db`, in which the Master database update the timestamp periodically, and the Slave agents check the difference between current timestamp and the heartbeat_db's timestamp. 35 | 36 | The `heartbeat_db.heartbeat` table's structure is: 37 | 38 | ```sql 39 | CREATE TABLE `heartbeat` ( 40 | `id` int(11) NOT NULL AUTO_INCREMENT, 41 | `ts` datetime NOT NULL, 42 | RIMARY KEY (`id`) 43 | ) 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /nginx/README.md: -------------------------------------------------------------------------------- 1 | Template Nginx 2 | ============== 3 | 4 | Show Nginx status in Zabbix. 5 | 6 | REQUIREMENTS 7 | ------------ 8 | 9 | * Zabbix Server **2.0** 10 | * Zabbix Agent **2.0** 11 | * Wget 12 | 13 | INSTALL 14 | ------- 15 | 16 | Assume the Zabbix agent is installed in /zabbix-agent/ directory. 17 | 18 | ### Nginx HttpStubStatusModule 19 | 20 | Nginx needs to be built with HttpStubStatusModule, i.e. --with-http_stub_status_module. You can use `nginx -V` to check whether the current binary includes this module. 21 | 22 | More information could be found in this [Wiki][1] 23 | 24 | ### Add Configuration 25 | 26 | Add the following into Nginx configuration: 27 | 28 |
29 | server {
30 | listen 10061;
31 | location /nginx_status {
32 | stub_status on;
33 | access_log off;
34 | allow 127.0.0.1;
35 | deny all;
36 | }
37 | }
38 |
39 |
40 | Reload Nginx, and use `curl http://127.0.0.1:10061/nginx_status` to get the statistics.
41 |
42 | ### Install script nginx-check.sh
43 |
44 | Create directory /usr/local/zabbix-agent-ops/bin/ and copy nginx-check.sh to inside.
45 |
46 | ### Add User Parameters
47 |
48 | Copy nginx-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. Restart Zabbix agent.
49 |
50 | ### Import Template
51 |
52 | Import nginx-template.xml, and link it to a host. Set the host macro {$NGINX_STATUS_URL} if needed.
53 |
54 |
55 | CREDITS
56 | -------
57 |
58 | The scripts are form http://github.com/zbal/zabbix.
59 |
60 | [1]: http://wiki.nginx.org/HttpStubStatusModule
61 |
--------------------------------------------------------------------------------
/jvm/README.md:
--------------------------------------------------------------------------------
1 | Template JVM
2 | ============
3 |
4 | Show JVM statistics in Zabbix.
5 |
6 | INSTALL
7 | -------
8 |
9 | Assume the Zabbix agent is installed in /zabbix-agent/ directory.
10 |
11 | ### A Compatible JDK
12 |
13 | This package uses `jstat` and `jstack` commands to gather information of jVM.
14 |
15 | ### Start Daemon
16 |
17 | Since the Zabbix agent runs in zabbix user, making it impossible to attache to JVMs running under other users. The solution is to start a daemon under that user and provide socket access to gather the information.
18 |
19 | $ ./jvm-service.pl -d
20 |
21 | It will write logs into /tmp/jvm-service.log
22 |
23 | ### Install Script and Add User Parameters
24 |
25 | Copy jvm-check.pl to /zabbix-agent/bin/. Copy jvm-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. Restart Zabbix agent.
26 |
27 | ### Import Template
28 |
29 | Import jvm-template.xml, and link it to a host. Set the host macro {$JVMPORT} to which the JVM you want to monitor bind.
30 |
31 | HOW IT WORKS
32 | ------------
33 |
34 | To gather information more effectively, I didn't use a lot of user parameters in the configuration file, to run multiple times. Instead, I used the 'zabbix agent trapper' data type, and run another script sending multiple data items to zabbix server.
35 |
36 | Again, instead of setup a cron job for the script, I used another 'zabbix agent' data type to let the server trigger this script.
37 |
38 | In case the `jstat` command spends more than 3 seconds, which surpasses the timeout limit of Zabbix, so you may want to adjust the `Timeout` option in *both* Zabbix server and agent configuration.
39 |
40 |
--------------------------------------------------------------------------------
/php-fpm/README.md:
--------------------------------------------------------------------------------
1 | Template php-fpm
2 | ================
3 |
4 | Show php-fpm statistics in Zabbix.
5 |
6 | REQUIREMENTS
7 | ------------
8 |
9 | * Zabbix Server **2.0**
10 | * Zabbix Agent **2.0**
11 | * Wget
12 |
13 | INSTALL
14 | -------
15 |
16 | Assume the Zabbix agent is installed in /zabbix-agent/ directory.
17 |
18 | ### Configure php-fpm
19 |
20 | Open the php-fpm pool's configuration file, uncomment the 'pm.status=' directive:
21 |
22 | pm.status_path = /php-fpm_status
23 |
24 | Since php-fpm's statistics is collected by different pools, so you need to create corresponding hosts for them.
25 |
26 | ### Configure Nginx
27 |
28 | Add the following lines to Nginx configuration:
29 |
30 | ```
31 | server {
32 | listen 10061;
33 |
34 | location /php-fpm_status {
35 | fastcgi_pass 127.0.0.1:9000;
36 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
37 | include fastcgi_params;
38 | }
39 | }
40 | ```
41 |
42 | After restarting both php-fpm and nginx, try the following command to test:
43 |
44 | $ curl http://127.0.0.1:10061/php-fpm_status
45 |
46 | ### Install script php-fpm-check.sh
47 |
48 | Create directory /usr/local/zabbix-agent-ops/bin/ and copy php-fpm-check.sh to inside.
49 |
50 | ### Add User Parameters
51 |
52 | Copy php-fpm-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. Restart Zabbix agent.
53 |
54 | ### Import Template
55 |
56 | Import php-fpm-template.xml, and link it to a host. Set the host macro {$PHP_FPM_STATUS_URL} if needed.
57 |
58 |
59 | CREDITS
60 | -------
61 |
62 | Some of the scripts are form http://github.com/zbal/zabbix.
63 |
64 |
--------------------------------------------------------------------------------
/php-fpm/php-fpm-check.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ##################################
3 | # Zabbix monitoring script
4 | #
5 | # php-fpm:
6 | # - anything available via FPM status page
7 | #
8 | ##################################
9 | # Contact:
10 | # vincent.viallet@gmail.com
11 | ##################################
12 | # ChangeLog:
13 | # 20100922 VV initial creation
14 | ##################################
15 |
16 | # Zabbix requested parameter
17 | ZBX_REQ_DATA="$1"
18 | ZBX_REQ_DATA_URL="$2"
19 |
20 | # Nginx defaults
21 | NGINX_STATUS_DEFAULT_URL="http://localhost:80/php-fpm_status"
22 | WGET_BIN="/usr/bin/wget"
23 |
24 | #
25 | # Error handling:
26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
27 | # - items need to be of type "float" (allow negative + float)
28 | #
29 | ERROR_NO_ACCESS_FILE="-0.9900"
30 | ERROR_NO_ACCESS="-0.9901"
31 | ERROR_WRONG_PARAM="-0.9902"
32 | ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
33 |
34 | # Handle host and port if non-default
35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
36 | URL="$ZBX_REQ_DATA_URL"
37 | else
38 | URL="$NGINX_STATUS_DEFAULT_URL"
39 | fi
40 |
41 | # save the nginx stats in a variable for future parsing
42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
43 |
44 | # error during retrieve
45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
46 | echo $ERROR_DATA
47 | exit 1
48 | fi
49 |
50 | #
51 | # Extract data from nginx stats
52 | #
53 | RESULT=$(echo "$NGINX_STATS" | awk 'match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }')
54 | if [ $? -ne 0 -o -z "$RESULT" ]; then
55 | echo $ERROR_WRONG_PARAM
56 | exit 1
57 | fi
58 |
59 | echo $RESULT
60 |
61 | exit 0
62 |
--------------------------------------------------------------------------------
/mysql-v2/README.md:
--------------------------------------------------------------------------------
1 | Template MySQL
2 | ============
3 |
4 | Show MySQL statistics in Zabbix. Version 2 uses LLD (Low Level Discovery) to bind multiple MySQL instances to the same host.
5 |
6 | INSTALL
7 | -------
8 |
9 | Assume the Zabbix agent is installed in /zabbix-agent/ directory.
10 |
11 | ### Preparatory
12 |
13 | This package uses `mysql` and `mysqladmin` commands to gather information of MySQL.
14 |
15 | ### Install Script and Add User Parameters
16 |
17 | * Copy mysql-check-v2.sh to /zabbix-agent/bin/.
18 | * Copy mysql-params-v2.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/.
19 | * Edit mysql-check-v2.sh to configure username and password.
20 | * Restart Zabbix agent.
21 |
22 | ### Import Template
23 |
24 | Import mysql-template-v2.xml, and link it to a host.
25 |
26 | HOW IT WORKS
27 | ------------
28 |
29 | ### Discovery
30 |
31 | `mysql-check-v2.sh` has two forms of invocation:
32 |
33 | * `./mysql-check-v2.sh discovery` Return a JSON encoded string indicating the MySQL instances (or ports) to be discovered.
34 | * `./mysql-check-v2.sh collector "$host" $port` Get and submit the statistics from MySQL Server to Zabbix Server. (use `zabbix trapper` data type)
35 |
36 | ### Collector
37 |
38 | In order not to run `mysqladmin` several times to get enough information, here we use `Zabbix trapper` data type to let the agent send data actively. Also to save the trouble of adding a cron job, here we use a `Zabbix agent` item to trigger the data collection process.
39 |
40 | ### `mysqladmin`
41 |
42 | Most statistics items are from `mysqladmin extended-status`.
43 |
44 | ### Replication Delay
45 |
46 | To detect the replication delay (in sec) of Slave database, we use a dedicated `heartbeat_db`, in which the Master database update the timestamp periodically, and the Slave agents check the difference between current timestamp and the heartbeat_db's timestamp.
47 |
48 | The `heartbeat_db.heartbeat` table's structure is:
49 |
50 | ```sql
51 | CREATE TABLE `heartbeat` (
52 | `id` int(11) NOT NULL AUTO_INCREMENT,
53 | `ts` datetime NOT NULL,
54 | RIMARY KEY (`id`)
55 | )
56 | ```
57 |
--------------------------------------------------------------------------------
/mysql-v2/mysql-check-v2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | MYSQL_USERNAME="root"
4 | MYSQL_PASSWORD="password"
5 | MYSQL_PORTS="3306" # use space-seperated multiple instance ports
6 |
7 | MYSQL_VARIABLES="Connections Aborted_clients Aborted_connects Com_select Com_insert Com_update Com_replace Com_delete Slow_queries Threads_connected Threads_running"
8 |
9 | ZABBIX_HOME="/usr/local/zabbix-agent-ops"
10 | ZABBIX_BIN="$ZABBIX_HOME/bin/zabbix_sender -c $ZABBIX_HOME/etc/zabbix_agentd.conf"
11 |
12 | function usage() {
13 | echo "Usage: ./mysql-check-v2.sh