Prometheus监控mysql nginx tomcat 黑盒监控

部署consul_exporter

https://github.com/prometheus/consul_exporter/releases/download/v0.9.0/consul_exporter-0.9.0.linux-amd64.tar.gz

注册

bash 复制代码
oot@ubuntu20:~# cat consul_export.json 
root@ubuntu20:~# cat consul_export.json 
{
  "services": [{
      "id": "consul_exporter",
      "name": "192.168.1.50_cousul_expo",
      "address": "192.168.1.50",
      "port": 9107,
      "tags": ["consul_exporter"],
      "checks": [{
        "http": "http://192.168.1.50:9107/metrics",
        "interval": "5s"
      }]
    }
  ]

consul services register consul_export.json

Prometheus添加配置

bash 复制代码
 - job_name: "consul_exporter"
    metrics_path: '/metrics'
    scheme: "http"
    consul_sd_configs:
        - server: "192.168.1.50:8500"
          tags:
          - "consul_exporter"
          refresh_interval: 1m

重新加载Prometheus

root@consumer:/apps/prometheus# curl -XPOST localhost:9090/-/reload

export 获取数据转换为Prometheus数据

pushgetway

查询持久化

grafanf绘图

altermanager 发送告警系统

选择

应用程序不兼容Prometheus

mysqld export

nginx-export

https://github.com/nginxinc/nginx-prometheus-exporter

添加nginx配置,添加这个查看指标

bash 复制代码
       location /stub_status {
           # Turn on nginx stats
                stub_status on;
                access_log   off;
    # Only allow access from certain IP addresses
                allow all;
    #deny all;
                }

运行采集指标export

root@ubuntu20:/apps# ./nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.1.50/stub_status

root@ubuntu20:/etc/nginx# netstat -antp |grep 9113

tcp6 0 0 :::9113 ::😗 LISTEN 168719/./nginx-prom

bash 复制代码
root@ubuntu20:~# cat nginx_export.json 
{
  "services": [{
      "id": "nginx_exporter",
      "name": "192.168.1.50_nginx",
      "address": "192.168.1.50",
      "port": 9113,
      "tags": ["nginx_exporter"],
      "checks": [{
        "http": "http://192.168.1.50:9113/metrics",
        "interval": "5s"
      }]
    }
  ]
}

consul services register  nginx_export.json 

配置Prometheus添加

bash 复制代码
  - job_name: "nginx_exporter"
    metrics_path: '/metrics'
    scheme: "http"
    consul_sd_configs:
        - server: "192.168.1.50:8500"
          tags:
          - "nginx_exporter"
          refresh_interval: 1m

curl -XPOST localhost:9090/-/reload

监控tomcat

tomcat

mcat自身并不能提供监控指标数据,需要借助第三方exporter实现:https://github.com/nlighten/tomcat_exporter

JVM的export或者tomcat export

构建tomcat镜像,并暴露8082端口

bash 复制代码
cat docker-compose.yml 
version: '3.6'

volumes:
    tomcat_webapps: {}

networks:
  monitoring:
    driver: bridge
    ipam:
      config:
        - subnet: 172.31.130.0/24

services:
  tomcat:
    #image: tomcat:jdk11
    build:
      context: tomcat
      dockerfile: Dockerfile 
    hostname: tomcat.magedu.com
    expose:
      - 8080
    ports:
      - 8082:8080
    volumes:
      - tomcat_webapps:/usr/local/tomcat/webapps
      - ./tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml
    networks:
      - monitoring
    environment:
      TZ: Asia/Shanghai

root@jenkins:~/learning-prometheus/08-prometheus-components-compose/tomcat-and-metrics# docker-compose up

注册到consul

bash 复制代码
root@ubuntu20:~# cat tomcat2.json 
{
  "services": [{
      "id": "tomcat",
      "name": "192.168.1.51_tomcat",
      "address": "192.168.1.51",
      "port": 8082,
      "tags": ["tomcat_exporter"],
      "checks": [{
        "http": "http://192.168.1.51:8082/metrics",
        "interval": "5s"
      }]
    }
  ]
}


consul services register   tomcat2.json 

添加Prometheus配置并重新加载

bash 复制代码
  - job_name: "tomcat_exporter"
    metrics_path: '/metrics'
    scheme: "http"
    consul_sd_configs:
        - server: "192.168.1.50:8500"
          tags:
          - "tomcat_exporter"
          refresh_interval: 1m

curl -XPOST localhost:9090/-/reload

黑盒监控

https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz

通过容器运行

root@jenkins:~/learning-prometheus/08-prometheus-components-compose/blackbox-exporter# docker-compose up -d

Prometheus添加

bash 复制代码
  - job_name: "tomcat_exporter"
    metrics_path: '/metrics'
    scheme: "http"
    consul_sd_configs:
        - server: "192.168.1.50:8500"
          tags:
          - "tomcat_exporter"
          refresh_interval: 1m
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
    - targets:
      - www.magedu.com
      - www.google.com
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: "192.168.1.51:9115"  # Blackbox exporter.
      - target_label: region
        replacement: "remote"

容器部署在9115端口页面显示失败

使用二进制部署参考https://blog.csdn.net/u011417723/article/details/120783567

正常

相关推荐
lee_curry3 天前
kube-prometheus-stack 87.21.0 部署
prometheus
扶疏5254 天前
Prometheus+Prometheus Adapter+metrics-server+Ingress实现k8s水平自动扩缩容(HPA)
容器·kubernetes·prometheus
奔跑中的小象4 天前
UOS V2500 沐曦mx-exporter监控加速卡(非K8S)
grafana·prometheus·uos·vllm·沐曦
Wang's Blog5 天前
Go-Zero 项目开发45: Prometheus + Grafana 安装部署与服务监控实战
golang·grafana·prometheus
Wang's Blog5 天前
Go-Zero 项目开发44:集成 Kibana 日志可视化与 Prometheus 性能监控
golang·prometheus·go-zero
Gauss松鼠会6 天前
Prometheus 实现 openGauss 的指标监控(二)Prometheus 中添加 openGauss指标
网络·数据库·oracle·prometheus·opengauss·经验总结
小尘要自信6 天前
让Prometheus跨网络抓取指标:Node Exporter公网监控实战
网络·prometheus
想你依然心痛7 天前
从监控数据到告警管理:Prometheus与Alertmanager部署实战
ubuntu·prometheus·内网穿透·系统监控·cpolar·告警管理
码农阿豪7 天前
Prometheus怎么监控另一台Linux服务器?Node Exporter配置教程
linux·服务器·prometheus
溜达的大象7 天前
Prometheus怎么监控MySQL?mysqld_exporter部署与告警教程
mysql·adb·prometheus