监控CPU负载、Nginx、TCP、PHP、Memcached、Redis、Mysql、Tomcat

监控CPU负载

Agent端:

[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf

UserParameter=cpu_load1,/usr/bin/w|awk 'NR==1 {print $10}'|awk -F, '{print $1}'

UserParameter=cpu_load5,/usr/bin/w|awk 'NR==1 {print $11}'|awk -F, '{print $1}'

UserParameter=cpu_load15,/usr/bin/w|awk 'NR==1 {print $12}'

Server端:

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k cpu_load1

0.00

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k cpu_load5

0.01

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k cpu_load15

0.05

Step1(配置-->模板-->创建模板):

Step2(创建克隆监控项):

Step3(创建克隆触发器):

Step4(创建图形):

Step5(添加模板如下图):

ab压测使CPU有波动

Server端:

[[email protected] ~]# yum install -y httpd-tools

[[email protected] ~]# ab -n 10000 -c 100 http://10.0.0.101/index

Agent端:

[[email protected] ~]# yum install -y httpd

[[email protected] ~]# systemctl start httpd

[[email protected] ~]# vim /var/www/html/index.html

[[email protected] ~]# curl --head http://10.0.0.101/index.html

监控Nginx服务

Agent端:

[[email protected] ~]#  vim /etc/yum.repos.d/nginx.repo

[[email protected] ~]#  cat /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/x86_64/

gpgcheck=0

enabled=1

[[email protected] ~]#  rpm -qa | grep centos-release

centos-release-7-4.1708.el7.centos.x86_64

[[email protected] ~]# yum install -y nginx

[[email protected] ~]# systemctl start nginx  ##启动前查看是否有其他服务占用80端口(Apache)

[[email protected] ~]# netstat -lntup|grep nginx

tcp        0      0 0.0.0.0:80      0.0.0.0:*         LISTEN      76182/nginx: master

[[email protected] ~]# vim /etc/nginx/conf.d/default.conf

location /nginx_status {

stub_status on;

access_log off;

allow 127.0.0.1;

deny all;

}

[[email protected] ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

浏览器查看http://10.0.0.101/nginx_status或者

[[email protected] ~]# curl http://10.0.0.101/nginx_status

Active connections: 2

server accepts handled requests

123 123 129

Reading: 0 Writing: 1 Waiting: 1

[[email protected] ~]# mkdir -p /etc/zabbix/scripts

[[email protected] ~]# cd /etc/zabbix/scripts

[[email protected] scripts]# vim nginx_status.sh

#!/bin/bash

############################################################

# $Name:       zabbix_linux_plugins.sh

# $Version:      v1.0

# $Function:     zabbix plugins

# $Author:       Andy

# $organization: http://blog.51cto.com/13162375

# $Create Date:  2018-5-18

# $Description:  Monitor Linux Service Memcached Status

############################################################

if [ $# -ne 1 ];then

echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"

exit 1

Fi

NGINX_CMD=$1

NGINX_PORT=80

nginx_active(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'

}

nginx_reading(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'

}

nginx_writing(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'

}

nginx_waiting(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'

}

nginx_accepts(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'

}

nginx_handled(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'

}

nginx_requests(){

/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'

}

case $NGINX_CMD in

active)

nginx_active

;;

reading)

nginx_reading

;;

writing)

nginx_writing

;;

waiting)

nginx_waiting

;;

accepts)

nginx_accepts

;;

handled)

nginx_handled

;;

requests)

nginx_requests

;;

*)

echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"

esac

[[email protected] scripts]# chmod +x nginx_status.sh

[[email protected] scripts]# systemctl restart zabbix-agent

[[email protected] scripts]# cd /etc/zabbix/zabbix_agentd.d

[[email protected] zabbix_agentd.d]# vim nginx_status.conf

[[email protected] zabbix_agentd.d]# cat nginx_status.conf

UserParameter=nginx_status[*],/bin/bash /etc/zabbix/scripts/nginx_status.sh "$1"

Server端检测:

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k nginx_status[accepts]

177

Step1(配置-->模板-->创建模板):

Step2(添加克隆监控项):

Step3(添加触发器):

