日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

【DevOps】 Prometheus + Grafana (一)安装配置与系统级监控

發(fā)布時(shí)間:2024/1/1 windows 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【DevOps】 Prometheus + Grafana (一)安装配置与系统级监控 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 關(guān)于Prometheus
      • 介紹
      • 數(shù)據(jù)格式與實(shí)例
      • 四種數(shù)據(jù)類(lèi)型
      • promql
      • 相關(guān)組件
  • Centos7 安裝 Prometheus
      • Centos7 安裝 Go 環(huán)境
      • Centos7 安裝 Prometheus
      • 配置 Prometheus
      • 啟動(dòng)與使用
  • Centos7 安裝與配置 Grafana
      • 安裝 Grafana
      • 配置數(shù)據(jù)源
      • dashboards
  • Prometheus + Grafana 監(jiān)控案例
      • 監(jiān)控 Linux 服務(wù)器
      • 監(jiān)控 mysql
      • 監(jiān)控 redis
      • 監(jiān)控 kafka
      • 監(jiān)控 Nginx
      • 監(jiān)控業(yè)務(wù)
  • Prometheus 查詢(xún)
  • 參考

關(guān)于Prometheus


介紹

1、prometheus 存儲(chǔ)的是時(shí)序數(shù)據(jù),適合監(jiān)控一些隨時(shí)間變化的場(chǎng)景

2、原理:通過(guò)HTTP協(xié)議周期性抓取(Pull方式)被監(jiān)控組件的狀態(tài),好處是任意組件只要提供HTTP接口就可以接入監(jiān)控系統(tǒng),不需要任何SDK或者其他的集成過(guò)程。這樣做非常適合虛擬化環(huán)境,比如VM或者Docker。輸出被監(jiān)控組件信息的Http接口叫exporter。

3、特點(diǎn)

Prometheus Server 負(fù)載定時(shí)在目標(biāo)上抓取 metrics(指標(biāo))數(shù)據(jù),每個(gè)抓取目標(biāo)都需要暴露一個(gè) HTTP 服務(wù)接口用于 Prometheus 定時(shí)抓取。這種調(diào)用被監(jiān)控對(duì)象獲取監(jiān)控?cái)?shù)據(jù)的方式被稱(chēng)為 Pull(拉)。Pull 方式體現(xiàn)了 Prometheus 獨(dú)特的設(shè)計(jì)哲學(xué)與大多數(shù)采用 Push(推)方式的監(jiān)控不同

Pull 方式的優(yōu)勢(shì)是能夠自動(dòng)進(jìn)行上游監(jiān)控和水平監(jiān)控,配置更少,更容易擴(kuò)展,更靈活,更容易實(shí)現(xiàn)高可用。簡(jiǎn)單來(lái)說(shuō)就是 Pull 方式可以降低耦合。由于在推送系統(tǒng)中很容易出現(xiàn)因?yàn)橄虮O(jiān)控系統(tǒng)推送數(shù)據(jù)失敗而導(dǎo)致被監(jiān)控系統(tǒng)癱瘓的問(wèn)題。所以通過(guò) Pull 方式,被采集端無(wú)需感知監(jiān)控系統(tǒng)的存在,完全獨(dú)立于監(jiān)控系統(tǒng)之外,這樣數(shù)據(jù)的采集完全由監(jiān)控系統(tǒng)控制

4、時(shí)序(time series)是由名字(Metric)以及一組key/value標(biāo)簽定義的,具有相同的名字以及標(biāo)簽屬于相同時(shí)序

5、metric名字:表示metric的功能,如 http_request_total

數(shù)據(jù)格式與實(shí)例

1、數(shù)據(jù)格式:<metric name>{<label name>=<label value>, ...}

2、實(shí)例

up{job="<job-name>", instance="<instance-id>"}: 1 表示該實(shí)例正常工作 up{job="<job-name>", instance="<instance-id>"}: 0 表示該實(shí)例故障

四種數(shù)據(jù)類(lèi)型

1、Counter

Counter用于累計(jì)值,例如記錄請(qǐng)求次數(shù)、任務(wù)完成數(shù)、錯(cuò)誤發(fā)生次數(shù)。一直增加,不會(huì)減少。重啟進(jìn)程后,會(huì)被重置。

http_response_total{method=”GET”,endpoint=”/api/tracks”} 100

2、Gauge

Gauge 瞬時(shí)數(shù)據(jù),比如內(nèi)存使用率、CPU使用率等。

