prometheus+grafana监控nginx

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
简介: prometheus+grafana监控nginx


image.png

在prometheus需要向ngxin中打入探针,通过探针获取ngxin信息,并通过接口输出。下文将讲述如何监控ngxin。

1.下载

为了各位小伙伴方便,这里提供了一波下载地址,如果模板不是特别满意,也可以去官网自行下载。

nginx:

链接:https://pan.baidu.com/s/1OBI1NmiMKhtLG4lYxKJyWg

提取码:2shu

nginx-module-vts-master:

链接:https://pan.baidu.com/s/1gOdYjNwHk9eEfIKcVdrE4A

提取码:m0z9

nginx-vts-exporter

链接:https://pan.baidu.com/s/1Q5E1E6Z6FSn8fTP43xBIUA

提取码:bez4

nginx-vts-stats_rev2 (grafana显示模板)

链接:https://pan.baidu.com/s/1VUZwgEMtBOyw3sSE-qEIkA

提取码:pl9v

2.安装nginx与nginx-vts-exporter

1.解压nginx-vts-exporter

这里nginx是重新安装 ,解压nginx-vts-exporter 这里放在usr/local。

unzip nginx-module-vts-master.zip

这里注意nginx版本有要求否则会报错,以下是nginx对应的版本。

image.png

2.解压nginx。

tar -zxvf nginx-1.14.2.tar.gz

3.安装

把nginx-vts-exporter放到nginx路径 ,并执行安装操作。

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.启动

cd /usr/local/nginx/sbin
./nginx

image.png

访问http://ip/status出现以下显示则表示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

启动。

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,如果出现以下证明完成。

image.png

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']    

出现以下配置成功。

image.png

5.配置Grafana

输入grafana可视化页面地址:ip:3000。

1.配置数据源 (prometheus地址:ip:9090)

image.png

image.png

上图填写你prometheus地址,端口切记填写9090,点击save后,如果失败会有提示 。

2.可视化界面模板

image.png

选择上文配置好的数据源,prometheus选项就是上文配置的数据源。

image.png

3.验证

出现以下显示则表示成功。

image.png


相关文章
|
2月前
|
Prometheus 监控 Kubernetes
如何用 Prometheus Operator 监控 K8s 集群外服务?
如何用 Prometheus Operator 监控 K8s 集群外服务?
|
2月前
|
Prometheus 监控 Kubernetes
Prometheus Operator 与 kube-prometheus 之二 - 如何监控 1.23+ kubeadm 集群
Prometheus Operator 与 kube-prometheus 之二 - 如何监控 1.23+ kubeadm 集群
|
1天前
|
Prometheus 监控 Cloud Native
Prometheus+Grafana+NodeExporter 打造一款出色的监控系统,帅呆了!
Prometheus+Grafana+NodeExporter 打造一款出色的监控系统,帅呆了!
9 2
|
26天前
|
存储 监控 数据可视化
Nginx+Promtail+Loki+Grafana Nginx日志展示
通过这些步骤,你可以将Nginx的日志收集、存储、查询和可视化整合在一起。这样,你就可以在Grafana中轻松地创建和展示Nginx日志的图表和面板。
31 3
|
1月前
|
数据采集 监控 数据库
请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
【2月更文挑战第25天】请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
25 2
|
2月前
|
存储 Prometheus Cloud Native
Grafana 系列 - 统一展示 -2-Prometheus 数据源
Grafana 系列 - 统一展示 -2-Prometheus 数据源
|
2月前
|
JSON Prometheus Cloud Native
Grafana 系列 - 统一展示 -3-Prometheus 仪表板
Grafana 系列 - 统一展示 -3-Prometheus 仪表板
|
2月前
|
监控 Cloud Native 关系型数据库
使用 Grafana 统一监控展示 - 对接 Zabbix
使用 Grafana 统一监控展示 - 对接 Zabbix
|
2月前
|
Prometheus 监控 Cloud Native
使用 Prometheus 配置 SLO 监控和告警
使用 Prometheus 配置 SLO 监控和告警
|
2月前
|
Prometheus Kubernetes Cloud Native
「译文」使用 Prometheus 和 Grafana 实现 SLO
「译文」使用 Prometheus 和 Grafana 实现 SLO