简体   繁体   English

如何在 prometheus 中安装和抓取 Nginx 和 mssql 的指标

[英]How to install and scrape metric for Nginx and mssql in prometheus

I am trying to setup prometheus monitoring tool for a project.我正在尝试为项目设置普罗米修斯监控工具。 While I am able to configure prometheus to scrape server metrics with node_exporter and DNS with blackbox_exporter, I am having a hard time setting up metrics for Nginx and MsSQL in prometheus.虽然我可以配置 prometheus 以使用 node_exporter 和 DNS 和 blackbox_exporter 来抓取服务器指标,但我很难在 prometheus 中为 Nginx 和 MsSQL 设置指标。 I will appreciate any resources or walk through to get the exporter for both as well as the installation process for prometheus to scrape data.我将不胜感激任何资源或逐步获取导出器以及普罗米修斯抓取数据的安装过程。 The project is hosted on digital ocean cloud.该项目托管在数字海洋云上。

Both appear straightforward:两者看起来都很简单:

  1. The NGINX exporter NGINX 出口商
  2. The official Microsoft SQL Server exporter微软官方SQL 服务器导出器

Please update your question and explain:请更新您的问题并解释:

  • Exactly what you tried (include code and config)正是您尝试过的(包括代码和配置)
  • What errors you received你收到了什么错误

Example例子

This would be better under eg Docker Compose but...这在例如 Docker Compose 下会更好,但是......

nginx.conf : nginx.conf

events {
    use           epoll;
    worker_connections  128;
}

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

Run NGINX (defaults to :80 ):运行 NGINX (默认为:80 ):

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

Test it:测试它:

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

Run Exporter:运行导出器:

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

Test it:测试它:

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

Yields:产量:

# 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 : prometheus.yml

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

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

Then:然后:

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

Then:然后:

Targets:目标:

在此处输入图像描述

Graph:图形:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM