Prometheus、Node_Exporter、PushGateway的使用

2023-11-02

一、prometheus_server端部署prometheus

prometheus是基于T_S(timeseries)的数据库,对系统时间的准确性要求很高,必须保证主机时间的实时同步。所以,安装prometheus之前,须先进行ntp时间同步

[root@test ~]# yum install ntpdate -y
[root@test ~]# ntpdate ntp1.aliyun.com
[root@test ~]# hwclock -w
[root@test ~]# crontab -e
* * * * * /usr/sbin/ntpdate ntp1.aliyun.com 2&> /dev/null && /usr/sbin/hwclock -w 2&>/dev/null

关闭防火墙和selinux

[root@test ~]# sed -i 's/SELINUX=enforcing/SLINUX=disabled/g' /etc/selinux/config
[root@test ~]# systemctl stop firewalld
[root@test ~]# systemctl disable firewalld
[root@test ~]# setenforce 0

下载安装

二进制包下载解压后即可使用,官网地址:https://prometheus.io/

[root@test ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.30.1/prometheus-2.30.1.linux-amd64.tar.gz
[root@test ~]# ls
prometheus-2.30.1.linux-amd64.tar.gz
[root@test ~]# tar -xf prometheus-2.30.1.linux-amd64.tar.gz -C /usr/local
[root@test ~]# mv /usr/local/prometheus-2.30.1.linux-amd64/ /usr/local/prometheus/

启动

# 查看版本等信息
[root@test prometheus]# ./prometheus --version
prometheus, version 2.30.1 (branch: HEAD, revision: fafb309d4027b050c917362d7d2680c5ad6f6e9e)
  build user:       root@36ab67e1b043
  build date:       20210928-09:41:36
  go version:       go1.17.1
  platform:         linux/amd64

[root@test ~]# cd /usr/local/prometheus/
# 前台启动
[root@test prometheus]# ./prometheus 
# 当不带任何参数启动时,其实默认自带参数 --config.file=prometheus.yml ,使用当前目录下的prometheus.yml文件作为配置文件
# 后台启动为: nohup ./prometheus  &  ,输出的信息会存放在当前目录下的nohup.out中
# 或者 nohup ./prometheus  &> /PATH/FILENAME & 
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:400 msg="No time or size retention was set so using the default time retention" duration=15d
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:438 msg="Starting Prometheus" version="(version=2.30.1, branch=HEAD, revision=fafb309d4027b050c917362d7d2680c5ad6f6e9e)"
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:443 build_context="(go=go1.17.1, user=root@36ab67e1b043, date=20210928-09:41:36)"
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:444 host_details="(Linux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 test (none))"
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:445 fd_limits="(soft=1024, hard=4096)"
level=info ts=2021-09-29T10:58:37.550Z caller=main.go:446 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2021-09-29T10:58:37.552Z caller=web.go:541 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2021-09-29T10:58:37.552Z caller=main.go:822 msg="Starting TSDB ..."
level=warn ts=2021-09-29T10:58:37.552Z caller=db.go:683 component=tsdb msg="A TSDB lockfile from a previous execution already existed. It was replaced" file=/usr/local/prometheus/data/lock
level=info ts=2021-09-29T10:58:37.553Z caller=tls_config.go:191 component=web msg="TLS is disabled." http2=false
level=info ts=2021-09-29T10:58:37.554Z caller=head.go:466 component=tsdb msg="Replaying on-disk memory mappable chunks if any"
level=info ts=2021-09-29T10:58:37.554Z caller=head.go:500 component=tsdb msg="On-disk memory mappable chunks replay completed" duration=3.947µs
level=info ts=2021-09-29T10:58:37.554Z caller=head.go:506 component=tsdb msg="Replaying WAL, this may take a while"
level=info ts=2021-09-29T10:58:37.556Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=2
level=info ts=2021-09-29T10:58:37.558Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=2
level=info ts=2021-09-29T10:58:37.559Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=2 maxSegment=2
level=info ts=2021-09-29T10:58:37.559Z caller=head.go:583 component=tsdb msg="WAL replay completed" checkpoint_replay_duration=26.379µs wal_replay_duration=4.976829ms total_replay_duration=5.017724ms
level=info ts=2021-09-29T10:58:37.561Z caller=main.go:849 fs_type=XFS_SUPER_MAGIC
level=info ts=2021-09-29T10:58:37.561Z caller=main.go:852 msg="TSDB started"
level=info ts=2021-09-29T10:58:37.561Z caller=main.go:979 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2021-09-29T10:58:37.602Z caller=main.go:1016 msg="Completed loading of configuration file" filename=prometheus.yml totalDuration=41.166168ms db_storage=1.422µs remote_storage=14.496µs web_handler=531ns query_engine=1.442µs scrape=40.625426ms scrape_sd=84.755µs notify=23.322µs notify_sd=7.193µs rules=2.375µs
level=info ts=2021-09-29T10:58:37.602Z caller=main.go:794 msg="Server is ready to receive web requests."
# 默认prometheus会把运行的本机同时当作本监控节点(prometheus server不需要部署node_exporter)

# 本机IP
[root@test ~]# ifconfig | awk 'NR==2 {print $2}'
192.168.126.120

在默认配置中,已经将 Prometheus Server 自身作为被监控端进行监控

可以通过HTTP_GET请求方式查看prometheus对本机的监控内容:

[root@test ~]# curl localhost:9090/metrics
# 或者在浏览器访问 http://192.168.126.120:9090/metrics
# 可以看到获取到的当前主机的所有监控数据,返回了⼤量的这种 metrics类型 K/V数据

在这里插入图片描述

Prometheus UI是Prometheus内置的一个可视化管理界面,当 Prometheus 启动成功后,可以访问 http://IP:9090 页面。通过Prometheus UI用户能够轻松的了解 Prometheus当前的配置,监控任务运行状态等。在Prometheus UI的 Web Console界面, 用它可以进行任何 PromQL 查询和调试工作,非常方便,通过 Graph 面板,用户还能直接使用 PromQL 实时查询监控数据:

在这里插入图片描述
那么此时可以使用 PromQL (Prometheus Query Language)在Web Console界面也可以对采集到的metrics中的某一key值进行查看
在这里插入图片描述在这里插入图片描述

查看监控节点
在这里插入图片描述

prometheus配置文件说明

# 配置文件格式是yaml格式
# 此片段指定的是 prometheus 的全局配置, 比如采集间隔,抓取超时时间等。( 通常可以被job单独的配置覆盖
global:)
global:

  # 默认抓取周期,可用单位ms、smhdwy #设置每15s采集数据一次,默认1分钟
  [ scrape_interval: <duration> | default = 1m ]

  # 默认抓取超时
  [ scrape_timeout: <duration> | default = 10s ]

  # 监控规则的默认周期(多长时间会进行一次监控规则的评估) ,默认1分钟
  # 举例:假如设置当内存使用量>70%时发出报警这么一条rule(规则),那么prometheus会根据这个配置项设定的时间来执行一次这个规则检查内存的使用情况
  [ evaluation_interval: <duration> | default = 1m ]

  # 和外部系统(例如AlertManager)通信时为时间序列或者警情(Alert)强制添加的标签列表
  external_labels:
    [ <labelname>: <labelvalue> ... ]
 
