国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

prometheus 監(jiān)控 nginx

2020-09-30 16:30 作者:軟件測試檸檬班Pro  | 我要投稿

用 prometheus 可以對 nginx 的 server_name 和 upstream 進(jìn)行監(jiān)控

監(jiān)控 Nginx 主要用到以下三個模塊:

nginx-module-vts:Nginx virtual host traffic status module,Nginx 的監(jiān)控模塊,能夠提供 JSON 格式的數(shù)據(jù)產(chǎn)出。

nginx-vts-exporter:Simple server that scrapes Nginx vts stats and exports them via HTTP for Prometheus consumption。主要用于收集 Nginx 的監(jiān)控數(shù)據(jù),并給 Prometheus 提供監(jiān)控接口,默認(rèn)端口號 9913。

Prometheus:監(jiān)控 Nginx-vts-exporter 提供的 Nginx 數(shù)據(jù),并存儲在時序數(shù)據(jù)庫中,可以使用 PromQL 對時序數(shù)據(jù)進(jìn)行查詢和聚合。

安裝 Prometheus

安裝步驟:


安裝 go 語言環(huán)境

解壓:[root@localhost data]# tar -zxvf go1.11.9.linux-amd64.tar.gz -C /usr/local/

[root@localhost data]# VIM /etc/profile

#go

GO_HMOE=/usr/local/go

export PATH=PATH:GO_HMOE/bin

[root@localhost ~]# source /etc/profile

[root@localhost ~]# go version

go version go1.11 linux/amd64


安裝 Prometheus

[root@localhost data]# wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz

[root@localhost data]# tar -zxvf prometheus-2.9.2.linux-amd64.tar.gz -C /usr/local/

[root@localhost data]# mv /usr/local/prometheus-2.9.2.linux-amd64 /usr/local/prometheus

修改配置文件:

[root@localhost data]# VIM /usr/local/prometheus/prometheus.yml

  • job_name: 'prometheus'

    metrics_path defaults to '/metrics'

    scheme defaults to 'http'.

    static_configs:

    • targets: ['192.168.226.140:9090']

啟動 prometheus:

配置 Prometheus 服務(wù):

[root@localhost data]# VIM /etc/systemd/system/prometheus.service

[Unit]

Description=Prometheus Monitoring System

Documentation=Prometheus Monitoring System

[Service]

ExecStart=/usr/local/prometheus/prometheus \

--config.file=/usr/local/prometheus/prometheus.yml \

--web.listen-address=:9090

[Install]

WantedBy=multi-user.target

[root@localhost data]# systemctl daemon-reload

[root@localhost data]# service prometheus start

[root@localhost prometheus]# netstat -anp|grep prometheus

tcp6 0 0 :::9090 :::* LISTEN 9451/prometheus

通過 url 打開 prometheus 的自帶監(jiān)控界面:http://192.168.226.140:9090/targets

nginx-module-vts 模塊的編譯

(nginx 可以和 Prometheus 在同一臺機(jī)器上面,我這邊是不在一臺機(jī)器上面)

[root@localhost data]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.17.9

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

下載 ngin-module-vts 模塊,并添加模塊到 nginx

[root@localhost data]# cd /usr/local/src

[root@localhost data]# Git clone git://github.com/vozlt/nginx-module-vts.git

[root@localhost data]# cd /data/nginx-1.17.9/ # 進(jìn)入到 nginx 安裝包目錄

[root@localhost data]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts

[root@localhost data]# make ## 編譯,不要 make install,不然會覆蓋

看到如下信息,成功了

替換 Nginx 啟動文件

[root@localhost data]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak ## 備份 nginx 啟動文件

[root@localhost data]# pkill -9 nginx # 停止 nginx

[root@localhost data]# cp /data/nginx-1.16.0/objs/nginx /usr/local/nginx/sbin/

cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y

修改 Nginx.conf 配置文件,試驗安裝是否成功

http {

vhost_traffic_status_zone;
vhost_traffic_status on;

vhost_traffic_status_filter_by_host on;
# 設(shè)定查看 Nginx 狀態(tài)的地址

location /nginx_status {

stub_status on; access_log ?off;

vhost_traffic_status_display;

vhost_traffic_status_display_format html;
}
}

配置解析:

1.1 打開 vhost 過濾:

vhost_traffic_status_filter_by_host on;

開啟此功能,在 Nginx 配置有多個 server_name 的情況下,會根據(jù)不同的 server_name 進(jìn)行流量的統(tǒng)計,否則默認(rèn)會把流量全部計算到第一個 server_name 上。

1.2 在統(tǒng)計流量的 server 區(qū)域開啟 vhost_traffic_status,配置

vhost_traffic_status on;

打開瀏覽器訪問

http://192.168.226.148/nginx_status

在 Prometheus 機(jī)器上面,安裝 nginx-vts-exporter

[root@localhost data]# wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz

[root@localhost data]# tar -zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz

[root@localhost data]# cp nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter /usr/local/prometheus/nginx-vts-exporter/

[root@localhost data]# chmod +x /usr/local/prometheus/nginx-vts-exporter


# 配置 nginx_vts_exporter 服務(wù)

[root@localhost data]# VIM /etc/systemd/system/nginx-vts-exporter.service

[Unit]

Description=nginx-vts-exporter

After=network.target

[Service]

Type=simple

User=root

# 配置 nginx-vts-exporter 的文件所在位置

# 配置 nginx 的機(jī)器 ip 地址

ExecStart=/usr/local/prometheus/nginx-vts-exporter -nginx.scrape_uri=http://192.168.226.148/nginx_status/format/json

Restart=on-failure

[Install]

WantedBy=multi-user.target


啟動 nginx_vts_exporter

[root@localhost data]# systemctl daemon-reload

[root@localhost data]# systemctl start nginx-vts-exporter

[root@localhost data]# systemctl status nginx-vts-exporter

看到如下信息,說明服務(wù)起來了

查看端口:

[root@localhost data]# netstat -anp|grep 9913

訪問安裝了 nginx-vts-exporter 的機(jī)器:http://192.168.226.140:9913/metrics

修改 peometheus.yml, 加入下面的監(jiān)控目標(biāo):

  • job_name: 'nginx'

    static_configs:

    • targets: ['192.168.226.140:9913']

重啟 Prometheus

[root@localhost data]#service prometheus restart

在 grafana 里面配置 Prometheus 的連接

點擊 save&Test

導(dǎo)入 nginx_stat 模板

nginx-vts-stats_rev2.json.json

選擇 Prometheus

效果圖

聲明:本文作者為檸檬班Mike老師,轉(zhuǎn)載請注明出處!

prometheus 監(jiān)控 nginx的評論 (共 條)

分享到微博請遵守國家法律
高陵县| 丁青县| 唐海县| 缙云县| 神池县| 霍邱县| 香河县| 六枝特区| 陆川县| 射阳县| 璧山县| 永丰县| 吴江市| 印江| 淮滨县| 凤山市| 淮阳县| 手游| 上蔡县| 尚志市| 桐梓县| 满城县| 合江县| 望都县| 南阳市| 江达县| 松溪县| 微山县| 五华县| 宣威市| 平乡县| 拜泉县| 尤溪县| 望江县| 新密市| 电白县| 合川市| 城口县| 通州区| 保定市| 长春市|