深圳龙岗网站维护,怎么做旅游网站,司局网站维护廉政风险建设,网络营销服务策略目录 监控查看性能相关命令Prometheus1、安装和配置2、将 NFS服务器和LB服务器作为exporter采集数据3、在prometheus server里添加安装exporter程序的服务器 grafana出图工具 监控
监控的目的是获取数据#xff0c;通过数据分析了解机器是否正常运行
查看性能相关命令 查看c… 目录 监控查看性能相关命令Prometheus1、安装和配置2、将 NFS服务器和LB服务器作为exporter采集数据3、在prometheus server里添加安装exporter程序的服务器 grafana出图工具 监控
监控的目的是获取数据通过数据分析了解机器是否正常运行
查看性能相关命令 查看cpu详细信息 lscpu 、 cat /proc/cpuinfo 查看CPU使用率 top 一行一个进程默认以CPU使用率排序 %Cpu(s): 0.2 us, 0.3 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st当mysqld进程进行读写操作大多时候调用系统调用如read()、write()、fork()等系统调用就是操作系统给其他应用程序的接口也就是实现某个功能的程序 us用户空间User SpaceCPU使用率表示用户进程所占用的CPU时间百分比。sy系统空间System SpaceCPU使用率表示内核进程所占用的CPU时间百分比。ninice值Nice ValueCPU使用率表示以较低优先级运行的进程所占用的CPU时间百分比。id空闲IdleCPU时间百分比表示CPU处于空闲状态的时间百分比。wa等待WaitCPU时间百分比表示CPU等待I/O操作完成的时间百分比。hi硬中断Hardware InterruptCPU时间百分比表示处理硬件中断的时间百分比。si软中断Software InterruptCPU时间百分比表示处理软件中断的时间百分比。st偷取StealCPU时间百分比表示虚拟机如果在虚拟化环境中运行被物理主机偷取的CPU时间百分比。 top交互命令 htop 命令 yum install epel-release -y
yum install htopz在top命令的输出中看到系统的负载平均值 top - 10:13:26 up 19:20, 2 users, load average: 0.00, 0.02, 0.05Load Average 显示在 load average: 后面的三个数字分别是 1 分钟、5 分钟和 15 分钟的平均负载 系统平均负载是指过去的1分钟5分钟15分钟处于可运行或就绪或阻塞或不可中断的进程的平均数量 假如系统有n个核心这个平均数量超过n就说明系统比较繁忙了但如果不超过5n就说明还没有达到最忙的时候 查看内存使用情况 free -m ,默认以kb为单位接-m以M为单位 [rootlb-2 keepalived]# free -mtotal used free shared buff/cache available
Mem: 1819 240 1270 9 308 1419
Swap: 2047 0 2047Men 物理内存即内存条的大小 Swap 交换分区的内存大小交换分区是从磁盘里划分出来的一块空间临时做内存使用的当物理内存不足的时候将不活跃的进程交换到swap分区里。但由于交换分区速度慢尽量不使用 [rootlb-2 keepalived]# cat /proc/sys/vm/swappiness
30
# 当物理内存只剩下30%的时候开始使用交换分区临时修改为0%
echo 0 /proc/sys/vm/swappiness total物理内存的总量 used已用内存的总量。已用内存是当前被系统和应用程序使用的内存。 free可用内存的总量。可用内存是当前未被使用的内存可以用于新的进程和应用程序。 shared共享内存的总量。共享内存是被多个进程共享的内存区域。在这里共享内存为9 MB。 buff/cache用于缓存的内存总量。这包括用于文件系统缓存和磁盘I/O缓存的内存。buff内存的数据读取到磁盘的时候先写到buffer里等buffer满了再写到磁盘减少IO读写次数。cache磁盘的数据读取到内存的时候先写在cache里提升速度。 available下一个进程可用内存的估计总量。这是系统根据当前内存使用情况和缓存来估计的可用内存量。 available free buff/cache里的未使用完的空间 查看网络流量 dstat 、 iptraf 、 glances dstat [rootlb-2 keepalived]# dstatYou did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw 0 0 100 0 0 0|4124B 1644B| 0 0 | 0 0 | 101 134 1 1 99 0 0 0| 0 0 | 180B 1024B| 0 0 | 139 161 0 1 99 0 0 0| 0 0 | 120B 398B| 0 0 | 141 174 1 1 99 0 0 0| 0 0 | 120B 398B| 0 0 | 121 145 [rootlb-2 keepalived]# dstat -N ens33
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/ens33- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw 0 0 100 0 0 0|4122B 1692B| 0 0 | 0 0 | 101 134 0 0 99 0 0 0| 0 0 | 120B 878B| 0 0 | 123 157 0 0 100 0 0 0| 0 0 | 120B 398B| 0 0 | 132 160 [rootlb-2 keepalived]# dstat -N ens33,total -am
----total-cpu-usage---- -dsk/total- -net/ens33---net/total- ---paging-- ---system-- ------memory-usage-----
usr sys idl wai hiq siq| read writ| recv send: recv send| in out | int csw | used buff cach free0 0 100 0 0 0|4113B 1695B| 0 0 : 0 0 | 0 0 | 101 134 | 309M 2108k 306M 1202M0 0 100 0 0 0| 0 0 | 120B 1214B: 120B 1214B| 0 0 | 125 157 | 310M 2108k 306M 1201M1 1 99 0 0 0| 0 0 | 120B 534B: 120B 534B| 0 0 | 123 155 | 310M 2108k 306M 1201M glances iftop iptraf 也可以抓包 nethogs
Prometheus
Prometheus开源的监控软件
其他监控软件 cacti仙人掌。出图比较好 nagios监控脚本多 zabbix集合cacti和nagios的优点 openfalcon小米公司开元的监控软件
组件 1、tsdb时序数据库time series database。 2、http serverweb服务 3、push gateway中间件代理 4、altermanager告警软件 5、exporter收集数据采集数据
出图工具grafana – 展示数据
1、安装和配置 在监控服务器192.168.232.166上编译安装 首先在官网上下载源码包https://prometheus.io/download/ 将下载好的源码包传到监控服务器解压 临时和永久修改PATH变量添加prometheus路径 PATH/prom/prometheus:$PATH
[rootprometheus prometheus]# cat /root/.bashrc
# .bashrc# User specific aliases and functionsalias rmrm -i
alias cpcp -i
alias mvmv -i# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi
PATH/prom/prometheus:$PATH # 添加的信息启动prometheus服务并让他在后台运行不受到终端关闭的影响Prometheus监听9090端口 nohup prometheus --config.file/prom/prometheus/prometheus.yml 关闭防火墙并设置永久关闭。然后就可以在服务器上输入192.168.232.166:9090看到监控页面了 service firewalld stop
systemctl disable firewalld将源码二进制安装的Prometheus配置成一个服务便于管理 [rootprometheus prometheus]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
Descriptionprometheus
[Service]
ExecStart/prom/prometheus/prometheus --config.file/prom/prometheus/prometheus.yml
ExecReload/bin/kill -HUP $MAINPID
KillModeprocess
Restarton-failure
[Install]
WantedBymulti-user.target# 重新加载systemd相关的服务
[rootprometheus prometheus]# systemctl daemon-reload 将之前使用nohup方式启动的Prometheus服务杀死再使用以下命令开启 service prometheus start容器安装prometheus docker run -d -p 9090:9090 --name sc-prom-1 prom/prometheus2、将 NFS服务器和LB服务器作为exporter采集数据 在官网上下载node节点源码包解压 tar xf node_exporter-1.6.1.linux-amd64.tar.gz
mv node_exporter-1.6.1.linux-amd64 /node_exporter
cd /node_exporter/ 修改PATH变量 PATH/node_exporter/:$PATH[rootlb node_exporter]# cat /root/.bashrc
# .bashrc# User specific aliases and functionsalias rmrm -i
alias cpcp -i
alias mvmv -i# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi
PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/scnginx99/sbin:/usr/local/scnginx99/sbin
PATH/node_exporter/:$PATH 启动exporter服务并让他在后台运行不受到终端关闭的影响自定义exporter监听8090端口 nohup node_exporter --web.listen-address 0.0.0.0:8090 在浏览器上访问node节点上的metrics指标 http://192.168.232.164:8090/metrics3、在prometheus server里添加安装exporter程序的服务器
[rootprometheus prometheus]# pwd
/prom/prometheus
[rootprometheus prometheus]# cat prometheus.yml# The job name is added as a label jobjob_name to any timeseries scraped from this config.- job_name: prometheusstatic_configs:- targets: [localhost:9090]- job_name: LB1static_configs:- targets: [192.168.232.161:8090]- job_name: LB2static_configs:- targets: [192.168.232.165:8090]- job_name: NFSstatic_configs:- targets: [192.168.232.164:8090]
修改完之后记得重启服务
然后再去浏览器查看监控页面就可以看到LB和NFS的相关信息了
grafana出图工具 将grafana和prometheus安装在一台机器上 官网https://dl.grafana.com/enterprise/release/grafana-enterprise-10.1.1-1.x86_64.rpm下载rpm包传入prometheus服务器中 [rootprometheus grafana]# ls
grafana-enterprise-10.1.1-1.x86_64.rpm
[rootprometheus grafana]# yum install grafana-enterprise-10.1.1-1.x86_64.rpm service grafana-server start
systemctl enable grafana-servergrafana监听3000端口 可以在浏览器上访问用户和密码都为 admin 配置prometheus的数据源导入模版 这里输入Prometheus的IP地址和端口号 导入出图模版
好模版编号1860、8919