===================================================================================================
# 此片段指定报警规则文件, prometheus 根据这些规则信息,会推送报警信息到 alertmanager 中。
# (proemtheus将会通过rules对获取到的指标进行定时告警触发,并将触发的告警推送给下游进一步处理,一般我们选择alertmanager作为处理工具。)
rule_files:
  [ - <filepath_glob> ... ]



# Alertmanager(是用于管理和发出警报的插件)相关配置,若要使用该功能需要先安装alertmanager插件。一般是使用grafana的报警功能代替此功能
alerting:		# 此片段指定报警配置, 这里主要是指定 prometheus 将报警规则推送到指定的 alertmanager 实例地址。
  alert_relabel_configs:
    [ - <relabel_config> ... ]
  alertmanagers:
    [ - <alertmanager_config> ... ]


# 该框之内都是关于告警的相关配置,需先安装AlertManager插件并进行配置才能使用该功能。 一般是使用grafana的报警功能代替该AlertManager功能
===================================================================================================

# 此片段指定抓取配置,prometheus 的数据采集通过此片段配置。
scrape_configs:	 # 一个 scrape_config 片段指定一组目标和参数, 目标就是实例,指定采集的端点
  [ - <scrape_config> ... ]
  scrape_interval: 抓取间隔,不配置默认继承 global 值。 
  scrape_timeout: 抓取超时时间,不配置默认继承 global 值。 
  metric_path: 抓取路径, 默认是/metrics 
  *_sd_configs: 指定服务发现配置 
  static_configs: 静态指定服务 job。 
  relabel_config: relabel 设置

例:
# 在scrape_config中每个监控目标是一个job,但job的类型有很多种。可以是最简单的static_config,即静态地指定每一个目标。
scrape_configs:
# 这里定义了一个job的名称:job_name: 'prometheus',然后定义监控节点:
  - job_name: "prometheus"
    static_configs:
      - targets: ['localhost:9090']
