解析prometheus+grafana監(jiān)控nginx的方法

?在prometheus需要向ngxin中打入探針,通過探針獲取ngxin信息,并通過接口輸出。下文將講述如何監(jiān)控ngxin。
1.下載
為了各位小伙伴方便,這里提供了一波下載地址,如果模板不是特別滿意,也可以去官網(wǎng)自行下載。
nginx:
鏈接: https://pan.baidu.com/s/1QxcWrxAEARlEhxSb2ZETjQ
提取碼: 6fp5
nginx-module-vts-master:
鏈接: https://pan.baidu.com/s/1gCyAithAlRkORuZwhpcPmA?
提取碼: h9aa
nginx-vts-exporter
鏈接: https://pan.baidu.com/s/1gVB_I6ifDbeNIBX5x9pGAA
提取碼: upkw?
nginx-vts-stats_rev2 (grafana顯示模板)
鏈接: https://pan.baidu.com/s/1VI9V395OemPkf6W-sNL9HQ
提取碼: da56?
2.安裝nginx與nginx-vts-exporter
1.解壓nginx-vts-exporter
這里nginx是重新安裝 ,解壓nginx-vts-exporter 這里放在usr/local。
unzip nginx-module-vts-master.zip
這里注意nginx版本有要求否則會(huì)報(bào)錯(cuò),以下是nginx對(duì)應(yīng)的版本。

2.解壓nginx。
tar -zxvf nginx-1.14.2.tar.gz
3.安裝
把nginx-vts-exporter放到nginx路徑 ,并執(zhí)行安裝操作。
cd usr/local/nginx-1.14.2 ./configure --prefix=/usr/local/nginx --add-module=usr/local/nginx-module-vts-master/ 注意:注意prefix=/usr/local/nginx意思是安裝位置為/usr/local/nginx文件夾 make install
4.修改conf文件
http {
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
...
server {
...
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
5.啟動(dòng)
cd /usr/local/nginx/sbin ./nginx

訪問http://ip/status出現(xiàn)以下顯示則表示nginx與nginx-vts-exporter安裝成功。
3.安裝nginx-vts-exporter-0.9.1.linux-amd64.tar
這里安裝包放在usr/local下,解壓。
tar -zxvf nginx-vts-exporter-0.9.1.linux-amd64.tar
啟動(dòng)。
cd /usr/local/nginx-vts-exporter-0.9.1.linux-amd64 nohup ./nginx-vts-exporter -nginx.scrape_uri http://ip/status/format/json &
輸入http://ip:9913/metrics,如果出現(xiàn)以下證明完成。

4.配置Prometheus
修改/usr/local/prometheus-2.17.1.linux-amd64/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'
static_configs:
- targets: ['localhost:9090']
- job_name: 'nginx'
static_configs:
- targets: ['ip:9913']
出現(xiàn)以下配置成功。

5.配置Grafana
輸入grafana可視化頁面地址:ip:3000。
1.配置數(shù)據(jù)源 (prometheus地址:ip:9090)


上圖填寫你prometheus地址,端口切記填寫9090,點(diǎn)擊save后,如果失敗會(huì)有提示 。
2.可視化界面模板

選擇上文配置好的數(shù)據(jù)源,prometheus選項(xiàng)就是上文配置的數(shù)據(jù)源。

3.驗(yàn)證
出現(xiàn)以下顯示則表示成功。

到此這篇關(guān)于解析prometheus+grafana監(jiān)控nginx的方法的文章就介紹到這了,更多相關(guān)prometheus+grafana監(jiān)控nginx內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信