Add部分

Step4(添加图形):

Step5(为主机添加模板):

监控TCP信息状态

Agent端:

[[email protected] ~]# cd /etc/zabbix/scripts/

[[email protected] scripts]#vim tcp_status.sh

[[email protected] scripts]# chmod +x tcp_status.sh

[[email protected] scripts]# sh -x tcp_status.sh ESTAB  ##测试脚本

+ '[' 1 -ne 1 ']'

+ tcp_status_fun ESTAB

+ TCP_STAT=ESTAB

+ ss -ant

+ awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}'

++ grep ESTAB /tmp/ss.txt

++ cut -d ' ' -f2

+ TCP_STAT_VALUE=1

+ '[' -z 1 ']'

+ echo 1

1

[[email protected] zabbix_agentd.d]# vim tcp_status.conf

[[email protected] zabbix_agentd.d]# cat tcp_status.conf

UserParameter=tcp_status[*],/bin/bash /etc/zabbix/scripts/tcp_status.sh "$1"

[[email protected] zabbix_agentd.d]# systemctl restart zabbix-agent

Server端

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k tcp_status[ESTAB] ##出现这种错误到客户端删掉/opt/ss.txt文件

/etc/zabbix/scripts/tcp_status.sh: line 18: /tmp/ss.txt: Permission denied

2

[[email protected] ~]# zabbix_get -s 10.0.0.101 -k tcp_status[ESTAB]  ##检验键值

2

Step1(创建模板):

Step2(创建克隆监控项):

Step3(创建图形):

Step4(关联主机):

中文字符集乱码问题

[[email protected] ~]# cd /usr/share/zabbix/fonts/

[[email protected] fonts]# rz simkai.ttf

[[email protected] fonts]# vim /usr/share/zabbix/include/defines.inc.php  ##修改两处

#define('ZBX_FONT_NAME', 'graphfont');

define('ZBX_FONT_NAME', 'simkai');

#define('ZBX_GRAPH_FONT_NAME',          'graphfont'); // font file name

define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name

[[email protected] fonts]# systemctl restart zabbix-server

监控php-fpm状态

Agent端:

[[email protected] ~]# yum install -y php php-fpm

[[email protected] ~]# systemctl start php-fpm

[[email protected] ~]# netstat -lntup|grep 9000

tcp      0    0 127.0.0.1:9000   0.0.0.0:*     LISTEN      64086/php-fpm: mast

[[email protected] ~]# vim /etc/nginx/conf.d/default.conf

location ~ \.php$ {

root           /usr/share/nginx/html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

include        fastcgi_params;

}

[[email protected] ~]# vim /usr/share/nginx/html/index.php

<?php

phpinfo();

?>

浏览器http://10.0.0.101/index.php能否成功

[[email protected] ~]# vim /etc/php-fpm.d/www.conf

pm.status_path = /phpfpm_status

[[email protected] ~]# systemctl restart php-fpm

[[email protected] ~]# vim /etc/nginx/conf.d/default.conf