# 这是prometheus本机的一个监控节点,可以继续扩展加入其它需要被监控的节点,例如:
  - job_name: 'aliyun'
    static_configs:
      - targets: [‘server01:9100’,'IP:9100’,’nginxserver:9100','web006:9100’,'redis:9100','logserver:9100','redis1:9100']
# 可以看到targets可以并列写入多个节点,用逗号隔开,机器名+端口号,端口号主要是exporters的端口,在这里9100其实是node_exporter的默认端口。配置完成后,prometheus就可以通过配置文件识别监控的节点,持续开始采集数据,prometheus基础配置也就搭建好了。

# 也可以监控安装pushgateway插件的节点
  - job_name: 'xxxxx'
    static_configs:
      - targets: [‘IP:9091’]	# pushgateway默认是9091端口
        labels:
          instance: pushgateway
 
# 远程读写特性相关的配置(此部分内容需参考prometheus集群和高可用部分,如果是单机架构则无需配置。)
remote_write:		# 指定后端的存储的写入 api 地址。
  [ - <remote_write> ... ]
remote_read:		# 指定后端的存储的读取 api 地址。
  [ - <remote_read> ... ]


# 安装后默认配置文件
[root@test ~]# cat /usr/local/prometheus/prometheus.yml
global:		# 全局配置(如果有内部单独设定,会覆盖这个参数)
  scrape_interval: 15s # 周期性从监控目标上收集数据,然后将数据存储到本地存储上。设置全局每次数据收集的间隔为15s,不设置默认为1分钟。可以设定全局也可以设定单个metrics。
  evaluation_interval: 15s  # 规则扫描时间间隔是15秒,默认不填写是 1分钟

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
  
scrape_configs:		# 指定prometheus要监控的目标
  - job_name: "prometheus"		# 定义job名称
    static_configs:
      - targets: ["localhost:9090"]		# 具体被监控的节点

prometheus命令行启动参数

--config.file  即指定prometheus.yml配置文件位置,默认为当前目录下 prometheus.yml

--web.listen-adress 指定监听地址和端口,默认为 "0.0.0.0:9090"

--web.config.file 用于开启TLS或者认证

--web.read-timeout prometheus管理页面访问超时,支持 5s, 5m 这样的单位配置

--web.max-connection 最大同时连接数限制

--web.external-url 额外的url格式,例如我们可以为prometheus的api加上前缀

--web.route-prrfix 同 erternal-url一样可以控制前缀,之后可能会移除这个参数

--web.user-assets 用户静态文件目录,我们可以通过这个配置自定义prometheus的默认ui

--web.enable-lifecycle  

--web.enable-admin-api 启用后可以通过api来对prometheus进行查询和管理

--web.console.templates 指定控制台页面模板,用于自定义ui

--web.console.libraries 自定义控制台所需要的库文件

--web.page-title 自定义页面的tile标签

--web.core.origin 请求头跨域指定,默认为 ".*"

--storage.tsdb.path 监控数据存储目录,默认为工作目录下 data/

--storage.tsdb.retention 监控数据持久化存储保持时间,这个flag即将废弃,建议使用–storage.tsdb.retention.time

--storage.tsdb.retention.time 作用同retention,推荐的参数,可以使用 90d 这样的格式

--storage.tsdb.retention.size 【实验性功能】按照数据文件大小保留持久化数据

--storage.stdb.no-lockfile 不创建数据文件的lockfile,可以节省磁盘空间但是增加了数据块损坏的风险

--storage.tsdb.allow-overlappping-block 【实验性功能】启用数据垂直压缩

--storage.tsdb.wal-compression 启用wal文件的压缩

--storage.remote.flush-deadline 配置远程写数据以及配置重载最大时间,详见prometheus远程读写

--storage.remote.read-sample-limit 远程读取样本点最大数量,默认为五千万

--storage.remote.read-concurrent-limit 并发远程读的线程数限制,0代表不限制

--storage.remote.read-max-bytes-in-frame  单个查询框中样本数据大小限制,默认为protobuf本身限制

--rules.alert.for-outage-tolerance 允许告警规则中“持续检测时间”最大值,默认为1h

--rules.alert.for-grace-period  告警触发和解决与 "for" 状态之间最短持续时间,只对配置了 for 的告警有效,默认为10m

--rules.alert.resend-delay 触发的告警持续发送给alertmanager的最小等待时间

--alertmanager.notification-queue-capacity 将要推送给alertmanager的告警队列大小限制,默认为1万

--alertmanager.timeout 推送给alertmanager消息的超时时间,支持 1m 格式配置,默认为 10s

--query.max-concurrency 并发查询数量限制,默认为20

--query.timeout 单次查询的超时时间,默认为2m

--query.max-samples 单次查询的最大样本点数量,默认为五千万

二、在被监控节点部署 node_exporter

在Prometheus的架构设计中,Prometheus Server并不直接服务监控特定的目标,其主要任务负责数据的收集, 存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的CPU使用率,我们需要使用到 Exporter。Prometheus周期性的从Exporter暴露的HTTP服务地址(通常是/metrics)拉取监控样本数据。 从上面的描述中可以看出Exporter可以是一个相对开放的概念,其可以是一个独立运行的程序独立于监控目标以外, 也可以是直接内置在监控目标中。只要能够向Prometheus提供标准格式的监控样本数据即可。

光搭建好prometheus_server 是不够的,所以还需要给监控节点部署 exporter ⽤来采样数据。 这里为了能够采集到主机的运行指标如CPU, 内存,磁盘等信息。选⽤企业中最常⽤的 node_exporter 这个插件。

Exporter是Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。

Prometheus提供多种类型的Exporter用于采集各种不同服务的运行状态。目前支持的有数据库、硬件、消息中间件、存储系统、HTTP服务器等。另外也可以进行自定义开发。用户还可以基于Prometheus提供的Client Library创建自己的Exporter程序。

官网提供了许多现成的exporter:

blackbox_exporter:是prometheus社区提供的官方黑盒监控解决方案,其允许用户通过:http、https、dns、tcp以及icmp的方式对网络进行探测。我们利用icmp探针可以坚持网络是否通畅,利用http,https可以坚持网页是否可以正常访问,利用tcp检测服务端口判断服务是否正常。
cadvisor:是google开源的用于监控容器运行的工具。
redis_exporter:主要用于监控采集redis数据库服务器相关指标。
mysqld_exporter:主要用于监控采集mysql数据库服务器相关指标。
node_exporter:主要用来采集机器的性能指标数据,包括cpu,内存,磁盘,io等基本信息。
statsd_exporter
raphite_exporter
haproxy_exporter

node_exporter 是⼀个以http_server⽅式运⾏在后台,并且持续不断采集 Linux系统中各种操作系统本⾝相关的监控参数的程序,其采集量是很⼤很全的,往往默认的采集项⽬就远超过实际需求。

下载地址:https://prometheus.io/download/

# 本机IP
[root@nginx ~]# ifconfig ens32 | awk 'NR==2 {print $2}'
192.168.126.41
# 时间同步
[root@nginx ~]# yum install ntpdate -y
[root@nginx ~]# ntpdate ntp1.aliyun.com
[root@nginx ~]# hwclock -w

# 关闭防火墙和selinux
[root@nginx ~]# sed -i 's/SELINUX=enforcing/SLINUX=disabled/g' /etc/selinux/config
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# systemctl disable firewalld
[root@nginx ~]# setenforce 0

# 下载
[root@nginx ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
# 解压
[root@nginx ~]# tar xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local
[root@nginx ~]# mv /usr/local/node_exporter-1.2.2.linux-amd64/ /usr/local/node_exporter
[root@nginx ~]# cd /usr/local/node_exporter

# 查看版本等信息
[root@nginx node_exporter]# ./node_exporter --version
node_exporter, version 1.2.2 (branch: HEAD, revision: 26645363b486e12be40af7ce4fc91e731a33104e)
  build user:       root@b9cb4aa2eb17
  build date:       20210806-13:44:18
  go version:       go1.16.7
  platform:         linux/amd64
 
 # 前台启动
[root@nginx node_exporter]# ./node_exporter
# 后台启动为: nohup ./node_exporter  &  ,输出的信息会存放在当前目录下的nohup.out中
# 或者 nohup /usr/local/node_exporter/node_exporter &> /PATH/FILENAME & 指定将输出信息输入到指定文件中
level=info ts=2021-09-29T13:45:58.309Z caller=node_exporter.go:182 msg="Starting node_exporter" version="(version=1.2.2, branch=HEAD, revision=26645363b486e12be40af7ce4fc91e731a33104e)"
level=info ts=2021-09-29T13:45:58.309Z caller=node_exporter.go:183 msg="Build context" build_context="(go=go1.16.7, user=root@b9cb4aa2eb17, date=20210806-13:44:18)"
level=warn ts=2021-09-29T13:45:58.309Z caller=node_exporter.go:185 msg="Node Exporter is running as root user. This exporter is designed to run as unpriviledged user, root is not required."
level=info ts=2021-09-29T13:45:58.309Z caller=filesystem_common.go:110 collector=filesystem msg="Parsed flag --collector.filesystem.mount-points-exclude" flag=^/(dev|proc|sys|var/lib/docker/.+)($|/)
level=info ts=2021-09-29T13:45:58.309Z caller=filesystem_common.go:112 collector=filesystem msg="Parsed flag --collector.filesystem.fs-types-exclude" flag=^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:108 msg="Enabled collectors"
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=arp
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=bcache
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=bonding
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=btrfs
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=conntrack
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=cpu
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=cpufreq
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=diskstats
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=edac
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=entropy
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=fibrechannel
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=filefd
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=filesystem
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=hwmon
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=infiniband
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=ipvs
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=loadavg
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=mdadm
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=meminfo
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=netclass
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=netdev
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=netstat
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=nfs
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=nfsd
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=nvme
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=powersupplyclass
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=pressure
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=rapl
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=schedstat
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=sockstat
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=softnet
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=stat
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=tapestats
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=textfile
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=thermal_zone
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=time
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=timex
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=udp_queues
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=uname
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=vmstat
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=xfs
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:115 collector=zfs
level=info ts=2021-09-29T13:45:58.310Z caller=node_exporter.go:199 msg="Listening on" address=:9100
level=info ts=2021-09-29T13:45:58.310Z caller=tls_config.go:191 msg="TLS is disabled." http2=false


[root@nginx node_exporter]# ss -aulntp | grep 9100
tcp    LISTEN     0      128      :::9100                 :::*                   users:(("node_exporter",pid=1190,fd=3))
[root@nginx node_exporter]# ps -aux | grep [n]ode
root       1190  0.0  0.5 716168 11204 pts/0    Sl+  21:45   0:00 ./node_exporter





node_exporter的启动参数说明

  1. 指定textfile收集器目录

    使用textfile收集器可以让用户添加自定义的度量指标,功能类似pushgateway,同zabbix中自定义的item一样,只要将度量指标和值按照prometheus规范的格式输出到指定位置且以.prom后缀文件保存,textfile收集器会自动读取collector.textfile.directory目录下所有以.prom结尾的文件,并提取所有格式为Prometheus的指标暴露给Prometheus来抓取。

    textfile收集器默认是开启的,只需要指定–collector.textfile.directory的路径启动参数即可。
    –collector.textfile.directory=/usr/local/node_exporter/textfile.collected

例如:

# 需要监控系统登录用户数
echo "node_login_users $(who |wc -l)" > /usr/local/node_exporter/textfile.collected/login_users.prom
echo "node_processes $(ps -ef |wc -l)" > /usr/local/node_exporter/textfile.collected/node_processes.prom

# 以定时任务的方式采集
*/1 * * * * echo "login_users $(who |wc -l)" > /usr/local/node_exporter/textfile.collected/login_users.prom
*/1 * * * * echo "login_users $(who |wc -l)" > /usr/local/node_exporter/textfile.collected/node_processes.prom
  1. 启用或禁用收集器
    通过 ./node_exporter -h 命令,可以看到默认启用了哪些收集器(default: enabled),若要禁用某个收集器,如
    –collector.ntp,可以修改为 --no-collector.ntp,即禁用该收集器。

  2. 只添加指定收集器。

    node_exporter等各种收集器默认会收集非常多的指标数据,有很多并非我们所需要的,是可以不收集的,我们可以在启动node_exporter时指定禁用某些收集器,也可以在Prometheus的配置文件中(注意是Prometheus)的scrape_configs配置块下指定只收集哪些指标,配置格式大致如下:

scrape_configs:
- job_name: 'node_exporter'
 static_configs:
 - targets: ['node01:9100']
params:
collect[]:
- cpu
     - meminfo
     - netstat
     - xfs

详细配置可参照github文档(https://github.com/prometheus/node_exporter)。

使用场景:只有在我们非常清楚每一个收集器用途时才使用该方法,官方推荐按默认收集所有数据,然后禁用某些不需要的收集器。





将node_exporter配置成systemd服务

因为部署node_exporter节点需要一开机就进行监控,所以需要将其配置为开机自启

# 创建service文件
[root@nginx ~]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@nginx ~]# pkill node_exporter
# 使用systemctl方式启动(重要说明,如果添加为service,那么就不要将systemctl方式和使用可执行文件命令方式混用)
[root@nginx ~]# systemctl start node_exporter
[root@nginx ~]# systemctl status node_exporter
● node_exporter.service - node_exporter
   Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-30 17:20:12 CST; 2s ago
     Docs: https://github.com/prometheus/node_exporter
 Main PID: 1285 (node_exporter)
   CGroup: /system.slice/node_exporter.service
           └─1285 /usr/local/node_exporter/node_exporter

Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...one
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...ime
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...mex
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...ues
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...ame
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...tat
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...xfs
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...zfs
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.561Z caller=node_e...100
Sep 30 17:20:12 nginx node_exporter[1285]: level=info ts=2021-09-30T09:20:12.562Z caller=tls_co...lse
Hint: Some lines were ellipsized, use -l to show in full.

[root@nginx ~]# ss -aulntp | grep 9100
tcp    LISTEN     0      128      :::9100                 :::*                   users:(("node_exporter",pid=1285,fd=3))
[root@nginx ~]# ps -aux | grep [n]ode_exporter
root       1285  0.0  0.6 716424 13016 ?        Ssl  17:20   0:00 /usr/local/node_exporter/node_exporter
# 启动成功

# 加入开机自启
[root@nginx ~]# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.

node_exporter默认⼯作在9100端⼜可以响应 prometheus_server发过来的 HTTP_GET请求也可以响应其他⽅式的 HTTP_GET请求

[root@nginx node_exporter]# curl localhost:9100/metrics
# 或者在浏览器访问 http://192.168.126.41:9100/metrics
# 可以看到当前node exporter获取到的当前主机的所有监控数据,返回了⼤量的这种 metrics类型 K/V数据

每一个监控指标之前都会有一段类似于如下形式的信息:

# HELP node_cpu_seconds_total Seconds the CPUs spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 413.75
node_cpu_seconds_total{cpu="0",mode="iowait"} 0.09
node_cpu_seconds_total{cpu="0",mode="irq"} 0
node_cpu_seconds_total{cpu="0",mode="nice"} 0
node_cpu_seconds_total{cpu="0",mode="softirq"} 0.06
node_cpu_seconds_total{cpu="0",mode="steal"} 0
node_cpu_seconds_total{cpu="0",mode="system"} 2.17
node_cpu_seconds_total{cpu="0",mode="user"} 0.81
node_cpu_seconds_total{cpu="1",mode="idle"} 415.92
node_cpu_seconds_total{cpu="1",mode="iowait"} 0.08
node_cpu_seconds_total{cpu="1",mode="irq"} 0
node_cpu_seconds_total{cpu="1",mode="nice"} 0
node_cpu_seconds_total{cpu="1",mode="softirq"} 0.08
node_cpu_seconds_total{cpu="1",mode="steal"} 0
node_cpu_seconds_total{cpu="1",mode="system"} 1.19
node_cpu_seconds_total{cpu="1",mode="user"} 0.66
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 0
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 0.01
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.01

# 其中HELP用于解释当前指标的含义,TYPE则说明当前指标的数据类型。在上面的例子中node_cpu_seconds_total的注释表明当前指 标是cpu0上idle进程
# 占用CPU的总时间,CPU占用时间是一个只增不减的度量指标,从类型中也可以看出node_cpu_seconds_total 的数据类型是计数器(counter),与该指标的
# 实际含义一致。又例如node_load1该指标反映了当前主机在最近一分 钟以内的负载情况,系统的负载情况会随系统资源的使用而变化,因此node_load1反映
# 的是当前状态,数据可能增加也可能减少,从注释中可以看出当前指标类型为仪表盘(gauge),与指标反映的实际含义一致。

# 除了这些以外,在当前页面中根据物理主机系统的不同,你还可能看到如下监控指标: 
# node_boot_time:系统启动时间 
# node_cpu:系统CPU使用量
#  nodedisk*:磁盘IO 
# nodefilesystem*:文件系统用量 
# node_load1:系统负载 
# nodememeory*:内存使用量 
# nodenetwork*:网络带宽 
# node_time:当前系统时间 
# go_*:node exporter中go相关指标 
# process_*:node exporter自身进程相关运行指标

为了能够让prometheus_server能够从当前node exporter获取到监控数据,这里需要修改Prometheus配置文 件。编辑prometheus.yml并在scrape_configs节点下添加以下内容:

# 停止prometheus_server的prometheus服务,前台启动的话直接使用 【ctrl+c】,后台启动的话直接pkill
[root@test ~]# pkill prometheus

# 修改配置文件
[root@test ~]# vim /usr/local/prometheus/prometheus.yml
  - job_name: "test"
    static_configs:
      - targets: ["192.168.126.41:9100"]

# 检查配置文件语法用法: /usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml 

# 启动
[root@test prometheus]# nohup ./prometheus &
[1] 3695
[root@test prometheus]# nohup: ignoring input and appending output to ‘nohup.out’

访问http://192.168.126.120:9090,进入到prometheus_server的Prometheus UI(Prometheus内置的一个可视化管理界面)查看监控节点

在这里插入图片描述

通过Prometheus UI用户能够轻松的了解 Prometheus当前的配置,监控任务运行状态等。 通过 Graph 面板,用户还能直接使用 PromQL 实时查询监控数据,在Web Console界面也可以对采集到的metrics中的某一key值进行查看
在这里插入图片描述
在这里插入图片描述

三、使用 PushGateway 进行数据上报采集

如果exporter+prometheus可以满足需求,也可以不使用pushgateway插件

exporter是首先安装在被监控服务器上运行在后台,然后自动采集系统数据,本身又是一个HTTP_server可以被Prometheus服务器定时去HTTP GET取得数据

如果把这个过程反过来,把pushgatewat安装在客户端或者服务端(其实装哪里都无所谓),pushgateway本身也是一个http服务器,运维通过自己的脚本程序抓取被监控端自己想要的监控数据,然后推送到pushgateway再由pushgateway推送到prometheus服务端。

已经有了那么强大的pull形式的node_exporter采集,为什么还需要一个pushgateway的形式呢?

  1. exporter虽然采集类型已经很丰富了,但是我们依然需要很多自制的监控数据,非规则化的自定制的

  2. Prometheus采用pull模式,可能由于不在一个子网或者防火墙原因,导致prometheus无法直接拉取各个target

  3. 一个新的自定义的pushgateway脚本开发远远比开发一个全新的exporter简单快速的多(exporter的开发需要使用真正的编程语言,shell这种快速脚本是不行的,而且需要了解很多Prometheus自定义的编程格式才能开始制作工作量很大)

  4. 由于网络问题或者安全问题,可能我们的数据无法直接暴露出一个entrypoint 给prometheus采集。 这个时候可能就需要一个pushgateway来作为中间者完成中转工作。 prometheus还是采用pull方式来采集pushgateway的数据,我们的采集端通过push方式把数据push给pushgateway,来完成数据的上报。

  5. 在监控业务数据的时候,需要将不同的数据汇总,由Prometheus统一收集

由于以上原因不得不使用pushgateway,但在使用之前,有必要了解一下它的弊端:

  1. pushgateway会形成一个单点瓶颈。将多个节点数据汇总到pushgateway,如果pushgateway挂了,受影响比多个target大
  2. Prometheus拉取状态up只针对pushgateway,无法做到对每个节点有效
  3. pushgateway可以持久化推送给它的所有监控数据,因此, 即使你的监控节点已经下线,Prometheus还会拉取到旧的监控数据,需要手动清理pushgateway不要的数据
  4. pushgateway 并不能对发送过来的脚本采集数据进行更智能的判断,加入脚本中间采集出了问题,那么有问题的数据pushgateway一样照单全收发送给Prometheus

即:
pushgateway是另一种采用被动推送的方式(而不是exporter主动获取)获取监控数据的prometheus插件。它是可以单独运行在任何节点上的插件(并不一定要在被监控客户端),然后通过用户自定义开发脚本把需要监控的数据发送给pushgateway,然后pushgateway再把数据推送给Prometheus_server(pushgateway本身没有任何抓取监控数据的功能,它只是被动的等待数据推送过来)
在这里插入图片描述在这里插入图片描述

pushgateway安装及使用

主机名 角色 IP 说明
ds-master client 192.168.126.90 使用脚本采集本机数据,push给pushgateway
ds-slave pushgateway 192.168.126.91 安装pushgateway,接收来自客户端的数据并pull给prometheus
test prometheus 192.168.126.120 安装prometheus,存储并分析数据

所有主机准备工作

yum install ntpdate -y
ntpdate ntp1.aliyun.com
hwclock -w
crontab -e
sed -i 's/SELINUX=enforcing/SLINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

安装pushgateway

二进制包下载解压后即可使用,官网地址:https://prometheus.io/

[root@ds-slave ~]# ifconfig ens32| awk 'NR==2 {print $2}'
192.168.126.91

[root@ds-slave ~]# wget https://github.com/prometheus/pushgateway/releases/download/v1.4.1/pushgateway-1.4.1.linux-amd64.tar.gz
[root@ds-slave ~]# ls
pushgateway-1.4.1.linux-amd64.tar.gz
[root@ds-slave ~]# tar xf pushgateway-1.4.1.linux-amd64.tar.gz -C /usr/local
[root@ds-slave ~]# mv /usr/local/pushgateway-1.4.1.linux-amd64/ /usr/local/pushgateway
# 版本等信息
[root@ds-slave ~]# /usr/local/pushgateway/pushgateway --version
pushgateway, version 1.4.1 (branch: HEAD, revision: 6fa509bbf4f082ab8455057aafbb5403bd6e37a5)
  build user:       root@da864be5f3f0
  build date:       20210528-14:30:10
  go version:       go1.16.4
  platform:         linux/amd64

# 查看pushgateway启动参数
[root@ds-slave ~]# /usr/local/pushgateway/pushgateway -h
usage: pushgateway [<flags>]

The Pushgateway

Flags:
  -h, --help                     Show context-sensitive help (also try --help-long and --help-man).
      --web.config.file=""       [EXPERIMENTAL] Path to configuration file that can enable TLS or
                                 authentication.
      --web.listen-address=":9091"  # 指定服务端口,默认为9091
                                 Address to listen on for the web interface, API, and telemetry.
      --web.telemetry-path="/metrics"  
                                 Path under which to expose metrics.
      --web.external-url=        The URL under which the Pushgateway is externally reachable.
      --web.route-prefix=""      Prefix for the internal routes of web endpoints. Defaults to the
                                 path of --web.external-url.
      --web.enable-lifecycle     Enable shutdown via HTTP request.
      --web.enable-admin-api     # 启用后可以通过api来对prometheus进行查询和管理
      --persistence.file=""      #持久化存储的文件,如果为空,存储在内存中
      --persistence.interval=5m  #持久化存储的间隔时间
      --push.disable-consistency-check  
                                 Do not check consistency of pushed metrics. DANGEROUS.
      --log.level=info           Only log messages with the given severity or above. One of: [debug,
                                 info, warn, error]
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]
      --version                  Show application version.

配置成systemd服务

[root@ds-slave ~]# vim /usr/lib/systemd/system/pushgateway.service
[Unit]
Description=pushgateway
Documentation=https://github.com/prometheus/pushgateway
After=network.target 

[Service]
Type=simple
User=root
WorkingDirectory=/usr/local/pushgateway
ExecStart=/usr/local/pushgateway/pushgateway \
                --web.enable-admin-api  \
                --persistence.file="/usr/local/pushgateway/pushfile.txt" \
                --persistence.interval=10m 	# 为了防止 pushgateway 重启或意外挂掉,导致数据丢失,可以通过 --persistence.file 和 --persistence.interval 参数将数据持久化下来。
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@ds-slave ~]# systemctl start pushgateway
[root@ds-slave ~]# systemctl status pushgateway
● pushgateway.service - pushgateway
   Loaded: loaded (/usr/lib/systemd/system/pushgateway.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-10-01 11:28:25 CST; 4s ago
     Docs: https://github.com/prometheus/pushgateway
 Main PID: 11572 (pushgateway)
   Memory: 11.0M
   CGroup: /system.slice/pushgateway.service
           └─11572 /usr/local/pushgateway/pushgateway --web.enable-admin-api --persistence.file="/...

Oct 01 11:28:25 ds-slave systemd[1]: Started pushgateway.
Oct 01 11:28:25 ds-slave systemd[1]: Starting pushgateway...
Oct 01 11:28:25 ds-slave pushgateway[11572]: level=info ts=2021-10-01T03:28:25.872Z caller=main...5)"
Oct 01 11:28:25 ds-slave pushgateway[11572]: level=info ts=2021-10-01T03:28:25.872Z caller=main...0)"
Oct 01 11:28:25 ds-slave pushgateway[11572]: level=info ts=2021-10-01T03:28:25.882Z caller=main...091
Oct 01 11:28:25 ds-slave pushgateway[11572]: level=info ts=2021-10-01T03:28:25.883Z caller=tls_...lse
Hint: Some lines were ellipsized, use -l to show in full.
[root@ds-slave ~]# systemctl enable pushgateway
Created symlink from /etc/systemd/system/multi-user.target.wants/pushgateway.service to /usr/lib/systemd/system/pushgateway.service.