3、Histogram

<basename>_bucket{le="<upper inclusive bound>"} <basename>_bucket{le="+Inf"} <basename>_sum <basename>_count

Histogram(直方圖)可以理解為柱狀圖的意思,常用于跟蹤事件發(fā)生的規(guī)模,例如:請(qǐng)求耗時(shí)、響應(yīng)大小。它特別之處是可以對(duì)記錄的內(nèi)容進(jìn)行分組,提供count和sum全部值的功能。

4、Summary

<basename>{quantile="<φ>"} <basename>_sum <basename>_count

Summary和Histogram十分相似,常用于跟蹤事件發(fā)生的規(guī)模,例如:請(qǐng)求耗時(shí)、響應(yīng)大小。同樣提供 count 和 sum 全部值的功能。

count=7次,sum=7次的值求值。

它提供一個(gè)quantiles的功能,可以按%比劃分跟蹤的結(jié)果。例如:quantile取值0.95,表示取采樣值里面的95%數(shù)據(jù)。

promql

做查詢(xún) 與 報(bào)警

相關(guān)組件

參考:https://baijiahao.baidu.com/s?id=1689945188583938997&wfr=spider&for=pc

1、Prometheus Server:Prometheus 的核心部分,負(fù)責(zé)實(shí)現(xiàn)對(duì)監(jiān)控?cái)?shù)據(jù)的獲取,存儲(chǔ)以及查詢(xún);

  • 靜態(tài)或動(dòng)態(tài)的配置管理監(jiān)控目標(biāo);

  • 本身具有時(shí)序數(shù)據(jù)庫(kù)的功能;

  • 對(duì)外提供自定義的 PromQL 語(yǔ)言,可以查詢(xún)分析;

  • 內(nèi)置 Express Browser UI, 可以通過(guò)該 UI 用 PromQL 實(shí)現(xiàn)數(shù)據(jù)的查詢(xún)以及可視化

2、push gateway:接收由 Client push 過(guò)來(lái)的指標(biāo)數(shù)據(jù),在指定的時(shí)間間隔,由主程序來(lái)抓取;

Prometheus Server 與 Exporter 無(wú)法直接通信時(shí),可以利用 PushGateway 來(lái)進(jìn)行中轉(zhuǎn)。

3、Exporter:采集數(shù)據(jù),并通過(guò) HTTP 服務(wù)的形式暴露給 Prometheus Server;

例子:node_exporter、mysqld_exporter、haproxy_exporter 等。

4、Alertmanager:Prometheus 體系中的告警處理中心;

Prometheus Server 中支持基于 PromQL 創(chuàng)建告警規(guī)則,如果滿(mǎn)足PromQL定義的規(guī)則,則會(huì)產(chǎn)生一條告警,而告警的后續(xù)處理流程則由 AlertManager 進(jìn)行管理;

可以郵件、webhook 等方式預(yù)警。

Centos7 安裝 Prometheus


參考:https://blog.csdn.net/baidu_36943075/article/details/91829364

Centos7 安裝 Go 環(huán)境

wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz #下載包 sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz #解壓包 sudo vim /etc/profile #打開(kāi)環(huán)境變量配置文件,寫(xiě)入如下內(nèi)容(位置根據(jù)實(shí)際的存放位置為準(zhǔn)) export GO_HOME=/usr/local/go export PATH=$GO_HOME/bin:$PATH source /etc/profile # 重啟環(huán)境變量 go version #查看版本號(hào)驗(yàn)證是否安裝成功

Centos7 安裝 Prometheus

cd /usr/softwarewget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gztar -zxvf prometheus-2.26.0.linux-amd64.tar.gz -C /usr/local/

配置 Prometheus

官網(wǎng)說(shuō)明:https://prometheus.io/docs/prometheus/latest/configuration/configuration/

https://www.jianshu.com/p/b9d15f236e02

global:全局配置
alerting:Alertmanager相關(guān)配置
rule_files:規(guī)則文件列表,使用’evaluation_interval’ 參數(shù)抓取
scrape_configs:抓取配置列表

cd /usr/local/prometheus-2.26.0.linux-amd64 vim prometheus.yml # my global config global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files:# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus'# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ['localhost:9090']

啟動(dòng)與使用

1、啟動(dòng)

注意:prometheus 沒(méi)有自帶任何加密措施,因此盡量不要暴露所使用的端口,通過(guò) grafana去查看監(jiān)測(cè)數(shù)據(jù),實(shí)在要用 prometheus 的UI 的話(huà),可以做 Nginx 加密;

