├── .gitignore ├── PHP-FPM ├── README.md ├── conf │ └── monitor_phpfpm_status.conf ├── scripts │ └── monitor_phpfpm_status ├── snapshot.jpg └── templates │ └── zbx_templates_phpfpm_status.xml ├── README.md ├── Server ├── README.md └── templates │ └── zbx_templates_DELL_R415.xml ├── Zabbix_Java_GateWay └── scripts │ ├── README.md │ └── zabbix_java_gateway └── redis ├── README.md ├── conf └── redis.conf ├── redis-connection-snapshot.jpg ├── redis-cpu-snapshot.jpg ├── redis-items-stored-snapshot.jpg ├── redis-memory-snapshot.jpg ├── redis-request-snapshot.jpg ├── scripts └── redis-status.sh └── templates └── redis.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | -------------------------------------------------------------------------------- /PHP-FPM/README.md: -------------------------------------------------------------------------------- 1 | ## 基本描述 2 | 贡献者: [itnihao](http://weibo.com/itnihao) 3 | 4 | ## 使用说明 5 | ### 前置条件 6 | * 需要确定你有部署php-fpm, 以及你需要监控php-fpm 7 | * PHP-FPM与nginx结合部署 8 | 9 | #### php-fpm.conf 10 | 文件中存在如下内容: 11 | 12 | pm.status_path = /phpfpmstatus 13 | 14 | #### nginx.conf配置 15 | 16 | http{ 17 | .................. 18 | server { 19 | listen 127.0.0.1:80; 20 | server_name 127.0.0.1; 21 | location ~ ^/(phpfpmstatus)$ { 22 | include fastcgi_params; 23 | fastcgi_pass unix:/tmp/fpm.sock; 24 | #fastcgi_pass 127.0.0.1:9000; 25 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 26 | } 27 | } 28 | ................ 29 | } 30 | 31 | 32 | ### 部署监控 33 | #### Zabbix Agent 34 | * 将 [scripts/monitor_phpfpm_status](scripts/monitor_phpfpm_status) 文件拷贝至/etc/zabbix/scripts/目录下,并增加执行权限 35 | * 将 [conf/monitor_phpfpm_status.conf](conf/monitor_phpfpm_status.conf) 文件至/etc/zabbix/zabbix_agentd.d/目录下,并重启zabbix agent 36 | 37 | #### Zabbix Server 38 | * 导入 [templates/zbx_templates_phpfpm_status.xml](templates/zbx_templates_phpfpm_status.xml) 模板,并关联对应主机 39 | * 效果图: 40 | 41 | ![php-fpm效果图](snapshot.jpg) 42 | -------------------------------------------------------------------------------- /PHP-FPM/conf/monitor_phpfpm_status.conf: -------------------------------------------------------------------------------- 1 | UserParameter=phpfpm.status.pool,/etc/zabbix/scripts/monitor_phpfpm_status pool 2 | UserParameter=phpfpm.status.process.manager,/etc/zabbix/scripts/monitor_phpfpm_status process_manager 3 | UserParameter=phpfpm.status.start.since,/etc/zabbix/scripts/monitor_phpfpm_status start_since 4 | UserParameter=phpfpm.status.accepted.conn,/etc/zabbix/scripts/monitor_phpfpm_status accepted_conn 5 | UserParameter=phpfpm.status.listen.queue,/etc/zabbix/scripts/monitor_phpfpm_status listen_queue 6 | UserParameter=phpfpm.status.max.listen.queue,/etc/zabbix/scripts/monitor_phpfpm_status max_listen_queue 7 | UserParameter=phpfpm.status.listen.queue.len,/etc/zabbix/scripts/monitor_phpfpm_status listen_queue_len 8 | UserParameter=phpfpm.status.idle.processes,/etc/zabbix/scripts/monitor_phpfpm_status idle_processes 9 | UserParameter=phpfpm.status.active.processes,/etc/zabbix/scripts/monitor_phpfpm_status active_processes 10 | UserParameter=phpfpm.status.total.processes,/etc/zabbix/scripts/monitor_phpfpm_status total_processes 11 | UserParameter=phpfpm.status.max.active.processes,/etc/zabbix/scripts/monitor_phpfpm_status max_active_processes 12 | UserParameter=phpfpm.status.max.children.reached,/etc/zabbix/scripts/monitor_phpfpm_status max_children_reached 13 | -------------------------------------------------------------------------------- /PHP-FPM/scripts/monitor_phpfpm_status: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # function:monitor php-fpm status from zabbix 4 | # License: GPL 5 | # mail:itnihao@qq.com 6 | # date:2013-05-30 7 | 8 | source /etc/bashrc >/dev/null 2>&1 9 | source /etc/profile >/dev/null 2>&1 10 | 11 | LOG_FILE=/var/log/zabbix/phpfpmstatus.log 12 | curl http://127.0.0.1/phpfpmstatus >${LOG_FILE} 13 | 14 | pool(){ 15 | awk '/pool/ {print $NF}' ${LOG_FILE} 16 | } 17 | process_manager() { 18 | awk '/process manager/ {print $NF}' ${LOG_FILE} 19 | } 20 | 21 | start_since(){ 22 | awk '/start since:/ {print $NF}' ${LOG_FILE} 23 | } 24 | accepted_conn(){ 25 | awk '/accepted conn:/ {print $NF}' ${LOG_FILE} 26 | } 27 | listen_queue(){ 28 | awk '/listen queue:/ {print $NF}' ${LOG_FILE} 29 | } 30 | max_listen_queue(){ 31 | awk '/max listen queue:/ {print $NF}' ${LOG_FILE} 32 | } 33 | listen_queue_len(){ 34 | awk '/listen queue len:/ {print $NF}' ${LOG_FILE} 35 | } 36 | idle_processes(){ 37 | awk '/idle processes:/ {print $NF}' ${LOG_FILE} 38 | } 39 | active_processes(){ 40 | awk '/active processes:/ {print $NF}' ${LOG_FILE} 41 | } 42 | total_processes(){ 43 | awk '/total processes:/ {print $NF}' ${LOG_FILE} 44 | } 45 | max_active_processes(){ 46 | awk '/max active processes:/ {print $NF}' ${LOG_FILE} 47 | } 48 | max_children_reached(){ 49 | awk '/max children reached:/ {print $NF}' ${LOG_FILE} 50 | } 51 | 52 | 53 | case "$1" in 54 | pool) 55 | pool 56 | ;; 57 | process_manager) 58 | process_manager 59 | ;; 60 | start_since) 61 | start_since 62 | ;; 63 | accepted_conn) 64 | accepted_conn 65 | ;; 66 | listen_queue) 67 | listen_queue 68 | ;; 69 | max_listen_queue) 70 | max_listen_queue 71 | ;; 72 | listen_queue_len) 73 | listen_queue_len 74 | ;; 75 | idle_processes) 76 | idle_processes 77 | ;; 78 | active_processes) 79 | active_processes 80 | ;; 81 | total_processes) 82 | total_processes 83 | ;; 84 | max_active_processes) 85 | max_active_processes 86 | ;; 87 | max_children_reached) 88 | max_children_reached 89 | ;; 90 | *) 91 | echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}" 92 | esac 93 | -------------------------------------------------------------------------------- /PHP-FPM/snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/PHP-FPM/snapshot.jpg -------------------------------------------------------------------------------- /PHP-FPM/templates/zbx_templates_phpfpm_status.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-05-30T05:00:19Z 5 | 6 | 7 | phpfpm_status 8 | 9 | 10 | 11 | 499 | 500 | 501 | 502 | phpfpm_status 503 | 900 504 | 200 505 | 0.0000 506 | 100.0000 507 | 1 508 | 1 509 | 0 510 | 1 511 | 0 512 | 0.0000 513 | 0.0000 514 | 0 515 | 0 516 | 0 517 | 0 518 | 519 | 520 | 0 521 | 0 522 | C80000 523 | 0 524 | 2 525 | 0 526 | 527 | phpfpm_status 528 | phpfpm.status.accepted.conn 529 | 530 | 531 | 532 | 1 533 | 0 534 | 00C800 535 | 0 536 | 2 537 | 0 538 | 539 | phpfpm_status 540 | phpfpm.status.active.processes 541 | 542 | 543 | 544 | 2 545 | 0 546 | 0000C8 547 | 0 548 | 2 549 | 0 550 | 551 | phpfpm_status 552 | phpfpm.status.idle.processes 553 | 554 | 555 | 556 | 3 557 | 0 558 | C800C8 559 | 0 560 | 2 561 | 0 562 | 563 | phpfpm_status 564 | phpfpm.status.listen.queue 565 | 566 | 567 | 568 | 4 569 | 0 570 | 00C8C8 571 | 0 572 | 2 573 | 0 574 | 575 | phpfpm_status 576 | phpfpm.status.listen.queue.len 577 | 578 | 579 | 580 | 5 581 | 0 582 | C8C800 583 | 0 584 | 2 585 | 0 586 | 587 | phpfpm_status 588 | phpfpm.status.max.active.processes 589 | 590 | 591 | 592 | 6 593 | 0 594 | C8C8C8 595 | 0 596 | 2 597 | 0 598 | 599 | phpfpm_status 600 | phpfpm.status.max.children.reached 601 | 602 | 603 | 604 | 7 605 | 0 606 | 960000 607 | 0 608 | 2 609 | 0 610 | 611 | phpfpm_status 612 | phpfpm.status.max.listen.queue 613 | 614 | 615 | 616 | 8 617 | 0 618 | 960096 619 | 0 620 | 2 621 | 0 622 | 623 | phpfpm_status 624 | phpfpm.status.start.since 625 | 626 | 627 | 628 | 9 629 | 0 630 | 009696 631 | 0 632 | 2 633 | 0 634 | 635 | phpfpm_status 636 | phpfpm.status.total.processes 637 | 638 | 639 | 640 | 641 | 642 | 643 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 存放Zabbix监控模板、自定义脚本等 2 | 3 | ## PHP-FPM 4 | php-fpm监控 5 | 6 | ## redis 7 | redis监控 8 | 9 | 10 | ## Server 11 | 存放服务器监控 12 | 13 | ## Zabbix_Java_GateWay 14 | 存放Zabbix Java GateWay相关 15 | -------------------------------------------------------------------------------- /Server/README.md: -------------------------------------------------------------------------------- 1 | ## 监控DELL PowerEdge R415服务器硬件状况 2 | * 监控方法:IPMI 3 | * 对应监控模板: templates/zbx_templates_DELL_R415.xml 4 | * 模板说明: 本模板提供通过IPMI监控Dell PowerEdge R415主板温度、风扇转速功能,当温度超过40时,触发trigger 5 | * 具体操作:[基于Zabbix IPMI监控服务器硬件状况 -- pengyao](http://pengyao.org/zabbix-monitor-ipmi-1.html) 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Server/templates/zbx_templates_DELL_R415.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-04-27T08:21:48Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 430 | 431 | 432 | 433 | {Template Dell PowerEdge R415:ipmi.sensor.Ambient_Temp.last(0)}>40 434 | 服务器温度近超过40度 435 | 436 | 0 437 | 3 438 | 439 | 0 440 | 441 | 442 | 443 | 444 | 445 | Ambient Temp 446 | 900 447 | 200 448 | 0.0000 449 | 100.0000 450 | 1 451 | 1 452 | 0 453 | 1 454 | 0 455 | 0.0000 456 | 0.0000 457 | 0 458 | 0 459 | 0 460 | 0 461 | 462 | 463 | 0 464 | 2 465 | C80000 466 | 0 467 | 2 468 | 0 469 | 470 | Template Dell PowerEdge R415 471 | ipmi.sensor.Ambient_Temp 472 | 473 | 474 | 475 | 476 | 477 | FANS RPM 478 | 900 479 | 200 480 | 0.0000 481 | 100.0000 482 | 1 483 | 1 484 | 0 485 | 1 486 | 0 487 | 0.0000 488 | 0.0000 489 | 0 490 | 0 491 | 0 492 | 0 493 | 494 | 495 | 0 496 | 2 497 | 00C800 498 | 0 499 | 2 500 | 0 501 | 502 | Template Dell PowerEdge R415 503 | ipmi.sensor.FAN_MOD_1A_RPM 504 | 505 | 506 | 507 | 1 508 | 2 509 | 0000C8 510 | 0 511 | 2 512 | 0 513 | 514 | Template Dell PowerEdge R415 515 | ipmi.sensor.FAN_MOD_1B_RPM 516 | 517 | 518 | 519 | 2 520 | 2 521 | C800C8 522 | 0 523 | 2 524 | 0 525 | 526 | Template Dell PowerEdge R415 527 | ipmi.sensor.FAN_MOD_2A_RPM 528 | 529 | 530 | 531 | 3 532 | 2 533 | 00C8C8 534 | 0 535 | 2 536 | 0 537 | 538 | Template Dell PowerEdge R415 539 | ipmi.sensor.FAN_MOD_2B_RPM 540 | 541 | 542 | 543 | 4 544 | 2 545 | C8C800 546 | 0 547 | 2 548 | 0 549 | 550 | Template Dell PowerEdge R415 551 | ipmi.sensor.FAN_MOD_3A_RPM 552 | 553 | 554 | 555 | 5 556 | 2 557 | C8C8C8 558 | 0 559 | 2 560 | 0 561 | 562 | Template Dell PowerEdge R415 563 | ipmi.sensor.FAN_MOD_3B_RPM 564 | 565 | 566 | 567 | 6 568 | 2 569 | 960000 570 | 0 571 | 2 572 | 0 573 | 574 | Template Dell PowerEdge R415 575 | ipmi.sensor.FAN_MOD_4A_RPM 576 | 577 | 578 | 579 | 7 580 | 2 581 | 009600 582 | 0 583 | 2 584 | 0 585 | 586 | Template Dell PowerEdge R415 587 | ipmi.sensor.FAN_MOD_4B_RPM 588 | 589 | 590 | 591 | 592 | 593 | 594 | -------------------------------------------------------------------------------- /Zabbix_Java_GateWay/scripts/README.md: -------------------------------------------------------------------------------- 1 | * zabbix_java_gateway为Zabbix Java GateWay启动脚本 2 | -------------------------------------------------------------------------------- /Zabbix_Java_GateWay/scripts/zabbix_java_gateway: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # /etc/init.d/zabbix_java_gateway 4 | # 5 | # Starts the zabbix_Java_gatway daemon 6 | # 7 | # chkconfig: - 95 5 8 | # description: Zabbix Monitoring JavaGateway 9 | 10 | # Author: pengyao 11 | # Date: 2013-05-01 12 | 13 | BASE="/usr/local/zabbix_java_gateway" 14 | CONF="/etc/zabbix/zabbix_java_gateway.conf" 15 | ZABBIX_JAVA_DIR="${BASE}/sbin/zabbix_java" 16 | 17 | JAVA=${JAVA_HOME}/bin/java 18 | 19 | RETVAL=0 20 | PROG="Zabbix Java Gateway" 21 | 22 | ###Functions 23 | get_options(){ 24 | config=$1 25 | option=$2 26 | default_value=$3 27 | result=$(sed -n "s/^${option}=//p" ${config}|tail -n 1|sed -r "s/[\"\']//g") 28 | if [ -z "$result" ];then 29 | result="${default_value}" 30 | fi 31 | } 32 | 33 | get_options ${CONF} LISTEN_IP "0.0.0.0" 34 | LISTEN_IP="${result}" 35 | get_options ${CONF} LISTEN_PORT "10052" 36 | LISTEN_PORT="${result}" 37 | get_options ${CONF} PID_FILE "/tmp/zabbix_java.pid" 38 | PID_FILE="${result}" 39 | get_options ${CONF} START_POLLERS "5" 40 | START_POLLERS="${result}" 41 | 42 | 43 | BOOTUP="color" 44 | RES_COL=60 45 | MOVE_TO_COL="echo -en \\033[${RES_COL}G" 46 | SETCOLOR_SUCCESS="echo -en \\033[1;32m" 47 | SETCOLOR_FAILURE="echo -en \\033[1;31m" 48 | SETCOLOR_NORMAL="echo -en \\033[0;39m" 49 | 50 | echo_success() { 51 | echo -en "\t\t\t\t\t" 52 | [ "$BOOTUP" = "color" ] && $MOVE_TO_COL 53 | echo -n "[" 54 | [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS 55 | echo -n $" OK " 56 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL 57 | echo -n "]" 58 | echo -e "\r" 59 | return 0 60 | } 61 | 62 | echo_failure() { 63 | echo -en "\t\t\t\t\t" 64 | [ "$BOOTUP" = "color" ] && $MOVE_TO_COL 65 | echo -n "[" 66 | [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE 67 | echo -n $"FAILED" 68 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL 69 | echo -n "]" 70 | echo -e "\r" 71 | return 1 72 | } 73 | 74 | status(){ 75 | if [ -n "$PID_FILE" -a -e "$PID_FILE" ] && [ -d "/proc/`cat ${PID_FILE}`" ]; then 76 | echo -e "${PROG} is already running" 77 | RETVAL=0 78 | else 79 | echo -e "${PROG} is not running" 80 | RETVAL=1 81 | fi 82 | 83 | return $RETVAL 84 | } 85 | 86 | start(){ 87 | JAVA_OPTIONS="-server -Dlogback.configurationFile=logback-console.xml" 88 | ZABBIX_OPTIONS="-Dzabbix.listenIP=$LISTEN_IP -Dzabbix.listenPort=$LISTEN_PORT -Dzabbix.pidFile=$PID_FILE -Dzabbix.startPollers=$START_POLLERS" 89 | 90 | CLASSPATH="${ZABBIX_JAVA_DIR}/lib" 91 | for jar in ${ZABBIX_JAVA_DIR}/{lib,bin}/*.jar; do 92 | if [[ $jar != *junit* ]]; then 93 | CLASSPATH="$CLASSPATH:$jar" 94 | fi 95 | done 96 | 97 | COMMAND_LINE="$JAVA $JAVA_OPTIONS -classpath $CLASSPATH $ZABBIX_OPTIONS com.zabbix.gateway.JavaGateway" 98 | 99 | echo -n "Starting: ${PROG}" 100 | $COMMAND_LINE > /dev/null 2>&1 & 101 | RETVAL=$? 102 | 103 | echo $! > $PID_FILE 104 | 105 | if [ $RETVAL -eq 0 ];then 106 | echo_success 107 | else 108 | echo_failure 109 | fi 110 | return $RETVAL 111 | 112 | } 113 | 114 | 115 | stop(){ 116 | echo -n "Stopping: ${PROG}" 117 | kill `cat $PID_FILE` 118 | 119 | RETVAL=$? 120 | if [ $RETVAL -eq 0 ];then 121 | echo_success 122 | else 123 | echo_failure 124 | exit $RETVAL 125 | fi 126 | return $RETVAL 127 | } 128 | 129 | case "$1" in 130 | start) 131 | status >/dev/null 2>&1 132 | [ $? = 0 ] || start 133 | ;; 134 | stop) 135 | status >/dev/null 2>&1 136 | [ $? = 0 ] && stop 137 | ;; 138 | restart) 139 | status >/dev/null 2>&1 140 | [ $? = 0 ] && stop && sleep 5 141 | start 142 | ;; 143 | status) 144 | status 145 | ;; 146 | *) 147 | echo -e "Usage: $0 {start|stop|restart|status}" 148 | exit 2 149 | esac 150 | exit $? 151 | -------------------------------------------------------------------------------- /redis/README.md: -------------------------------------------------------------------------------- 1 | ## 基本描述 2 | 贡献者: 彬彬 3 | 4 | 用于监控[Redis][] 5 | 6 | ## 使用说明 7 | ### 前置条件 8 | * 确保你部署有Redis以及你想通过zabbix监控Redis 9 | 10 | ### 部署监控 11 | #### Zabbix Agent 12 | * 将[scripts/redis-status.sh](scripts/redis-status.sh)文件拷贝至/etc/zabbix/scripts/目录下,并增加执行权限 13 | * 将[conf/redis.conf](conf/redis.conf)文件拷贝至/etc/zabbix/zabbix_agentd.d/目录下,并重启zabbix agent 14 | 15 | #### Zabbix Server 16 | * 导入[templates/redis.xml](templates/redis.xml)模板,并关联对应主机 17 | 18 | #### 效果图 19 | * CPU效果图 20 | 21 | ![redis-cpu](redis-cpu-snapshot.jpg) 22 | 23 | * 连接效果图 24 | 25 | ![redis-connection](redis-connection-snapshot.jpg) 26 | 27 | * 已存储的items效果图 28 | 29 | ![redis-items-stored](redis-items-stored-snapshot.jpg) 30 | 31 | 32 | * 内存使用效果图 33 | 34 | ![redis-memory](redis-memory-snapshot.jpg) 35 | 36 | 37 | * 请求状态效果图 38 | 39 | ![redis-request](redis-request-snapshot.jpg) 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | [Redis]: http://redis.io/ 55 | -------------------------------------------------------------------------------- /redis/conf/redis.conf: -------------------------------------------------------------------------------- 1 | #Redis 2 | UserParameter=redis[*],/etc/zabbix/scripts/redis-status.sh $1 $2 $3 3 | -------------------------------------------------------------------------------- /redis/redis-connection-snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/redis/redis-connection-snapshot.jpg -------------------------------------------------------------------------------- /redis/redis-cpu-snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/redis/redis-cpu-snapshot.jpg -------------------------------------------------------------------------------- /redis/redis-items-stored-snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/redis/redis-items-stored-snapshot.jpg -------------------------------------------------------------------------------- /redis/redis-memory-snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/redis/redis-memory-snapshot.jpg -------------------------------------------------------------------------------- /redis/redis-request-snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengyao/zabbix/9167bfe71a30c9f761a2fb414ab62e102e5df745/redis/redis-request-snapshot.jpg -------------------------------------------------------------------------------- /redis/scripts/redis-status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Redis status 4 | 5 | METRIC="$2" 6 | SERV="$1" 7 | DB="$3" 8 | 9 | PORT="16379" 10 | 11 | if [[ -z "$1" ]]; then 12 | echo "Please set server" 13 | exit 1 14 | fi 15 | 16 | CACHETTL="55" 17 | CACHE="/tmp/redis-status-`echo $SERV | md5sum | cut -d" " -f1`.cache" 18 | 19 | if [ -s "$CACHE" ]; then 20 | TIMECACHE=`stat -c"%Z" "$CACHE"` 21 | else 22 | TIMECACHE=0 23 | fi 24 | 25 | TIMENOW=`date '+%s'` 26 | 27 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 28 | (echo -en "INFO\r\n"; sleep 1;) | nc $SERV $PORT > $CACHE || exit 1 29 | fi 30 | 31 | FIRST_ELEMENT=1 32 | function json_head { 33 | printf "{"; 34 | printf "\"data\":["; 35 | } 36 | 37 | function json_end { 38 | printf "]"; 39 | printf "}"; 40 | } 41 | 42 | function check_first_element { 43 | if [[ $FIRST_ELEMENT -ne 1 ]]; then 44 | printf "," 45 | fi 46 | FIRST_ELEMENT=0 47 | } 48 | 49 | function databse_detect { 50 | json_head 51 | for dbname in $LIST_DATABSE 52 | do 53 | local dbname_t=$(echo $dbname| sed 's!\n!!g') 54 | check_first_element 55 | printf "{" 56 | printf "\"{#DBNAME}\":\"$dbname_t\"" 57 | printf "}" 58 | done 59 | json_end 60 | } 61 | 62 | case $METRIC in 63 | 'redis_version') 64 | cat $CACHE | grep "redis_version:" | cut -d':' -f2 65 | ;; 66 | 'redis_git_sha1') 67 | cat $CACHE | grep "redis_git_sha1:" | cut -d':' -f2 68 | ;; 69 | 'redis_git_dirty') 70 | cat $CACHE | grep "redis_git_dirty:" | cut -d':' -f2 71 | ;; 72 | 'redis_mode') 73 | cat $CACHE | grep "redis_mode:" | cut -d':' -f2 74 | ;; 75 | 'arch_bits') 76 | cat $CACHE | grep "arch_bits:" | cut -d':' -f2 77 | ;; 78 | 'multiplexing_api') 79 | cat $CACHE | grep "multiplexing_api:" | cut -d':' -f2 80 | ;; 81 | 'gcc_version') 82 | cat $CACHE | grep "gcc_version:" | cut -d':' -f2 83 | ;; 84 | 'uptime_in_seconds') 85 | cat $CACHE | grep "uptime_in_seconds:" | cut -d':' -f2 86 | ;; 87 | 'lru_clock') 88 | cat $CACHE | grep "lru_clock:" | cut -d':' -f2 89 | ;; 90 | 'connected_clients') 91 | cat $CACHE | grep "connected_clients:" | cut -d':' -f2 92 | ;; 93 | 'client_longest_output_list') 94 | cat $CACHE | grep "client_longest_output_list:" | cut -d':' -f2 95 | ;; 96 | 'client_biggest_input_buf') 97 | cat $CACHE | grep "client_biggest_input_buf:" | cut -d':' -f2 98 | ;; 99 | 'used_memory') 100 | cat $CACHE | grep "used_memory:" | cut -d':' -f2 101 | ;; 102 | 'used_memory_peak') 103 | cat $CACHE | grep "used_memory_peak:" | cut -d':' -f2 104 | ;; 105 | 'mem_fragmentation_ratio') 106 | cat $CACHE | grep "mem_fragmentation_ratio:" | cut -d':' -f2 107 | ;; 108 | 'loading') 109 | cat $CACHE | grep "loading:" | cut -d':' -f2 110 | ;; 111 | 'changes_since_last_save') 112 | cat $CACHE | grep "changes_since_last_save:" | cut -d':' -f2 113 | ;; 114 | 'bgsave_in_progress') 115 | cat $CACHE | grep "bgsave_in_progress:" | cut -d':' -f2 116 | ;; 117 | 'bgrewriteaof_in_progress') 118 | cat $CACHE | grep "bgrewriteaof_in_progress:" | cut -d':' -f2 119 | ;; 120 | 'aof_enabled') 121 | cat $CACHE | grep "aof_enabled:" | cut -d':' -f2 122 | ;; 123 | 'aof_rewrite_scheduled') 124 | cat $CACHE | grep "aof_rewrite_scheduled:" | cut -d':' -f2 125 | ;; 126 | 'total_connections_received') 127 | cat $CACHE | grep "total_connections_received:" | cut -d':' -f2 128 | ;; 129 | 'total_commands_processed') 130 | cat $CACHE | grep "total_commands_processed:" | cut -d':' -f2 131 | ;; 132 | 'instantaneous_ops_per_sec') 133 | cat $CACHE | grep "instantaneous_ops_per_sec:" | cut -d':' -f2 134 | ;; 135 | 'blocked_clients') 136 | cat $CACHE | grep "blocked_clients:" | cut -d':' -f2 137 | ;; 138 | 'expired_keys') 139 | cat $CACHE | grep "expired_keys:" | cut -d':' -f2 140 | ;; 141 | 'evicted_keys') 142 | cat $CACHE | grep "evicted_keys:" | cut -d':' -f2 143 | ;; 144 | 'keyspace_hits') 145 | cat $CACHE | grep "keyspace_hits:" | cut -d':' -f2 146 | ;; 147 | 'keyspace_misses') 148 | cat $CACHE | grep "keyspace_misses:" | cut -d':' -f2 149 | ;; 150 | 'pubsub_channels') 151 | cat $CACHE | grep "pubsub_channels:" | cut -d':' -f2 152 | ;; 153 | 'pubsub_patterns') 154 | cat $CACHE | grep "pubsub_patterns:" | cut -d':' -f2 155 | ;; 156 | 'latest_fork_usec') 157 | cat $CACHE | grep "latest_fork_usec:" | cut -d':' -f2 158 | ;; 159 | 'role') 160 | cat $CACHE | grep "role:" | cut -d':' -f2 161 | ;; 162 | 'connected_slaves') 163 | cat $CACHE | grep "connected_slaves:" | cut -d':' -f2 164 | ;; 165 | 'used_cpu_sys') 166 | cat $CACHE | grep "used_cpu_sys:" | cut -d':' -f2 167 | ;; 168 | 'used_cpu_user') 169 | cat $CACHE | grep "used_cpu_user:" | cut -d':' -f2 170 | ;; 171 | 'used_cpu_sys_children') 172 | cat $CACHE | grep "used_cpu_sys_children:" | cut -d':' -f2 173 | ;; 174 | 'used_cpu_user_children') 175 | cat $CACHE | grep "used_cpu_user_children:" | cut -d':' -f2 176 | ;; 177 | 'key_space_db_keys') 178 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $1}'|cut -d'=' -f2 179 | ;; 180 | 'key_space_db_expires') 181 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $2}'|cut -d'=' -f2 182 | ;; 183 | 'list_key_space_db') 184 | LIST_DATABSE=`cat $CACHE | grep '^db.:'|cut -d: -f1` 185 | databse_detect 186 | ;; 187 | 'expires') 188 | cat $CACHE | grep "db" | cut -d',' -f2 | cut -d'=' -f2 189 | ;; 190 | 'keys') 191 | cat $CACHE | grep "db" | cut -d',' -f1 | cut -d'=' -f2 192 | ;; 193 | *) 194 | echo "Not selected metric" 195 | exit 0 196 | ;; 197 | esac 198 | -------------------------------------------------------------------------------- /redis/templates/redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-05-30T05:31:06Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 928 | 929 | 930 | 931 | {Redis:net.tcp.port[127.0.0.1,{$PORT}].last(0)}=0 932 | Redis is down on {HOSTNAME} 933 | 934 | 0 935 | 4 936 | 937 | 0 938 | 939 | 940 | 941 | 942 | 943 | Redis Connections Client 944 | 800 945 | 150 946 | 0.0000 947 | 100.0000 948 | 1 949 | 1 950 | 0 951 | 1 952 | 0 953 | 0.0000 954 | 0.0000 955 | 0 956 | 0 957 | 0 958 | 0 959 | 960 | 961 | 0 962 | 1 963 | 009999 964 | 1 965 | 2 966 | 0 967 | 968 | Redis 969 | redis[connected_clients,{$PORT}] 970 | 971 | 972 | 973 | 974 | 975 | Redis CPU Usage 976 | 800 977 | 150 978 | 0.0000 979 | 100.0000 980 | 1 981 | 1 982 | 0 983 | 1 984 | 0 985 | 0.0000 986 | 0.0000 987 | 0 988 | 0 989 | 0 990 | 0 991 | 992 | 993 | 0 994 | 1 995 | AFECED 996 | 1 997 | 2 998 | 0 999 | 1000 | Redis 1001 | redis[used_cpu_user_children,{$PORT}] 1002 | 1003 | 1004 | 1005 | 1 1006 | 5 1007 | 784890 1008 | 1 1009 | 2 1010 | 0 1011 | 1012 | Redis 1013 | redis[used_cpu_user,{$PORT}] 1014 | 1015 | 1016 | 1017 | 2 1018 | 5 1019 | 907890 1020 | 1 1021 | 2 1022 | 0 1023 | 1024 | Redis 1025 | redis[used_cpu_sys_children,{$PORT}] 1026 | 1027 | 1028 | 1029 | 3 1030 | 5 1031 | FF7F00 1032 | 1 1033 | 2 1034 | 0 1035 | 1036 | Redis 1037 | redis[used_cpu_sys,{$PORT}] 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | Redis Items Stored 1044 | 800 1045 | 150 1046 | 0.0000 1047 | 100.0000 1048 | 1 1049 | 1 1050 | 0 1051 | 1 1052 | 0 1053 | 0.0000 1054 | 0.0000 1055 | 0 1056 | 0 1057 | 0 1058 | 0 1059 | 1060 | 1061 | 0 1062 | 1 1063 | AAAA00 1064 | 1 1065 | 2 1066 | 0 1067 | 1068 | Redis 1069 | redis[keys,{$PORT}] 1070 | 1071 | 1072 | 1073 | 1 1074 | 0 1075 | 00BBBB 1076 | 1 1077 | 2 1078 | 0 1079 | 1080 | Redis 1081 | redis[expires,{$PORT}] 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | Redis Memory 1088 | 800 1089 | 150 1090 | 0.0000 1091 | 100.0000 1092 | 1 1093 | 1 1094 | 0 1095 | 1 1096 | 0 1097 | 0.0000 1098 | 0.0000 1099 | 0 1100 | 0 1101 | 0 1102 | 0 1103 | 1104 | 1105 | 0 1106 | 0 1107 | 008888 1108 | 1 1109 | 2 1110 | 0 1111 | 1112 | Redis 1113 | redis[used_memory,{$PORT}] 1114 | 1115 | 1116 | 1117 | 1 1118 | 0 1119 | 0000C8 1120 | 1 1121 | 2 1122 | 0 1123 | 1124 | Redis 1125 | redis[used_memory_peak,{$PORT}] 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | Redis Requests/sec (commands/connections) 1132 | 800 1133 | 150 1134 | 0.0000 1135 | 100.0000 1136 | 1 1137 | 1 1138 | 0 1139 | 1 1140 | 0 1141 | 0.0000 1142 | 0.0000 1143 | 0 1144 | 0 1145 | 0 1146 | 0 1147 | 1148 | 1149 | 0 1150 | 0 1151 | 660000 1152 | 1 1153 | 2 1154 | 0 1155 | 1156 | Redis 1157 | redis[total_commands_processed,{$PORT}] 1158 | 1159 | 1160 | 1161 | 1 1162 | 0 1163 | 880088 1164 | 1 1165 | 2 1166 | 0 1167 | 1168 | Redis 1169 | redis[total_connections_received,{$PORT}] 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | --------------------------------------------------------------------------------