[root@ds-slave ~]# ss -aulntp | grep 9091
tcp    LISTEN     0      128      :::9091                 :::*                   users:(("pushgateway",pid=11572,fd=3))
[root@ds-slave ~]# ps -aux | grep [p]ushgateway
root      11572  0.0  1.1 716392 17104 ?        Ssl  11:28   0:00 /usr/local/pushgateway/pushgateway --web.enable-admin-api --persistence.file="/usr/local/pushgateway/pushfile.txt" --persistence.interval=10m

测试
在这里插入图片描述

prometheus配置

使用上面安装好的,修改配置文件

[root@test ~]# cd /usr/local/prometheus/
[root@test prometheus]# vim prometheus.yml
# 添加如下内容:
  - job_name: "pushgateway"
    static_configs:
      - targets: ["192.168.126.91:9091"]
        labels:
          instance: pushgateway

# 启动
[root@test prometheus]# nohup ./prometheus &
[1] 7114
[root@test prometheus]# nohup: ignoring input and appending output to ‘nohup.out’

查看pushgateway是否添加成功

在这里插入图片描述

采集数据客户端

API 方式 Push 数据到 PushGateway

接下来,我们要 Push 数据到 PushGateway 中,可以通过其提供的 API 标准接口来添加,默认 URL 地址为:http://<ip>:9091/metrics/job/<JOBNAME>{/<LABEL_NAME>/<LABEL_VALUE>},其中<JOBNAME>是必填项,为 job 标签值,后边可以跟任意数量的标签对,一般我们会添加一个 instance/<INSTANCE_NAME>实例名称标签,来方便区分各个指标。

