一、监控linux服务器

1.1 二进制安装

# 客户端操作
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz tar xvf node_exporter-1.7.0.linux-amd64.tar.gz ls -l mv node_exporter-1.7.0.linux-amd64/* /opt/prometheus/node_exporter
useradd -M -s /usr/sbin/nologin prometheus
chown prometheus:prometheus -R /opt/prometheus/node_exporter
# 创建system服务
cat > /etc/systemd/system/node_exporter.service <<"EOF"
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF # 启动服务
systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service
systemctl status node_exporter.service
journalctl -u node_exporter.service -f # 查看日志

服务端操作

# 修改prometheus配置
nano /opt/prometheus/prometheus/prometheus.yml # 再scrape_configs这行下面添加如下配置:
#node-exporter配置
- job_name: 'node-exporter'
scrape_interval: 15s
static_configs:
- targets: ['192.168.10.14:9100']
labels:
instance: test服务器 # 重载prometheus
curl -X POST http://localhost:9090/-/reload

1.2 docker 或docker-compose安装客户端

# docker安装
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter # docker-compose安装
mkdir /data/node_exporter -p cd /data/node_exporter cat > docker-compose.yaml <<"EOF"
version: '3.3'
services:
node_exporter:
image: prom/node-exporter:v1.5.0
container_name: node-exporter
restart: always
network_mode: "host"
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--web.listen-address=:9100'
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- "--path.rootfs=/rootfs"
- '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc|rootfs/var/lib/docker)($$|/)'
EOF # 启动和检查
docker-compose up -d docker ps
或:
docker logs -f node-exporter

http://192.168.10.100:9100/metrics

修改服务端prometheus.yml配置文件

# 增加
- job_name: 'node-exporter'
scrape_interval: 15s
static_configs:
- targets: ['node_exporter:9100']
labels:
instance: Prometheus服务器
- targets: ['192.168.10.100:9100']
labels:
instance: test服务器 # 重载服务端配置
curl -X POST http://localhost:9090/-/reload

二、常用监控指标

查看:http://192.168.10.14:9090/graph

2.1 cpu采集

node_cpu_seconds_total

名称 含义
node_load1 1分钟内cpu负载
node_load5 5分钟内cpu负载
node_load15 15分钟内cpu负载

2.2 内存采集/proc/meminfo文件

node_memory_

node_memory_MemTotal_bytes 内存总大小

node_memory_MemAvailable_bytes 空闲可使用内存大小(=free+buffer+cache)

node_memory_MemFree_bytes 空闲物理内存大小

2.3 磁盘采集

node_disk_

node_disk_read_bytes_total  自exporter启动以来从磁盘读取的总字节数

node_disk_written_bytes_total 自exporter启动以来写入到磁盘的总字节数

2.4 文件系统采集

node_filesystem_avail_bytes 空闲磁盘大小,单位字节  /1024/1024=MB,/1024/1024/1024=GB

node_filesystem_size_bytes 磁盘总大小

node_filesystem_files_free  空inode大小,单位个

node_filesystem_files inode总大小,大卫个

2.5 网络采集

node_network_

node_network_transmit_bytes_total    网络流出流量,单位字节(Byte)/1024/1024=Mb/s

node_network_receive_bytes_tota      网络流入流量,单位字节(Byte)

2.6 文件描述符

node_filefd_allocated: 已分配的文件描述符数。通过cat /proc/sys/fs/file-nr查看
node_filefd_maximum: 系统支持的最大文件描述符数,通过/proc/sys/fs/file-max或/proc/sys/fs/file-nr

2.7 进程文件描述符

process_max_fds: 进程可打开的最大文件描述符数。
process_open_fds: node_exporter进程当前打开的文件描述符数。 通过ls /proc/$PID/fd 2>/dev/null | wc -l 计算

2.8 socket

node_sockstat_sockets_used # 使用的 Socket 数
node_sockstat_TCP_inuse # 监听的 TCP Socket 数
node_sockstat_TCP_tw

2.9 TCP/UDP协议

node_netstat_Tcp_CurrEstab # ESTABLISHED 加 CLOSE_WAIT 状态的 TCP 连接数
node_netstat_Tcp_InSegs # 接收的 TCP 包数(包括错误的)
node_netstat_Tcp_InErrs # 接收的 TCP 错误包数(比如校验和错误)
node_netstat_Tcp_OutSegs # 发送的 TCP 包数
node_netstat_Udp_InDatagrams # 接收的 UDP 包数
node_netstat_Udp_InErrors # 接收的 UDP 错误包数
node_netstat_Udp_OutDatagrams # 发送的 UDP 包数

三、触发器设置

cd /data/docker-prometheus/

cat >> prometheus/alert.yml <<"EOF"
- name: node-exporter
rules:
- alert: HostOutOfMemory
expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10
for: 2m
labels:
severity: warning
annotations:
summary: "主机内存不足,实例:{{ $labels.instance }}"
description: "内存可用率<10%,当前值:{{ $value }}"
- alert: HostMemoryUnderMemoryPressure
expr: rate(node_vmstat_pgmajfault[1m]) > 1000
for: 2m
labels:
severity: warning
annotations:
summary: "内存压力不足,实例:{{ $labels.instance }}"
description: "节点内存压力大。 重大页面错误率高,当前值为:{{ $value }}"
- alert: HostUnusualNetworkThroughputIn
expr: sum by (instance) (rate(node_network_receive_bytes_total[2m])) / 1024 / 1024 > 100
for: 5m
labels:
severity: warning
annotations:
summary: "异常流入网络吞吐量,实例:{{ $labels.instance }}"
description: "网络流入流量 > 100 MB/s,当前值:{{ $value }}"
- alert: HostUnusualNetworkThroughputOut
expr: sum by (instance) (rate(node_network_transmit_bytes_total[2m])) / 1024 / 1024 > 100
for: 5m
labels:
severity: warning
annotations:
summary: "异常流出网络吞吐量,实例:{{ $labels.instance }}"
description: "网络流出流量 > 100 MB/s,当前值为:{{ $value }}"
- alert: HostUnusualDiskReadRate
expr: sum by (instance) (rate(node_disk_read_bytes_total[2m])) / 1024 / 1024 > 50
for: 5m
labels:
severity: warning
annotations:
summary: "异常磁盘读取,实例:{{ $labels.instance }}"
description: "磁盘读取> 50 MB/s,当前值:{{ $value }}"
- alert: HostUnusualDiskWriteRate
expr: sum by (instance) (rate(node_disk_written_bytes_total[2m])) / 1024 / 1024 > 50
for: 2m
labels:
severity: warning
annotations:
summary: "异常磁盘写入,实例:{{ $labels.instance }}"
description: "磁盘写入> 50 MB/s,当前值:{{ $value }}"
- alert: HostOutOfDiskSpace
expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
for: 2m
labels:
severity: warning
annotations:
summary: "磁盘空间不足告警,实例:{{ $labels.instance }}"
description: "剩余磁盘空间< 10% ,当前值:{{ $value }}"
- alert: HostDiskWillFillIn24Hours
expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs"}[1h], 24 * 3600) < 0 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
for: 2m
labels:
severity: warning
annotations:
summary: "磁盘空间将在24小时内耗尽,实例:{{ $labels.instance }}"
description: "以当前写入速率预计磁盘空间将在 24 小时内耗尽,当前值:{{ $value }}"
- alert: HostOutOfInodes
expr: node_filesystem_files_free{mountpoint ="/"} / node_filesystem_files{mountpoint="/"} * 100 < 10 and ON (instance, device, mountpoint) node_filesystem_readonly{mountpoint="/"} == 0
for: 2m
labels:
severity: warning
annotations:
summary: "磁盘Inodes不足,实例:{{ $labels.instance }}"
description: "剩余磁盘 inodes < 10%,当前值: {{ $value }}"
- alert: HostUnusualDiskReadLatency
expr: rate(node_disk_read_time_seconds_total[1m]) / rate(node_disk_reads_completed_total[1m]) > 0.1 and rate(node_disk_reads_completed_total[1m]) > 0
for: 2m
labels:
severity: warning
annotations:
summary: "异常磁盘读取延迟,实例:{{ $labels.instance }}"
description: "磁盘读取延迟 > 100ms,当前值:{{ $value }}"
- alert: HostUnusualDiskWriteLatency
expr: rate(node_disk_write_time_seconds_total[1m]) / rate(node_disk_writes_completed_total[1m]) > 0.1 and rate(node_disk_writes_completed_total[1m]) > 0
for: 2m
labels:
severity: warning
annotations:
summary: "异常磁盘写入延迟,实例:{{ $labels.instance }}"
description: "磁盘写入延迟 > 100ms,当前值:{{ $value }}"
- alert: high_load
expr: node_load1 > 4
for: 2m
labels:
severity: page
annotations:
summary: "CPU1分钟负载过高,实例:{{ $labels.instance }}"
description: "CPU1分钟负载>4,已经持续2分钟。当前值为:{{ $value }}"
- alert: HostCpuIsUnderUtilized
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100) > 80
for: 1m
labels:
severity: warning
annotations:
summary: "cpu负载高,实例:{{ $labels.instance }}"
description: "cpu负载> 80%,当前值:{{ $value }}"
- alert: HostCpuStealNoisyNeighbor
expr: avg by(instance) (rate(node_cpu_seconds_total{mode="steal"}[5m])) * 100 > 10
for: 0m
labels:
severity: warning
annotations:
summary: "CPU窃取率异常,实例:{{ $labels.instance }}"
description: "CPU 窃取率 > 10%。 嘈杂的邻居正在扼杀 VM 性能,或者 Spot 实例可能失去信用,当前值:{{ $value }}"
- alert: HostSwapIsFillingUp
expr: (1 - (node_memory_SwapFree_bytes / node_memory_SwapTotal_bytes)) * 100 > 80
for: 2m
labels:
severity: warning
annotations:
summary: "磁盘swap空间使用率异常,实例:{{ $labels.instance }}"
description: "磁盘swap空间使用率>80%"
- alert: HostNetworkReceiveErrors
expr: rate(node_network_receive_errs_total[2m]) / rate(node_network_receive_packets_total[2m]) > 0.01
for: 2m
labels:
severity: warning
annotations:
summary: "异常网络接收错误,实例:{{ $labels.instance }}"
description: "网卡{{ $labels.device }}在过去2分钟接收错误率大于0.01,当前值:{{ $value }}"
- alert: HostNetworkTransmitErrors
expr: rate(node_network_transmit_errs_total[2m]) / rate(node_network_transmit_packets_total[2m]) > 0.01
for: 2m
labels:
severity: warning
annotations:
summary: "异常网络传输错误,实例:{{ $labels.instance }}"
description: "网卡{{ $labels.device }}在过去2分钟传输错误率大于0.01,当前值:{{ $value }}"
- alert: HostNetworkInterfaceSaturated
expr: (rate(node_network_receive_bytes_total{device!~"^tap.*"}[1m]) + rate(node_network_transmit_bytes_total{device!~"^tap.*"}[1m])) / node_network_speed_bytes{device!~"^tap.*"} > 0.8 < 10000
for: 1m
labels:
severity: warning
annotations:
summary: "异常网络接口饱和,实例:{{ $labels.instance }}"
description: "网卡{{ $labels.device }}正在超载,当前值{{ $value }}"
- alert: HostConntrackLimit
expr: node_nf_conntrack_entries / node_nf_conntrack_entries_limit > 0.8
for: 5m
labels:
severity: warning
annotations:
summary: "异常连接数,实例:{{ $labels.instance }}"
description: "连接数过大,当前连接数:{{ $value }}"
- alert: HostClockSkew
expr: (node_timex_offset_seconds > 0.05 and deriv(node_timex_offset_seconds[5m]) >= 0) or (node_timex_offset_seconds < -0.05 and deriv(node_timex_offset_seconds[5m]) <= 0)
for: 2m
labels:
severity: warning
annotations:
summary: "异常时钟偏差,实例:{{ $labels.instance }}"
description: "检测到时钟偏差,时钟不同步。值为:{{ $value }}"
- alert: HostClockNotSynchronising
expr: min_over_time(node_timex_sync_status[1m]) == 0 and node_timex_maxerror_seconds >= 16
for: 2m
labels:
severity: warning
annotations:
summary: "时钟不同步,实例:{{ $labels.instance }}"
description: "时钟不同步"
- alert: NodeFileDescriptorLimit
expr: node_filefd_allocated / node_filefd_maximum * 100 > 80
for: 1m
labels:
severity: warning
annotations:
summary: "预计内核将很快耗尽文件描述符限制"
description: "{{ $labels.instance }}}已分配的文件描述符数超过了限制的80%,当前值为:{{ $value }}"
EOF

检查rule配置文件是否有问题:

docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

# 重载配置
curl -X POST http://localhost:9090/-/reload

查看:http://192.168.10.14:9090/alerts?search=,可以发现alters多了刚才定义的

四、grafana展示node-exporter数据

由于grafana已经添加了1860模版,可以直接登录查看

http://192.168.10.14:3000/login

4.prometheus监控--监控linux服务器的更多相关文章

  1. jprofiler_监控远程linux服务器的JVM进程(实践)

    几天前写了一篇文章,jprofiler_监控远程linux服务器的tomcat进程(实践),介绍了使用jprofiler怎样监控远程linux的tomcat进程,这两天想了想,除了可以监控tomcat ...

  2. jprofiler_监控远程linux服务器的JVM进程(转 非常棒)

    几天前写了一篇文章,jprofiler_监控远程linux服务器的tomcat进程(实践),介绍了使用jprofiler怎样监控远程linux的tomcat进程,这两天想了想,除了可以监控tomcat ...

  3. Nagios的安装配置与应用之五监控远程Linux服务器

    本文出自 “曹坏水” 博客,请务必保留此出处http://cao2012.blog.51cto.com/366908/1132113 NRPE是Nagios的一个功能扩展,它可在远程Linux和UNI ...

  4. 搭建基于Nagios的监控系统——之监控远程Linux服务器

    上一篇介绍了如何安装Nagios Core,这一篇跟大家分享一下如何将一台远程的Linux服务器加入纳入监控范围. 第一部分:在远程Linux上安装Nagios Plugins和NRPE   第一步: ...

  5. jprofiler_监控远程linux服务器的tomcat进程(实践)

    一.软件列表: windows和linux的jprofiler的版本必须一致 1.jprofiler_linux_9_1_1.tar.gz 2.jprofiler_windows_x64 9_1_1 ...

  6. 《Linux服务器的监控》

    本文地址:http://www.cnblogs.com/aiweixiao/p/7131532.html 原文地址(公众号):http://t.cn/RKwmqUs 点击关注 微信公众号 1. 监控概 ...

  7. Jmeter监控Linux服务器性能

    ①.下载JMeterPlugins相关的jar包,放jmeter的安装路径\lib\ext下——这个时候启动jmeter会发现,添加监听器时,出现了一堆的jp@jc……,这些就是插件的功劳. JMet ...

  8. docker-compose 搭建 Prometheus+Grafana监控系统

    有关监控选型之前有写过一篇文章: 监控系统选型,一文轻松搞定! 监控对象 Linux服务器 Docker Redis MySQL 数据采集 1).prometheus: 采集数据 2).node-ex ...

  9. Prometheus 监控linux服务器

    Prometheus 监控linux服务器 node_exporter:用于*NIX系统监控,使用Go语言编写的收集器. 使用版本 node_exporter 0.17.0 相关文档 使用文档:htt ...

  10. Grafana+Prometheus通过node_exporter监控Linux服务器信息

    Grafana+Prometheus通过node_exporter监控Linux服务器信息 一.Grafana+Prometheus通过node_exporter监控Linux服务器信息 1.1nod ...

随机推荐

  1. 记录--CSS 如何实现羽化效果?

    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 最近碰到这样一个问题,在一张封面上直接显示书名,可能会存在书名看不太清楚的情况(容易受到背景干扰),如下 为了解决这个问题,设计师提了一个 ...

  2. Excel多列求平均值

    数据源如下所示 需求描述:现在需要根据水果名称和月份求出对应水果的平均单价 一.添加一列辅助列(=A2&B2) 二.Ctrl+A选择所有数据插入数据透视表,选择辅助列到行,客单价到值(值字段设 ...

  3. read IEEE std for verolog(2)

    read IEE standard for verilog (2) 1.阅读前言 前面大致地看完了序言,了解了一下verilog的起源以及基本特性.接下来往下读有相关链接和目录,然后是正文.今天暂时阅 ...

  4. Spring Cloud项目搭建版本选择

    1.查看spring cloud的版本 https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4 ...

  5. #树状数组,dp#SGU 521 North-East

    题目 在平面上有 \(n\) 个点,现在有一个人要从某个点出发, 每次只能到达横纵坐标都超过原坐标的点,也就是 \(x_j<x_i,y_j<y_i\) 如果他要经过最多的点,那么哪些点是可 ...

  6. C语言 01 概述

    历史 C 语言是一门面向过程的计算机编程语言,于 1972 年诞生于贝尔实验室. C 语言是丹尼斯·里奇(Dennis Ritchie)以 B 语言为基础发展而来,因此他被称为 C 语言之父. C 语 ...

  7. 持续构建行业影响力|HarmonyOS SDK荣膺年度“技术卓越”奖项

    自2023年9月华为宣布鸿蒙原生应用全面启动以来,HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净.更智能.更精致.更易用的鸿蒙原生应用,和开发者共同成长 ...

  8. pathlib简单使用, 比os简单

    from pathlib import Path p = Path(r'D:\project\pachong\test1\a.txt') # 基本用法 ''' # 判断 p.is_dir() # 判断 ...

  9. 编译安装openGauss 3.0.0

    编译安装 openGauss 3.0.0 环境检查 1.1 检查 OS 版本 openGauss支持的操作系统: CentOS 7.6(x86 架构) openEuler-20.03-LTS(aarc ...

  10. HDC2021技术分论坛:ArkUI 3.0让多设备开发更简单!

    作者:wanglei,华为UI编程框架技术专家 HarmonyOS自诞生以来,就是为满足分布式多设备应用场景而设计的,大到智慧屏.车机.平板,小到手机.手表.在多设备场景下进行应用UI界面开发,面临新 ...