# 后臺(tái)啟動(dòng),并修改開(kāi)放端口 nohup ./prometheus --config.file=prometheus.yml --web.enable-lifecycle --web.listen-address=:19908 & # 查看啟動(dòng)狀態(tài) ps -ef | grep prometheus lsof -i:19908# 查看啟動(dòng)的命令行參數(shù) ./prometheus -h

2、常用啟動(dòng)參數(shù)

# 啟動(dòng)使用的配置文件 --config.file=prometheus.yml # 是否啟用 API,啟用API后,可以通過(guò) API指令完成 Prometheus 的 停止、熱加載配置文件 等 --web.enable-lifecycle # 服務(wù)監(jiān)聽(tīng)端口 --web.listen-address=:19908 # 是否啟用 admin api 的訪問(wèn)權(quán)限(TSDB管理API) --web.enable-admin-api # 保留數(shù)據(jù)的天數(shù) --storage.tsdb.retention.time=7d

3、API

# 查看當(dāng)前配置 curl http://localhost:9090/api/v1/status/config# 使修改后的配置生效 curl -XPOST http://localhost:19908/-/reload

4、強(qiáng)行關(guān)閉 Prometheus

lsof -i:19908 kill -9 pid

Centos7 安裝與配置 Grafana


官網(wǎng):https://grafana.com/grafana/download

配置文件說(shuō)明:https://blog.csdn.net/liumiaocn/article/details/104027047

Dashboards :https://grafana.com/grafana/dashboards

安裝 Grafana

wget https://dl.grafana.com/oss/release/grafana-7.5.3-1.x86_64.rpm sudo yum install grafana-7.5.3-1.x86_64.rpm yum clean allvim /etc/grafana/grafana.ini # 編輯 http_port = 13818 # 保存systemctl enable grafana-server systemctl start grafana-server訪問(wèn) ip:13818

配置數(shù)據(jù)源

訪問(wèn) ip:3000,初始用戶(hù)名和密碼都是 admin,修改新密碼后進(jìn)入

1、點(diǎn)擊 Configuration -> Add data source
2、選擇 Prometheus
3、Dashboards 選擇 Prometheus 2.0 Stats ,Import
4、Settings 寫(xiě)入 Prometheus 的 IP 和 端口,我這里寫(xiě)為 http://localhost:19908
5、點(diǎn)擊 Save & Test
6、進(jìn)入 Dashboards,選擇 prometheus-2-0-stats,即可看到監(jiān)控?cái)?shù)據(jù)

dashboards

網(wǎng)址:https://grafana.com/grafana/

服務(wù)器推薦:https://grafana.com/grafana/dashboards/8919

Docker 推薦:https://grafana.com/grafana/dashboards/8321

Prometheus + Grafana 監(jiān)控案例


exporter 案例:https://prometheus.io/docs/instrumenting/exporters/

監(jiān)控 Linux 服務(wù)器

參考: https://www.jianshu.com/p/7bec152d1a1f

1、被監(jiān)控服務(wù)器 同步時(shí)間

yum install ntpdate -yntpdate ntp5.aliyun.comdate # 或 timedatectl

2、在被監(jiān)控的機(jī)器下載與安裝 node_exporter

查看最新 Release:

https://github.com/prometheus/node_exporter/

cd /usr/softwarewget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gztar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/

3、啟動(dòng) node_exporter

命令啟動(dòng) (不推薦):

cd /usr/local/node_exporter-1.1.2.linux-amd64nohup ./node_exporter --web.listen-address=:19918 &

啟動(dòng)參數(shù):

#node_exporter監(jiān)聽(tīng)的端口,默認(rèn)是9100,若需要修改則通過(guò)此參數(shù)。 --web.listen-address=":19918" #獲取metric信息的url,默認(rèn)是/metrics,若需要修改則通過(guò)此參數(shù) --web.telemetry-path="/metrics" #設(shè)置日志級(jí)別 --log.level="info" #設(shè)置打印日志的格式,若有自動(dòng)化日志提取工具可以使用這個(gè)參數(shù)規(guī)范日志打印的格式 --log.format="logger:stderr"