接下来,可以 Push 一个简单的指标数据到 PushGateway 中测试一下。

[root@ds-master ~]# echo "test_metric 123456" | curl --data-binary @- http://192.168.126.91:9091/metrics/job/test_job

执行完毕,刷新一下 PushGateway UI 页面,此时就能看到刚添加的 test_metric 指标数据了。

在这里插入图片描述
不过我们会发现,除了 test_metric 外,同时还新增了 push_time_seconds 和 push_failure_time_seconds 两个指标,这两个是 PushGateway 系统自动生成的相关指标。

此时,我们在 Prometheus UI 页面上 Graph 页面可以查询的到该指标了。

在这里插入图片描述

这里要着重提一下的是,上图中 test_metric 我们查询出来的结果为:test_metric{exported_job="test_job",instance="pushgateway",job="pushgateway"}

会发现好像不太对劲,刚刚提交的指标所属 job 名称为 test_job ,为啥显示的为 exported_job=“test_job” ,而 job 显示为 job=“pushgateway” ,这显然不太正确,那这是因为啥?其实是因为 Prometheus 配置中的一个参数 honor_labels (默认为 false)决定的。

因为prometheus配置pushgateway 的时候,也会指定job和instance,但是它只表示pushgateway实例,不能真正表达收集数据的含义。所以在Prometheus配置文件中配置pushgateway时需要添加honor_labels:true(默认为 false)配置项,避免收集数据本身的job和instance被覆盖。

