久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

基于prometheus如何監(jiān)控nginx

共計(jì) 2899 個(gè)字符,預(yù)計(jì)需要花費(fèi) 8 分鐘才能閱讀完成。

這篇文章主要介紹“基于 prometheus 如何監(jiān)控 nginx”,在日常操作中,相信很多人在基于 prometheus 如何監(jiān)控 nginx 問(wèn)題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”基于 prometheus 如何監(jiān)控 nginx”的疑惑有所幫助!接下來(lái),請(qǐng)跟著丸趣 TV 小編一起來(lái)學(xué)習(xí)吧!

安裝準(zhǔn)備

nginx 服務(wù)器:172.22.3.164

prometheus 主機(jī)已安裝 prometheus 和 grafnana 

基于 prometheus 監(jiān)控 nginx 可選兩個(gè) exporter,一個(gè)是通過(guò) nginx_exporter 主要是獲取 nginx-status 中的內(nèi)建的指標(biāo),nginx 自身提供 status 信息,較為簡(jiǎn)單,promethues 中對(duì)應(yīng)的 metrics 也較少。另外一個(gè)是可以通過(guò) nginx-vts-exporter 監(jiān)控更多的指標(biāo),但 nginx-vts-exporter 依賴在編譯 nginx 的時(shí)候添加 nginx-module-vts 模塊來(lái)實(shí)現(xiàn)。vts 提供了訪問(wèn)虛擬主機(jī)狀態(tài)的信息,包含 server,upstream 以及 cache 的當(dāng)前狀態(tài),顯然指標(biāo)會(huì)更豐富一些。本實(shí)踐主要是介紹基于 prometheus 使用 nginx-vts-exporter 對(duì) nginx 進(jìn)行監(jiān)控。

相關(guān)安裝文件

https://github.com/vozlt/nginx-module-vts/archive/v0.1.18.tar.gz
https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz

nginx 添加 nginx-module-vts 支持

# cd /opt/nginx-1.19.6
# wget https://github.com/vozlt/nginx-module-vts/archive/v0.1.18.tar.gz 
# tar -zxf v0.1.18.tar.gz
##  重新編譯
# ./configure --add-module=nginx-module-vts-0.1.18/
# make
# cp objs/nginx /usr/local/nginx/sbin/nginx

修改 nginx.conf

http {
 vhost_traffic_status_zone;
 vhost_traffic_status_filter_by_host on;
 server {
 listen 10011;
 server_name localhost;
 # vhost_traffic_status off;
 location /nginx_status {
 vhost_traffic_status_display;
 vhost_traffic_status_display_format html;
 }
 }
}

重啟 nginx 后,訪問(wèn) http://172.22.3.164:10011/stub_status

安裝 nginx-vts-exporter

在 nginx 服務(wù)器安裝 nginx-vts-exporter

# cd /opt/
# wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
# tar -zxf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
# cp nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter /usr/local/bin

創(chuàng)建 service

##  創(chuàng)建 service
# vi /usr/lib/systemd/system/nginx-vts-exporter.service
[Unit]
Description=nginx-vts-exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/nginx-vts-exporter \
 -nginx.scrape_timeout 10 \
 -nginx.scrape_uri http://127.0.0.1:10011/nginx_status/format/json
Restart=on-failure
[Install]
WantedBy=multi-user.target

設(shè)置自動(dòng)啟動(dòng)

# systemctl daemon-reload
##  設(shè)置自啟動(dòng)
# systemctl enable nginx-vts-exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx-vts-exporter.service to /usr/lib/systemd/system/nginx-vts-exporter.service.

配置 nginx-vts-exporter 監(jiān)控

修改 prometheus 配置文件 prometheus.yml,在 scrape_configs 下增加如下配置

- job_name:  nginx-hosts 
 file_sd_configs:
 - files: [/opt/prometheus/sd_config/nginx-hosts.yml]
 refresh_interval: 5s

新增 /opt/prometheus/sd_config/docker-hosts.yml 文件,內(nèi)容如下

cat /opt/prometheus/sd_config/nginx-hosts.yml
- targets:
 - 172.22.3.164:9913

重啟 prometheus

# systemctl restart prometheus

瀏覽器地址欄輸入 http://172.22.3.148:9090/targets

可以看到 targets 已經(jīng)增加了對(duì)服務(wù) nginx-hosts 的監(jiān)控

在 grafana 中配置面板顯示對(duì)主機(jī) nginx-hosts 監(jiān)控內(nèi)容

點(diǎn)“+”按鈕,彈出導(dǎo)入面板窗口

如圖輸入 2949,點(diǎn) Load,grafana 會(huì)直接從官方網(wǎng)站導(dǎo)入編號(hào)為 2949 的面板如下

選擇數(shù)據(jù)源 Prometheus,繼續(xù)“Import”,顯示 nginx 監(jiān)控界面顯示如下

到此,關(guān)于“基于 prometheus 如何監(jiān)控 nginx”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-08-17發(fā)表,共計(jì)2899字。
轉(zhuǎn)載說(shuō)明:除特殊說(shuō)明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒(méi)有評(píng)論)
主站蜘蛛池模板: 上虞市| 苏尼特左旗| 科技| 延长县| 长宁区| 汕头市| 瑞金市| 新泰市| 锡林浩特市| 宁晋县| 保德县| 泽库县| 齐河县| 恭城| 宜都市| 民丰县| 会昌县| 大英县| 法库县| 吴川市| 壤塘县| 积石山| 黑龙江省| 惠东县| 长沙县| 石渠县| 咸宁市| 桦南县| 太仓市| 康平县| 本溪| 华池县| 乡城县| 樟树市| 南丰县| 富锦市| 文安县| 石屏县| 高唐县| 贺兰县| 上饶县|