做成系統(tǒng)服務(wù)并啟動(dòng) (優(yōu)秀教程:https://blog.csdn.net/yuesichiu/article/details/51485147)

# centos 7.9 cat > /usr/lib/systemd/system/node_exporter.service << EOF [Unit] Description=node_exporter Documentation=https://prometheus.io/ After=network.target [Service] Type=simple ExecStart=/usr/local/node_exporter-1.1.2.linux-amd64/node_exporter --web.listen-address=:19918 Restart=on-failure [Install] WantedBy=multi-user.target EOFchmod 754 /usr/lib/systemd/system/node_exporter.servicesystemctl daemon-reload && systemctl enable node_exporter.service && systemctl start node_exporter.service systemctl daemon-reload && systemctl restart node_exporter.service && systemctl status node_exporter systemctl status node_exporter# ubuntu 14.04 cd /usr/local/node_exporter-1.1.2.linux-amd64nohup ./node_exporter --web.listen-address=:19918 &# ubuntu 18.04 su # 進(jìn)入 rootcat > /etc/systemd/system/node_exporter.service << EOF [Unit] Description=node_exporter Documentation=https://prometheus.io/ After=network.target [Service] Type=simple ExecStart=/usr/local/node_exporter-1.1.2.linux-amd64/node_exporter --web.listen-address=:19918 Restart=on-failure [Install] WantedBy=multi-user.target EOFchmod 754 /etc/systemd/system/node_exporter.servicesystemctl daemon-reload && systemctl enable node_exporter.service && systemctl start node_exporter.service systemctl daemon-reload && systemctl restart node_exporter.service && systemctl status node_exporter systemctl status node_exporter

查看監(jiān)控指標(biāo):

curl http://localhost:19918/metrics;# 簡(jiǎn)單的指標(biāo)說(shuō)明:node_boot_time: 系統(tǒng)啟動(dòng)時(shí)間 node_cpu: 系統(tǒng)CUP使用情況 node_disk_*: 磁盤(pán)io node_filesystem_*: 文件系統(tǒng)使用量 node_load1: 系統(tǒng)負(fù)載 node_memory_*: 系統(tǒng)內(nèi)存使用量 node_network_*: 網(wǎng)絡(luò)寬帶 node_time: 當(dāng)前系統(tǒng)時(shí)間 go_*: node exporter中g(shù)o相關(guān)指標(biāo) *process_ :**node exporter自身進(jìn)程相關(guān)指標(biāo)

5、prometheus 的配置文件添加監(jiān)控項(xiàng)

Centos機(jī)器 29 臺(tái):

172、173、174、175、176、177、178、179、180、181、182、183、184、185、
186、·187、188、189、190、197、198

89、91、93、94

下載的四臺(tái)

Ubuntu機(jī)器 13 臺(tái):

164、165、166、168、169、170、171
85、86、87、88、90、92

cd /usr/local/prometheus-2.26.0.linux-amd64 vim prometheus.yml - job_name: 'server_91'crape_interval: 8sstatic_configs:- targets: ['192.168.10.106:19918']labels:instance: Prometheus # 保存# 熱重啟 Prometheus curl -XPOST http://localhost:19908/-/reload

6、導(dǎo)入 dashboard

Dashboards -> Manage -> Import -> mport via grafana.com -> 輸入8919 -> 點(diǎn)擊 load

監(jiān)控 mysql

參考:https://www.cnblogs.com/xiangsikai/p/11289675.html

1、在被監(jiān)控的mysql所在的服務(wù)器安裝 mysql_export

cd /usr/softwarewget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gztar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/

2、配置 被監(jiān)控機(jī)器的 mysql

mysql -u root -pCREATE USER 'mysql_exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX'; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'localhost';cd /usr/local/mysqld_exporter-0.12.1.linux-amd64vim .my.cnf[client] user=mysql_exporter password=123456

3 、啟動(dòng) mysql_export

命令啟動(dòng)(不推薦)

cd /usr/local/mysqld_exporter-0.12.1.linux-amd64# 如需修改端口,可加參數(shù) --web.listen-address=:9104(默認(rèn)是9104) nohup ./mysqld_exporter --config.my-cnf=.my.cnf &curl http://localhost:9104/metrics

做成系統(tǒng)服務(wù)啟動(dòng)

# centos 7.9 cat > /usr/lib/systemd/system/mysqld_exporter.service << EOF [Unit] Description=mysqld_exporter After=network.target [Service] Type=simple ExecStart=/usr/local/node_exporter-1.1.2.linux-amd64/node_exporter --config.my-cnf /usr/local/mysqld_exporter-0.12.1.linux-amd64/.my.cnf Restart=on-failure [Install] WantedBy=multi-user.target EOFchmod 754 /usr/lib/systemd/system/mysqld_exporter.servicesystemctl daemon-reload && systemctl enable mysqld_exporter.service && systemctl start mysqld_exporter.service && systemctl status mysqld_exporter systemctl daemon-reload && systemctl restart mysqld_exporter.service && systemctl status mysqld_exporter systemctl status mysqld_exporter

4、配置 Prometheus 配置文件,并熱重啟

- job_name: 'mysql'static_configs:- targets: ['xxx.xxx.xx.164:9104','xxx.xxx.xx.165:9104','xxx.xxx.xx.166:9104'] curl -XPOST http://localhost:19908/-/reload

5、在 Grafana 中 添加 dashboard

Dashboards -> Manage -> Import -> mport via grafana.com -> 輸入7362-> 點(diǎn)擊 load

監(jiān)控 redis

1、在要被監(jiān)控的redis 所在的機(jī)器上下載與安裝 redis_exporter

cd /usr/software/wget https://github.com/oliver006/redis_exporter/releases/download/v1.20.0/redis_exporter-v1.20.0.linux-amd64.tar.gztar -zxvf redis_exporter-v1.20.0.linux-amd64.tar.gz -C /usr/local

2 、啟動(dòng) redis_exporter

命令啟動(dòng)(不推薦)

cd /usr/local/redis_exporter-v1.20.0.linux-amd64# 如需修改端口,可加參數(shù) --web.listen-address=:9121(默認(rèn)是9121) nohup ./redis_exporter -redis.addr localhost:6379 -redis.password 123456 &curl http://localhost:9121/metrics

做成系統(tǒng)服務(wù)啟動(dòng)

# centos 7.9 cat > /usr/lib/systemd/system/redis_exporter.service << EOF [Unit] Description=redis_exporter After=network.target [Service] Type=simple ExecStart=/usr/local/redis_exporter-v1.20.0.linux-amd64/redis_exporter -redis.addr=IP:6379 -redis.password=passwd Restart=on-failure [Install] WantedBy=multi-user.target EOFchmod 754 /usr/lib/systemd/system/redis_exporter .servicesystemctl daemon-reload && systemctl enable redis_exporter .service && systemctl start redis_exporter .service && systemctl status redis_exporter systemctl daemon-reload && systemctl restart redis_exporter .service && systemctl status redis_exporter systemctl status redis_exporter

4、配置 Prometheus 配置文件,并熱重啟

- job_name: redis_exporterstatic_configs:- targets: ['xxx.xxx.xx.85:9121','xxx.xxx.xx.86:9121'] curl -XPOST http://localhost:19908/-/reload

5、在 Grafana 中 添加 dashboard

Dashboards -> Manage -> Import -> mport via grafana.com -> 輸入763-> 點(diǎn)擊 load

https://grafana.com/dashboards/763/revisions

監(jiān)控 kafka

1、在被監(jiān)控的kafka集群所在的任意一臺(tái)服務(wù)器安裝 kafka_exporter

cd /usr/softwarewget https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gztar -zxvf kafka_exporter-1.2.0.linux-amd64.tar.gz -C /usr/local/

2、啟動(dòng) kafka_exporter

命令啟動(dòng)(不推薦)

cd /usr/local/kafka_exporter-1.2.0.linux-amd64# 如需修改端口,可加參數(shù) --web.listen-address=:9308(默認(rèn)是9308) nohup ./kafka_exporter --kafka.server=localhost:9308 &curl http://localhost:9308/metrics

做成系統(tǒng)服務(wù)啟動(dòng)

# centos 7.9 cat > /usr/lib/systemd/system/kafka_exporter.service << EOF [Unit] Description=kafka_exporter Documentation=https://prometheus.io/ After=local-fs.target network-online.target network.target Wants=local-fs.target network-online.target network.target [Service] Type=simple ExecStart=/usr/local/node_exporter-1.1.2.linux-amd64/node_exporter --kafka.server=localhost:9096 Restart=on-failure [Install] WantedBy=multi-user.target EOFchmod 754 /usr/lib/systemd/system/kafka_exporter.servicesystemctl daemon-reload && systemctl enable kafka_exporter.service && systemctl start kafka_exporter.service && systemctl status node_exporter systemctl daemon-reload && systemctl restart kafka_exporter.service && systemctl status kafka_exporter systemctl status node_exporter

3、配置 Prometheus 配置文件,并熱重啟

- job_name: 'kafka'static_configs:- targets: ['xxx.xxx.xx.170:9308'] curl -XPOST http://localhost:19908/-/reload

4、在 Grafana 中 添加 dashboard

7589、10466、11963

Dashboards -> Manage -> Import -> mport via grafana.com -> 輸入7589-> 點(diǎn)擊 load

監(jiān)控 Nginx

參考:
https://it.baiked.com/nginx/2697.html
https://www.cnblogs.com/xiao987334176/p/11180652.html

promethues監(jiān)控nginx可選兩個(gè)exporter,通過(guò)nginx_exporter主要是獲取nginx-status中的內(nèi)建的指標(biāo),nginx自身提供status信息,較為簡(jiǎn)單,promethues中對(duì)應(yīng)的metrics也較少,想要監(jiān)控更多的指標(biāo)可以通過(guò)nginx-vts-exporter采集信息,依賴(lài)在編譯nginx的時(shí)候添加nginx-module-vts模塊來(lái)實(shí)現(xiàn)。

nginx virtual host traffic status模塊是nginx第三方模塊之一,vts提供了訪問(wèn)虛擬主機(jī)狀態(tài)的信息,包含server,upstream以及cache的當(dāng)前狀態(tài),類(lèi)似于NGINX Plus 提供的在線活動(dòng)監(jiān)控功能。

1、安裝 nginx-exporter

docker pull fish/nginx-exporterdocker run -it fish/nginx-exporter# 新開(kāi)一個(gè)終端 docker ps|grep nginx-exporterdocker cp 容器ID:/usr/local/bin/nginx_exporter /opt/# 執(zhí)行成功則說(shuō)明安裝成功 /opt/nginx_exporter --help# 退出容器mkdir -p /etc/nginx_exporter/bin/ mv /opt/nginx_exporter /etc/nginx_exporter/bin/

2、配置 nginx

vi /etc/nginx/sites-enabled/status.conf server {listen 8011;server_name localhost;location /nginx_status {stub_status on;access_log off;allow 127.0.0.1;} } nginx -s reload /etc/nginx/sites-enabled# curl 127.0.0.1:8011/nginx_status

3、封裝為系統(tǒng) service

vim /lib/systemd/system/nginx_exporter.service [Unit] Description=nginx monitor After=network.target[Service] ExecStart=/etc/nginx_exporter/bin/nginx_exporter -nginx.scrape_uri="http://127.0.0.1:8011/nginx_status" ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 TimeoutStopSec=5 KillMode=mixed[Install] WantedBy=multi-user.targetsystemctl daemon-reload systemctl enable nginx_exporter.service systemctl start nginx_exporter.servicenetstat -anpt|grep nginx_exportecurl 127.0.0.1:9113/metrics

4、配置 Prometheus

cd /usr/local/prometheus-2.26.0.linux-amd64 vim prometheus.yml - job_name: nginx_exporterstatic_configs:- targets: ['192.168.10.139:9113']# prometheus 熱重啟 curl -XPOST http://localhost:19908/-/reload

監(jiān)控業(yè)務(wù)

Prometheus 查詢(xún)


http_requests_total http_requests_total{code="200", handler="query"} http_requests_total{code~="2xx"} http_requests_total > 100 http_requests_total[5m] count(http_requests_total) sum(http_requests_total) avg(http_requests_total) topk(3, http_requests_total) irate(http_requests_total[5m])

參考


https://blog.csdn.net/ywd1992/article/details/85989259

prometheus 中文指南:https://yunlzheng.gitbook.io/prometheus-book/

Prometheus 官方文檔:https://prometheus.io/docs/introduction/overview/

Grafana 官方文檔:http://docs.grafana.org/

全面學(xué)習(xí)Prometheus:http://dockone.io/article/5716?tdsourcetag=s_pcqq_aiomsg

Prometheus 非官方中文手冊(cè):https://www.bookstack.cn/read/prometheus-manual/README.md

Prometheus 實(shí)戰(zhàn):https://songjiayang.gitbooks.io/prometheus/content/

prometheus-book:https://yunlzheng.gitbook.io/prometheus-book/

Grafana的一些實(shí)用技巧:https://segmentfault.com/a/1190000013565079

總結(jié)

以上是生活随笔為你收集整理的【DevOps】 Prometheus + Grafana (一)安装配置与系统级监控的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。