此时,修改Prometheus配置文件

[root@test prometheus]# vim /usr/local/prometheus/prometheus.yml 
  - job_name: "pushgateway"
    honor_labels: true	# 此行为添加的
    static_configs:
      - targets: ["192.168.126.91:9091"]
        labels:
          instance: pushgateway

# 重启prometheus
[root@test prometheus]# pkill prometheus
[root@test prometheus]# nohup ./prometheus &
[1] 7181
[root@test prometheus]# nohup: ignoring input and appending output to ‘nohup.out’

上边 Push 指标数据是通过命令行追加方式,少量数据还凑合,如果需要 Push 的数据比较大时,就不太方便了,这里我们也可以通过将指标数据写入到文件,然后将文件内容提交也可以正常添加到 PushGateway。也可以直接使用脚本搞定

# 抓取内存数据脚本
[root@ds-master ~]# vim mem_grab.sh
#!/bin/bash 
# desc push memory info 

total_memory=$(free |awk '/Mem/{print $2}')
used_memory=$(free |awk '/Mem/{print $3}')

job_name="custom_memory"
instance_name="192.168.126.90"

cat <<EOF | curl --data-binary @- http://192.168.126.91:9091/metrics/job/$job_name/instance/$instance_name
#TYPE custom_memory_total  gauge
custom_memory_total $total_memory
#TYPE custom_memory_used  gauge
custom_memory_used $used_memory
EOF

# 执行即可
[root@ds-master ~]# sh mem_grab.sh

执行完毕,刷新一下 PushGateway UI 页面,此时就能看到上面添加的指标(custom_memory_total和custom_memory_used)数据了。

在这里插入图片描述
此时,我们在 Prometheus UI 页面上 Graph 页面可以查询的到这两个指标(custom_memory_total和custom_memory_used)了。
在这里插入图片描述
在这里插入图片描述
此时,可以看到能够正确匹配到 Push 的指标值对应到 job 和 instance 上了。这里说明一下 honor_labels 的作用:因为 Prometheus 配置 PushGateway 的时候,也会指定 job 和 instance,但是它只表示 PushGateway 实例本身,不能真正表达收集数据的含义。所以配置 PushGateway 需要添加 honor_labels:true 参数,避免收集数据本身的 job 和 instance 被覆盖。

最后,如果要删除某一个指标,同样可以通过 API 方式触发删除。例如删除 job=“custom_memory” 组下的所有指标值,可以执行如下命令:

curl -X DELETE http://192.168.126.91:9091/metrics/job/custom_memory

此时在Prometheus UI 页面上 Graph 页面就无法查询的到job=custom_memory下的所有指标

注意:删除 job=“custom_memory” 组下的所有指标值,不包括 {job=“test_job”, instance=“192.168.126.90”} 中的指标值,虽然它们的 job 名称都为 custom_memory,所以在PushGateway UI 页面上还是会有 {job=“test_job”, instance=“192.168.126.90”} 中的指标值。如果想删除该指标值,那么需要执行如下命令:

curl -X DELETE http://192.168.126.91:9091/metrics/job/custom_memory/instance/192.168.126.90

