【问题标题】:如何在 prometheus 中安装和抓取 Nginx 和 mssql 的指标
【发布时间】:2021-08-27 16:20:55
【问题描述】:

我正在尝试为项目设置 prometheus 监控工具。虽然我能够配置 prometheus 以使用 node_exporter 抓取服务器指标,并使用 blackbox_exporter 抓取 DNS,但我很难在 prometheus 中为 Nginx 和 MsSQL 设置指标。我将不胜感激任何资源或逐步获取导出器以及普罗米修斯抓取数据的安装过程。该项目托管在数字海洋云上。

【问题讨论】:

  • 感谢@DazWilkin。您能否将这个过程分解为 5 年。我仍然难以遵循大纲流程。
  • 我在使用 docker install 命令时遇到了这个错误 "/var/snap/docker/common/var-lib-docker/overlay2/9e0d9809d2e579ff7e459fcad5dea34db8047b73fc921a65905ca0601da7cdd2/merged/etc/nginx/nginx.conf\\\ " 导致\\\"不是目录\\\"\"":未知:您是否尝试将目录挂载到文件上(反之亦然)?检查指定的主机路径是否存在并且是预期的类型。当我卷曲它时,我得到以下响应 curl \ > --request GET \ > localhost/basic_status curl: (7) 无法连接到本地主机端口 80:连接被拒绝

标签: sql-server nginx prometheus grafana digital-ocean


【解决方案1】:

两者看起来都很简单:

  1. NGINX exporter
  2. 官方Microsoft SQL Server exporter

请更新您的问题并解释:

  • 正是您尝试过的(包括代码和配置)
  • 您收到了哪些错误

示例

这会更好,例如Docker Compose 但是...

nginx.conf:

events {
    use           epoll;
    worker_connections  128;
}

http {
    server {
        location = /basic_status {
                stub_status;
        }
    }
}

运行 NGINX(默认为 :80):

docker run \
--interactive --tty --rm \
--net=host \
--volume=${PWD}/nginx.conf:/etc/nginx/nginx.conf:ro \
nginx

测试一下:

curl \
--request GET \
http://localhost/basic_status

运行导出器:

docker run \
--interactive --tty --rm \
--net=host \
nginx/nginx-prometheus-exporter \
  -nginx.scrape-uri=http://localhost/basic_status 

测试一下:

curl \
--request GET \
http://localhost:9113/metrics

产量:

# HELP nginx_connections_accepted Accepted client connections
# TYPE nginx_connections_accepted counter
nginx_connections_accepted 1
# HELP nginx_connections_active Active client connections
# TYPE nginx_connections_active gauge
nginx_connections_active 1
# HELP nginx_connections_handled Handled client connections
# TYPE nginx_connections_handled counter
nginx_connections_handled 1
# HELP nginx_connections_reading Connections where NGINX is reading the request header
# TYPE nginx_connections_reading gauge
nginx_connections_reading 0
# HELP nginx_connections_waiting Idle client connections
# TYPE nginx_connections_waiting gauge
nginx_connections_waiting 0
# HELP nginx_connections_writing Connections where NGINX is writing the response back to the client
# TYPE nginx_connections_writing gauge
nginx_connections_writing 1
# HELP nginx_http_requests_total Total http requests
# TYPE nginx_http_requests_total counter
nginx_http_requests_total 2
# HELP nginx_up Status of the last metric scrape
# TYPE nginx_up gauge
nginx_up 1
# HELP nginxexporter_build_info Exporter build information
# TYPE nginxexporter_build_info gauge
nginxexporter_build_info{commit="5f88afbd906baae02edfbab4f5715e06d88538a0",date="2021-03-22T20:16:09Z",version="0.9.0"} 1

prometheus.yml:

scrape_configs:
  # Self
  - job_name: "prometheus-server"
    static_configs:
      - targets:
          - "localhost:9090"

  # NGINX
  - job_name: "nginx"
    static_configs:
      - targets:
          - "localhost:9113"

然后:

docker run \
--interactive --tty --rm \
--net=host \
--volume=${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:v2.26.0 \
  --config.file=/etc/prometheus/prometheus.yml

然后:

目标:

图表:

【讨论】:

  • 谢谢@Dazwilkin。我已经浏览了您发送的资源,但无法理解该过程。我在指南中找到了一个“docker”,但我没有在服务器上运行一个。我该怎么做。另外,我对整个安装工作​​不熟悉。
  • 对于 Nginx 来说,它还没有开始完成我在门户网站上找到的过程。至于你发的github,我真的不知道Nginx和MsSQL如何处理
  • $ sudo $ nginx-prometheus-exporter -nginx.scrape-uri=http://:8080/stub_status -bash: nginx: 没有这样的文件或目录 $ sudo $ nginx-prometheus -exporter -nginx.scrape-uri=143.110.254.3:8080/stub_status $: command not found $ sudo nginx-prometheus-exporter -nginx.scrape-uri=143.110.254.3:8080/stub_status 2021/06/10 18:12:16 启动 NGINX Prometheus Exporter Version= 0.7.0 GitCommit=a2910f1 2021/06/10 18:12:16 无法创建 Nginx 客户端:预期 200 响应,得到 404
  • 谢谢达兹威尔金
猜你喜欢
  • 2019-12-30
  • 1970-01-01
  • 1970-01-01
  • 2022-11-04
  • 2019-06-03
  • 2021-04-30
  • 2021-01-13
  • 1970-01-01
  • 2018-10-15
相关资源
最近更新 更多