location ~ ^/(phpfpm_status)$ {

include fastcgi_params;

fastcgi_pass    127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

[[email protected] ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

浏览器http://10.0.0.101/phpfpm_status或者curl http://10.0.0.101/phpfpm_status

[[email protected] ~]# curl  http://10.0.0.101/phpfpm_status

pool:                 www

process manager:      dynamic

start time:          16/May/2018:19:33:39 +0800

start since:         462

accepted conn:       7

listen queue:        0

max listen queue:     0

listen queue len:     128

idle processes:       4

active processes:     1

total processes:      5

max active processes: 1

max children reached: 0

slow requests:        0

[[email protected] ~]# curl -s http://10.0.0.101/phpfpm_status|awk '/accepted conn:/ {print $NF}'

7

[[email protected] ~]# cd /etc/zabbix/scripts

[[email protected] scripts]# vim phpfpm_status.sh

[[email protected] scripts]# chmod +x phpfpm_status.sh

[[email protected] scripts]# cd ..

[[email protected] zabbix]# cd zabbix_agentd.d/

[[email protected] zabbix_agentd.d]# vim phpfpm_status.conf

UserParameter=phpfpm_status[*],/bin/bash /etc/zabbix/scripts/phpfpm_status.sh "$1"

[[email protected] ~]# systemctl restart zabbix-agent

Server端:

[[email protected] zabbix]# zabbix_get -s 10.0.0.101 -k phpfpm_status[accepted_conn]

20

Step1(创建模板):

Step2(关联主机):

监控mysql

Agent端:

[[email protected] ~]# yum install -y mariadb-server

[[email protected] ~]# systemctl start mariadb

[[email protected] ~]# netstat -lntup|grep 3306

tcp        0      0 0.0.0.0:3306    0.0.0.0:*           LISTEN      31688/mysqld

[[email protected] ~]# yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm

[[email protected] ~]# rpm -ql percona-release

/etc/pki/rpm-gpg/RPM-GPG-KEY-Percona

/etc/yum.repos.d/percona-release.repo

/usr/share/doc/percona-release-0.1

/usr/share/doc/percona-release-0.1/RPM-GPG-KEY-Percona

[[email protected] ~]# yum install -y percona-zabbix-templates

[[email protected] ~]# rpm -ql percona-zabbix-templates

/var/lib/zabbix/percona

/var/lib/zabbix/percona/scripts

/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh

/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php

/var/lib/zabbix/percona/templates

/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf

/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml

[[email protected] ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php

$mysql_user = 'root';

$mysql_pass = '';

$mysql_port = 3306;

[[email protected] ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/

[[email protected] ~]# systemctl restart zabbix-agent

由于agent端mariadb没有数据,监控也没有值,只能在server端测试

[[email protected] ~]# cd /var/lib/

[[email protected] lib]# scp -r zabbix/ [email protected]:/var/lib/

Server端:

[[email protected] ~]# ls /var/lib/zabbix

Percona

[[email protected] scripts]# zabbix_get -s 10.0.0.102 -k MySQL.Threads-connected

zabbix_get [82941]: Check access restrictions in Zabbix agent configuration

[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=10.0.0.102

[[email protected] scripts]# systemctl restart zabbix-agent

[[email protected] scripts]# zabbix_get -s 10.0.0.102 -k MySQL.Threads-connected

25

剩下就是导入模板和添加主机、关联主机。

监控Redis

Agent端:

[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[[email protected] ~]# yum install -y redis

[[email protected] ~]# systemctl start redis

[[email protected] ~]# redis-cli

127.0.0.1:6379> info

127.0.0.1:6379> quit

[[email protected] ~]# cd /etc/zabbix/scripts/

[[email protected] scripts]# vim redis_status.sh

[[email protected] scripts]# chmod +x redis_status.sh

[[email protected] scripts]# cd /etc/zabbix/zabbix_agentd.d/

[[email protected] zabbix_agentd.d]# vim redis_status.conf

UserParameter=redis_status[*],/bin/bash /etc/zabbix/scripts/redis_status.sh "$1"

[[email protected] zabbix_agentd.d]# systemctl restart zabbix-agent

Server端:

[[email protected] scripts]# zabbix_get -s 10.0.0.101 -k redis_status[used_cpu_sys]

0.10

剩下就是导入模板和添加主机、关联主机。

监控Memcached

Agent端:

[[email protected] ~]# yum install -y memcached

[[email protected] ~]# systemctl start memcached

[[email protected] ~]# netstat -lntup|grep 11211

tcp        0      0 0.0.0.0:11211     0.0.0.0:*          LISTEN      58548/memcached

tcp6       0      0 :::11211           :::*           LISTEN      58548/memcached

udp       0      0 0.0.0.0:11211       0.0.0.0:*                    58548/memcached

udp6      0      0 :::11211             :::*                      58548/memcached

[[email protected] ~]# mkdir -p /etc/zabbix/scripts

[[email protected] ~]# cd /etc/zabbix/scripts/

[[email protected] scripts]# vim memcached_status.sh

[[email protected] scripts]# chmod +x memcached.sh

[[email protected] scripts]# cd /etc/zabbix/zabbix_agentd.d/

[[email protected] zabbix_agentd.d]# vim memcache_status.conf

[[email protected] zabbix_agentd.d]# cat memcache_status.conf

UserParameter=memcached_status[*],/bin/bash /etc/zabbix/scripts/memcached_status.sh "$1"

Server端:

[[email protected] ~]# zabbix_get -s 10.0.0.103 -k memcached_status[pid]

58548

[[email protected] ~]# zabbix_get -s 10.0.0.103 -k memcached_status[curr_connections]

10

剩下就是导入模板和添加主机、关联主机。

监控Tomcat

tomcat端:

[[email protected] package]# rz apache-tomcat-9.0.8.tar.gz

[[email protected] package]# tar xf apache-tomcat-9.0.8.tar.gz -C /application/

[[email protected] package]# cd ..

[[email protected] application]# ln -s /application/apache-tomcat-9.0.8/ /application/apache-tomcat

[[email protected] application]# ll

total 0

lrwxrwxrwx 1 root root  33 May 18 23:51 apache-tomcat -> /application/apache-tomcat-9.0.8/

drwxr-xr-x 9 root root 160 May 18 23:50 apache-tomcat-9.0.8

drwxr-xr-x 2 root root  40 May 18 23:47 package

[[email protected] application]# yum install -y java

[[email protected] application]# cd apache-tomcat/bin/

[[email protected] bin]# ./startup.sh

Using CATALINA_BASE:   /application/apache-tomcat

Using CATALINA_HOME:   /application/apache-tomcat

Using CATALINA_TMPDIR: /application/apache-tomcat/temp

Using JRE_HOME:        /usr

Using CLASSPATH:    /application/apache-tomcat/bin/bootstrap.jar:/application/apache-tomcat/bin/tomcat-juli.jar

Tomcat started.

[[email protected] bin]# netstat -lntup|grep java

tcp6       0      0 :::8080           :::*            LISTEN      68252/java

tcp6       0      0 127.0.0.1:8005      :::*             LISTEN      68252/java

tcp6       0      0 :::8009           :::*             LISTEN      68252/java

[[email protected] bin]# vim catalina.sh

CATALINA_OPTS="$CATALINA_OPTS

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=12345

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.103"

[[email protected] bin]# ./shutdown.sh

[[email protected] bin]# ./startup.sh

[[email protected] bin]# netstat -lntup|grep java

tcp6       0      0 :::39246        :::*            LISTEN      68696/java

tcp6       0      0 :::8080         :::*            LISTEN      68696/java

tcp6       0      0 :::12345        :::*            LISTEN      68696/java

tcp6       0      0 :::33370        :::*            LISTEN      68696/java

tcp6       0      0 127.0.0.1:8005    :::*            LISTEN      68696/java

tcp6       0      0 :::8009        :::*             LISTEN      68696/java

Zabbix-java-gateway端:

[[email protected] ~]# yum install -y zabbix-java-gateway java-1.8.0-openjdk

[[email protected] ~]# systemctl start zabbix-java-gateway

[[email protected] ~]# netstat -lntup|grep java

tcp6       0      0 :::10052       :::*        LISTEN      6934/java

Zabbix-Server端:

[[email protected] ~]# vim /etc/zabbix/zabbix_server.conf

JavaGateway=10.0.0.101

StartJavaPollers=5

[[email protected] ~]# systemctl restart zabbix-server

Step1(配置-->主机-->创建主机):

Step2(添加主机-->添加模板):

Step3:

原文地址:http://blog.51cto.com/13162375/2118472

时间: 2024-10-26 18:02:59

监控CPU负载、Nginx、TCP、PHP、Memcached、Redis、Mysql、Tomcat的相关文章

nginx+play framework +mongoDB+redis +mysql+LBS实战总结

nginx+play framework +mongoDB+redis +mysql+LBS实战总结(一) 使用这个样的组合结构已经很久了,主要是实现web-server,不是做网站,二是纯粹的数据服务server.早就想总结一下,一直没有时间,最近也是一而再再而三的解决了使用途中的各种问题,从此片开始到之后悔慢慢的将这些经验教训总结下来,一边自己和朋友们借鉴使用.此片算是开篇吧,首先对这几种技术或者说平台做简单的介绍吧,顺便推荐一些文章给大家. nginx:本身是一个web server ,在

CentOS7.5 下zabbix3.0.18监控CPU负载

大纲: 一.环境准备 二.创建主机 三.创建监控项 四.查看监控流量图 一.环境准备 服务器1: IP:192.168.4.66,操作系统:CentOS 7.5 应用程序:zabbix-server-mysql-3.0.18 服务器2: IP:192.168.4.58,操作系统:CentOS 6.8 应用程序:zabbix-agent-3.0.18 二.创建主机 zabbix服务器上操作: 2.1.创建主机: 单击创建主机,创建主机:node1.com ,群组:OA server, agent代

zabbix管理四之监控cpu的负载

监控cpu的负载 分析: 安装完zabbix后,在Template OS Linux这个模板下面默认有监控cpu负载的触发器,但是这个默认的触发器是以cpu负载的个数为触发值的,由于agent客户机每台的cpu核数是不一样的,所以,以负载的个数为触发值不是很好,下面我设置的触发值是cpu负载占cpu核数的百分比 步骤: 1.(agent端) mkdir -p /etc/zabbix/itemscripts         (创建一个脚本目录,所有的zabbix agent的脚本都放在这里,方便管

nginx的worker进程挂起且某个CPU负载达到100%

nginx的worker进程挂起且某个CPU负载达到100% 场景说明: #tcp连接状态 [[email protected] ~]# netstat -nat |awk '{print   $6}'|grep -v 'Foreign'|grep -v 'established)'|sort|uniq -c|sort -rn 3010 TIME_WAIT 537 ESTABLISHED 65 SYN_RECV 45 FIN_WAIT2 20 CLOSE_WAIT 18 FIN_WAIT1 9

centos7下搭建nginx+php7.1+mariadb+memcached+redis

一.环境准备 1.首先介绍一下环境,以及我们今天的主角们 我用的环境是最小化安装的centos7,mariadb(江湖传言mysql被oracle收购后,人们担心像java一样毁在oracle手上于是成了新的分支,但是还是像mysql一样用), php7.1.0(版本无所谓,都是7版本),nginx1.10(我们安装的是稳定版而没有一味的追求新),memcached,和redis可以随机选择一个,当然全安装也没有干扰 2.软件包下载 1)mariadb软件包(yum安装,编译安装因为boost问

监控系统负载与CPU、内存、硬盘、登录用户数,超出警戒值则发邮件告警。

[email protected]:~$ cat warning.sh #!/bin/bash #监控系统负载与CPU.内存.硬盘.登录用户数,超出警戒值则发邮件告警.    前提安装mail服务  [email protected] #提取本服务器的IP地址信息 IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`    # 1.监控系统负载的变化情况

memcached&amp;redis性能测试

转自:http://www.iigrowing.cn/memcached-redis-xing-neng-ce-shi.html 一.Memcached 1.1.memcached简介 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态.数据库驱动网站的速度.Memcached基于一个存储键/值对的hashmap.其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通

使用snmp+mrtg监控CPU、流量、磁盘空间、内存

1.安装snmp rpm -qa|grep snmp* //查看是否安装了snmpyum -y install snmp* //安装snmp #vim /etc/snmp/snmpd.confrocommunity public //配置snmpv1模式disk / 13102744 //配置系统的大小disk /data 41279536 //配置数据盘的大小 service snmpd start //配置开启snmpchkconfig snmpd on //设置开机启动 2.安装mrtg

Linux CentOS搭建JDK+Mysql+Tomcat+Nginx负载均衡环境 &nbsp; &nbsp; &nbsp;

本文使用了Tomcat+Nginx环境,主要起到负载均衡的作用,使用Tomcat处理jsp后台程序,使用Nginx处理静态页面. 准备工作(下载软件版本,请自行百度下载) 安装包放至:/usr/local/src 安装地址:/usr/local/软件名 1.apache-tomcat-6.0.48 2.mysql-5.5.54 3.nginx-1.6.3 4.cmake-2.8.8 5.pcre-8.40 6.jdk-8u11-linux-x64 7.openssl-1.1.0d(https使用