那么此时在PushGateway UI 页面上的{job=“test_job”, instance=“192.168.126.90”} 指标也就被删除了

同样,我们也可以在 PushGateway UI 页面指定指标记录后边,点击 Delete Group 按钮来删除。

使用 PushGateway 注意事项:

  • 指标值只能是数字类型,非数字类型报错。 echo "test_metric 12.34.56ff" | curl --data-binary @- http://192.168.126.91:9091/metrics/job/test_job_1 text format parsing error in line 1: expected float as value, got "12.34.56ff"
  • 指标值支持最大长度为 16 位,超过16 位后默认置为 0 echo "test_metric 1234567898765432123456789" | curl --data-binary @- http://192.168.126.91:9091/metrics/job/test_job_2 # 实际获取值 test_metric{job=“test_job_2”} 1234567898765432200000000
  • PushGateway 数据持久化操作 默认 PushGateway 不做数据持久化操作,当 PushGateway 重启或者异常挂掉,导致数据的丢失,我们可以通过启动时添加--persistence.file--persistence.interval参数来持久化数据。--persistence.file表示本地持久化的文件,将 Push 的指标数据持久化保存到指定文件,--persistence.interval 表示本地持久化的指标数据保留时间,若设置为 5m,则表示 5 分钟后将删除存储的指标数据。/usr/local/pushgateway/pushgateway --persistence.file="pushfile.txt" --persistence.interval=5m
  • PushGateway 推送及 Prometheus 拉取时间设置 Prometheus 每次从 PushGateway 拉取的数据,并不是拉取周期内用户推送上来的所有数据,而是最后一次 Push 到 PushGateway 上的数据,所以推荐设置推送时间小于或等于 Prometheus 拉取的时间,这样保证每次拉取的数据是最新 Push 上来的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Prometheus、Node_Exporter、PushGateway的使用 的相关文章

  • 使用 prometheus 统计 k8s 集群 cpu/内存使用情况

    我想用prometheus计算k8s集群cpu 内存使用情况 不是k8s pod使用情况 这样我就可以在grafana中显示 I use sum container memory usage bytes id 获取 k8s 集群使用的内存
  • 普罗米修斯上的多个目标

    我已经在Centos上配置了prometheus 版本详细信息如下 prometheus 2 5 0 linux 386 我在 prometheus yml 配置文件中添加了两个目标 所有服务器节点导出器都在运行 配置如下 scrape c
  • Prometheus Blackbox_exporter笔记

    一 安装Promtheus 在 Prometheus 官网 Download Prometheus 获取适用于 Linux 的 Prometheus 安 装包 这里我选择最新的 2 46 0 版本 我是 Linux 系统 选择下载 prom
  • 如何使用 --set 来设置 Prometheus 图表的值?

    例如 设置alertmanager ingress annotations要添加两个项目 这两种方法都不起作用 helm install stable prometheus set alertmanager ingress enabled
  • 如何以零停机时间将 istio 1.4.3 升级到最新版本

    我是新聘的工程师 最近开始使用 istio 我的应用程序当前在 istio 1 4 3 上运行 当我尝试使用 istioctl Upgrade 升级到最新版本时遇到问题 以下是我尝试过的步骤 1 使用 istioctl version 验证
  • 带有正则表达式的标签-普罗米修斯

    我正在尝试使用正则表达式添加新标签 名称实例是pr na01 na02 A我试图只得到pr na01 所以我这样做了 source labels meta ec2 tag Name regex target label test repla
  • Grafana“Node Exporter Full”仪表板在导入后不显示任何数据

    我正在尝试从这里导入节点导出器完整仪表板 https grafana com grafana dashboards 1860 https grafana com grafana dashboards 1860 但是当我导入仪表板时 它什么也
  • 每次出现错误时使用 prometheus 创建警报

    我是普罗米修斯和警报系统的新手 我开发了一个微服务并添加了指标代码 以便在出现错误时获取增量总数 现在我正在尝试创建一个警报 以便每当错误增加时 它应该标记出来并发送邮件 但我无法针对这种情况形成正确的查询 我使用了诸如 error tot
  • Prometheus 为每个 pod 的多个指标端点抓取配置

    我们有一个 Kubernetes Pod 它提供多个指标端点 3093 metrics and 9113 metrics 但它还有一个不提供任何指标的端口 80 TL DR 是否可以只刮掉端口3093 and 9113 我们正在使用示例配置
  • Prometheus Java 摘要指标是线程安全的吗?

    普罗米修斯是Java吗Summary对象线程安全 如果我在类中将其声明为静态 则该类的所有实例都将使用它 Prometheus 是否为该度量对象实现了线程安全 Prometheus 客户端库负责处理方向检测的线程安全等细节 例如Summar
  • 为什么prometheus Operator无法启动

    我正在尝试在全新的 k8s 集群中使用操作符创建 prometheus 我使用以下文件 我正在创建一个命名空间监控 应用这个文件 就可以正常工作了 apiVersion apps v1beta2 kind Deployment metada
  • PromQL if then 语句等效

    我有一个执行计数的简单 PromQL 查询 sum up container name my container environment name env 这是 Grafana 仪表板的一部分 允许从下拉菜单中选择 env 我想根据环境执行
  • 如何配置 prometheus-operator 从 Kubernetes 上的 cAdvisor 收集?

    我在用普罗米修斯操作员 https github com coreos prometheus operator管理一个普罗米修斯 https prometheus io 部署在我的库伯内斯 https kubernetes io 簇 该设置
  • 如何使用 re2 正则表达式否定字符串模式?

    我正在使用谷歌re2 https github com google re2 wiki Syntax用于查询目的的正则表达式普罗米修斯 https prometheus io docs prometheus latest querying
  • 获取 Pod 处于挂起状态的平均时间

    我正在尝试使用 prometheus 计算 pod 在 grafana 中处于挂起状态的平均时间 我可以使用此查询生成一个图表 以获取一段时间内处于挂起状态的 Pod 数量 sum kube pod status phase phase P
  • 让 Prometheus 发送 SQL 查询

    我正在尝试使用普罗米修斯 https prometheus io 监视我的 MySQL 数据库 但似乎找不到添加 SQL 查询的区域 例如 我想运行一个返回值的 SQL 查询 然后将该值添加到图表中 发送警报 有没有办法让 Promethe
  • 使用 Prometheus 获取总磁盘空间和可用磁盘空间

    我尝试获取 Kubernetes VM 上的总磁盘空间和可用磁盘空间 以便可以显示其已占用空间的百分比 我尝试了名称中包含 文件系统 的各种指标 但没有一个显示正确的总磁盘大小 应该使用哪一个来做到这一点 这是我尝试过的指标列表 node
  • 如何使用 kubeadm 升级来更改 kubeadm-config 中的某些功能

    我想在现有的 kubernetes 集群 v1 10 上安装 kube prometheus 在此之前 文档说我需要将控制器 调度器的IP地址从127 0 0 1 to 0 0 0 0 并且还推荐使用kubeadm 配置升级 https k
  • 将 Kubernetes 抓取目标添加到不在 Kubernetes 中的 Prometheus 实例

    I run 普罗米修斯 https prometheus io 本地为 http localhost 9090 targets docker run name prometheus d p 127 0 0 1 9090 9090 prom
  • 没有 Spring 的自定义 Prometheus 指标

    我需要为 Web 应用程序提供自定义指标 问题是我不能使用 Spring 但我必须使用 jax rs 端点 要求非常简单 想象一下 您有一个包含键值对的映射 其中键是指标名称 值是一个简单的整数 它是一个计数器 代码会是这样的 public

随机推荐

  • 8-js高级-4

    JavaScript 进阶 4 深浅拷贝 浅拷贝 浅拷贝 把对象拷贝给一个新的对象 开发中我们经常需要复制一个对象 如果直接赋值 则复制的是地址 修改任何一个对象 另一个对象都会变化 常见方法 拷贝对象 Object assgin 展开运算
  • postgresql安装报错

    postgresql安装报错 版本问题 版本问题 第一次下载安装postgresql 进到官网 随便点了一个12得版本进行下载 postgresql 12 12 1 windows x64 下载后双击运行 直接提示 百度了一圈 有说 用管理
  • Python实战RBF神经网络

    程序员A 哥们儿 最近手头紧 借点钱 程序员B 成啊 要多少 A 1000行不 B 咱俩谁跟谁 给你凑个整 这1024 拿去吧 之前我们讲了神经网络 人工神经网络是受到人类大脑结构的启发而创造出来的 这也是它能拥有真智能的根本原因 在我们的
  • pycharm创建py脚本自动增加注释和描述

    pycharm创建py脚本自动增加注释和描述 创建脚本时可自动带入简单注释 设备 MAC 注释内容如下 Time DATE TIME Author fanzw File NAME py Description 可自由扩展 效果如下
  • JVM的垃圾回收机制 总结(垃圾收集、回收算法、垃圾回收器)

    如果想了解Java内存模型参考 jvm内存模型 和内存分配以及jdk jre jvm是什么关系 阿里 美团 京东 相信和小编一样的程序猿们在日常工作或面试当中经常会遇到JVM的垃圾回收问题 有没有在夜深人静的时候详细捋一捋JVM垃圾回收机制
  • 《C++ System Programming Cookbook》第一章读书笔记

    阅读书籍 C System Programming Cookbook 记录 使用docker linux 用户管理常见命令 adduser 创建用户 login 用户登录 passwd 修改用户密码 usermod a G 用户加入组 us
  • 【C语言-进阶】自定义类型详解(结构体+枚举+联合)

    结构体的声明与定义 s0 s1 s2都是struct Stu 的别名 即结构体的重命名 这种情况下就不可以在声明的同时定义变量了 sp spp都是sturct Stu类型的 n1为结构体声明的同时定义变量 在下面重新赋值时不能只写n1 还要
  • Jetson Nano中使用Darknet(AlexeyAB版本)运行YOLOV4

    之前几天使用了Darknet来跑YOLOV3 或多或少遇到了一些问题 一些问题也还没有解决 YOLOV3的作者呢之前宣布自己不再更新了 那么AlexeyAB就搞了YOLOV4的版本 接下来我们就尝试一下YOLOV4 安装Darknet Al
  • element UI 动态生成表头

    最近开始搞vue了 由于 element UI 中的 table 不能像 antd 里的 table 直接注入 json 字符串生成表头 这导致了不能轻松的通过后台生成表格 或是对表头进行排序 在网上参考找了一种最简易的方法 可以给表格里面
  • VS社区版离线试用到期解决办法

    很多朋友在学习工作中 有时需要离线安装VS2017 2019 而社区版 而社区版试用时间只有30天 到期后无法继续使用 下面教大家一种解决这个问题的办法 如下 1 下载离线授权文件 VS离线授权文件 1 开始 gt Visual Studi
  • 归并排序(递归)

    归并排序是通过递归的思想实现的排序算法 什么是递归呢 递归就是需要我们转变思想 思考将一个大事转变为一个个与原问题相似的小事 而我们需要对一个整型数组排序 应该怎样将排序整个数组这么大的规模转变为排序两个数这么小的规模呢 假设我们需要排序的
  • popwindow下拉筛选 二级联动_Excel技巧:一、二、三级联动下拉菜单制作方法分享...

    平时工作过程中 经常会用到Excel表格 关于表格数据处理还有一些小技巧的 掌握一个小技巧 可能对办公效率的提高起到很大的作用 表格中对常见的可能就是表格下拉菜单的设置了 比如说 性别 这一栏 如果每次填写都得重新输入的话 要是人数众多这工
  • vue 基于el-table实现多页多选/单选、翻页回显过程

    1 问题 表格可以多选 单选 分页的时候 表格数据能进行回显 type selection 可以设置表格进行多选 row key 指定数据的 Key 用来优化 Table 的渲染 select单选的事件 select all多选的事件 这两
  • 整数与IP地址间的转换Python

    data input split IP地址转整数 a b caozuo a append bin int i 2 rjust 8 0 for i in data for i in a b i ac int b 2 print ac data
  • SQL查询优化

    一 为什么要对SQL进行优化 我们开发项目上线初期 由于业务数据量相对较少 一些SQL的执行效率对程序运行效率的影响不太明显 而开发和运维人员也无法判断SQL对程序的运行效率有多大 故很少针对SQL进行专门的优化 而随着时间的积累 业务数据
  • AD20圆形PCB板铺铜(铜皮直径可小于板框直径)

    首先 板子是圆形的 可能会需要铺圆形的铜皮 1 画一个圆 选中后右键 选择铺铜操作 铺铜管理器 2 打开铺铜管理器后 选择来自新的 多边形 选择板外形 3 右侧选择layer以及net 设置铺铜相关的属性 4 若所铺圆形铜皮直径小于圆形板框
  • MongoDB保存与读取Numpy与Pandas格式的数据到一个数据格里

    对于Numpy格式的数据 保存时使用 Binary pickle dumps array protocol 2 其中array就是ndarry格式的数组 加载时使用 pickle loads result numpy 对于Pandas格式的
  • 动态规划问题——最长上升子序列(LIS)(二)

    原文转载自我的博客benym cn 推荐链接 动态规划问题 最长上升子序列 LIS 一 动态规划问题 最长上升子序列 LIS 三 题目描述 一天 小凯同学震惊的发现 自己无内的PM2 5指标是有规律的 小凯采样了PM2 5数值 发现PM2
  • Exception in thread “main“ org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obta

    问题描述 Exception in thread main org springframework jdbc CannotGetJdbcConnectionException Failed to obtain JDBC Connection
  • Prometheus、Node_Exporter、PushGateway的使用

    文章目录 一 prometheus server端部署prometheus 二 在被监控节点部署 node exporter 三 使用 PushGateway 进行数据上报采集 一 prometheus server端部署prometheu