Prometheus 系统监控

news/2024/5/19 0:03:39 标签: prometheus, 云原生, 开源软件

文章目录

      • 1.Linux
        • 1.1.Node exporter
        • 1.2.安装部署
      • 2.Windows
        • 2.1.windows_exporter
        • 2.2.安装部署
      • 3.Docker
        • 3.1.cadvisor
        • 3.2.安装部署
      • 4.Nginx
        • 4.1.nginx-vts-exporter
        • 4.2.安装部署
      • 5.Redis
        • 5.1.redis_exporter
        • 5.2.安装部署
      • 6.RabbitMQ
        • 6.1.rabbitmq_exporter
        • 6.2.安装部署
      • 7.PostgreSQL
        • 7.1.postgres_exporter
        • 7.2.安装部署
      • 8.MySQL
        • 8.1.mysqld_exporter
        • 8.2.安装部署
      • 9.Haproxy
        • 9.1.haproxy_exporter
        • 9.2.安装部署
      • 10.Elasticsearch
        • 10.1.elasticsearch_exporter
        • 10.2.安装部署

  • 开源中间件
# Prometheus

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/prometheus/prome-deploy/

1.Linux

1.1.Node exporter

Node_exporter是可以在* Nix和Linux系统上运行的计算机度量标准的导出器。
Node_exporter 主要用于暴露 metrics 给 Prometheus,其中 metrics 包括:cpu 的负载,内存的使用情况,网络等。

# node_exporter
 
# github
https://github.com/prometheus/node_exporter
 
# dockerhub
prom/node-exporter
https://hub.docker.com/r/prom/node-exporter/
1.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --name node-exporter --network host --restart=always \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
prom/node-exporter
# 访问地址
 
http://47.95.238.119:9100/metrics
curl '172.17.88.22:9100/metrics'
# 配置prometheus
 
  - job_name: centos-1
    static_configs:
      - targets: ['172.17.88.22:9100']
        labels:
          instance: node-1
     
  - job_name: centos-2
    static_configs:
      - targets: ['172.17.88.19:9100']
        labels:
          instance: node-2
 
  - job_name: centos-3
    static_configs:
      - targets: ['172.17.88.18:9100']
        labels:
          instance: node-3
  • 配置Grafana模板
# 搜索官网模板
https://grafana.com/
https://grafana.com/grafana/dashboards

# 选择模板
# 8919
https://grafana.com/grafana/dashboards/8919

# 11074
https://grafana.com/grafana/dashboards/11074

# 参考模板
9276  1860

在这里插入图片描述
在这里插入图片描述

2.Windows

2.1.windows_exporter
# windows_exporter
 
# github
https://github.com/prometheus-community/windows_exporter
2.2.安装部署
  • 安装wmi-exporter

在需要监控的Windows机器上安装wmi_exporterwmi_exporter下载地址:
https://github.com/martinlindhe/wmi_exporter/releases

下载后,双击即可完成安装。
完成安装后,会自动创建一个开机自启的服务

在这里插入图片描述
在这里插入图片描述

验证服务是否启动,默认wmi-exporter端口为9182
浏览器访问 http://192.168.56.1:9182/metrics
(Windows系统IP地址:9182端口),显示数据,则服务开启成功。

# 访问地址
 
http://47.95.238.119:9182/metrics
curl '172.17.88.22:9182/metrics'
# 配置prometheus
 
  - job_name: 'Windows'
    static_configs:
      - targets: ['192.168.0.100:9182']
        labels:
          instance: win
  • 配置Grafana模板
# 搜索官网模板
https://grafana.com/
https://grafana.com/grafana/dashboards

# 选择模板
# 10467
https://grafana.com/grafana/dashboards/10467
 
# 2129
https://grafana.com/grafana/dashboards/2129
 
# 参考模板
6545

3.Docker

3.1.cadvisor

CAdvisor是谷歌开发的用于分析运行中容器的资源占用和性能指标的开源工具。CAdvisor是一个运行时的守护进程,负责收集、聚合、处理和输出运行中容器的信息。

# cadvisor
 
# github
https://github.com/google/cadvisor
 
# dockerhub
google/cadvisor
https://hub.docker.com/r/google/cadvisor
3.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d -p 9601:8080 --name cadvisor --restart=always \
-v /:/rootfs:ro \
-v /var/run:/var/run:rw \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
# 访问地址
 
http://47.95.238.119:9601/metrics
curl '172.17.88.22:9601/metrics'
# 配置prometheus
 
  - job_name: docker-1
    static_configs:
      - targets: ['172.17.88.22:9601']
        labels:
          instance: dk-1
     
  - job_name: docker-2
    static_configs:
      - targets: ['172.17.88.19:9601']
        labels:
          instance: dk-2   
 
  - job_name: docker-3
    static_configs:
      - targets: ['172.17.88.18:9601']
        labels:
          instance: dk3-3
  • 配置Grafana模板
# 搜索官网模板
https://grafana.com/
https://grafana.com/grafana/dashboards


# 选择模板
# 10619
https://grafana.com/grafana/dashboards/10619

# 193
https://grafana.com/grafana/dashboards/193

# 参考模板
395   893
193   11277 
11558
179

在这里插入图片描述
在这里插入图片描述

4.Nginx

4.1.nginx-vts-exporter

nginx-module-vts: Nginx virtual host traffic status module,nginx的监控模块,能够提供json、html、prometheus格式的数据产出。
nginx-vts-exporter: Simple server that scrapes Nginx vts stats and exports them via HTTP for Prometheus consumption。主要用于收集nginx的监控数据,并给Prometheus提供监控接口,默认端口号9913。

# nginx-vts-exporter
 
# github
nginx-vts-exporter
https://github.com/hnlq715/nginx-vts-exporter
nginx-module-vts
https://github.com/vozlt/nginx-module-vts
 
# dockerhub
sophos/nginx-vts-exporter
https://hub.docker.com/r/sophos/nginx-vts-exporter
4.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --net=host --name nginx-vts-exporter --restart=always \
--env NGINX_STATUS="http://172.17.88.18/status/format/json" sophos/nginx-vts-exporter
# 访问地址
 
http://47.95.238.119:9913/metrics
curl '172.17.88.18:9913/metrics'
# 配置prometheus
 
  - job_name: nginx-3
    static_configs:
      - targets: ['172.17.88.18:9913']
        labels:
          instance: nx-3
  • 配置Grafana模板
# 选择模板
# 2949
https://grafana.com/grafana/dashboards/2949

# 参考模板
9785

5.Redis

5.1.redis_exporter
# redis_exporter
 
# github
https://github.com/oliver006/redis_exporter
 
# dockerhub
oliver006/redis_exporter
https://hub.docker.com/r/oliver006/redis_exporter/
5.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --name redis-exporter --network host --restart=always \
oliver006/redis_exporter
# 访问地址
 
http://47.95.238.119:9121/metrics
curl '172.17.88.22:9121/metrics'
  • 配置Grafana模板
# 选择模板
# 763
https://grafana.com/grafana/dashboards/763

# 参考模板
4074    12497

在这里插入图片描述

6.RabbitMQ

6.1.rabbitmq_exporter
# rabbitmq_exporter
 
# github
https://github.com/kbudde/rabbitmq_exporter
 
# dockerhub
kbudde/rabbitmq-exporter
https://hub.docker.com/r/kbudde/rabbitmq-exporter
6.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --net=container:rabbit-node1 --name rabbitmq-exporter --restart=always \
kbudde/rabbitmq-exporter
# 访问地址
 
http://47.95.238.119:9419/metrics
curl '172.17.88.22:9419/metrics'
# 配置prometheus
 
  - job_name: rabbitmq-1
    static_configs:
      - targets: ['172.17.88.22:9419']
        labels:
          instance: mq-1
     
  - job_name: rabbitmq-2
    static_configs:
      - targets: ['172.17.88.19:9419']
        labels:
          instance: mq-2
     
  - job_name: rabbitmq-3
    static_configs:
      - targets: ['172.17.88.18:9419']
        labels:
          instance: mq-3
  • 配置Grafana模板
# 选择模板
# 10120
https://grafana.com/grafana/dashboards/10120
 
# 4279
https://grafana.com/grafana/dashboards/4279 
 
# 参考模板
2121  4371

7.PostgreSQL

7.1.postgres_exporter
# postgres_exporter
 
# github
https://github.com/wrouesnel/postgres_exporter
 
# dockerhub
postgres_exporter
https://hub.docker.com/r/wrouesnel/postgres_exporter/tags
7.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --network host --name postgres_exporter --restart=always \
-e DATA_SOURCE_NAME="postgresql://postgres:123456@172.17.88.22:5432/postgres?sslmode=disable" \
wrouesnel/postgres_exporter
# 访问地址
 
http://47.95.238.119:9187/metrics
curl '172.17.88.22:9187/metrics'
# 配置prometheus
 
  - job_name: postgres-1
    static_configs:
      - targets: ['172.17.88.22:9187']
        labels:
          instance: pg-1
 
  - job_name: postgres-2
    static_configs:
      - targets: ['172.17.88.19:9187']
        labels:
          instance: pg-2
  • 配置Grafana模板
# 选择模板
# 455
https://grafana.com/grafana/dashboards/455
 
# 9628
https://grafana.com/grafana/dashboards/9628 
 
# 参考模板
3742

8.MySQL

8.1.mysqld_exporter
# mysqld_exporter
 
# github
https://github.com/prometheus/mysqld_exporter
 
# dockerhub
mysqld_exporter
https://registry.hub.docker.com/r/prom/mysqld-exporter
8.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --network host  --name mysqld-exporter --restart=always \
-e DATA_SOURCE_NAME="root:root@(172.17.88.22:3306)/" \
prom/mysqld-exporter
# 访问地址
 
http://47.95.238.119:9104/metrics
curl '172.17.88.22:9104/metrics'
# 配置prometheus
 
  - job_name: mysql
    static_configs:
      - targets: ['172.17.88.22:9104']
        labels:
          instance: mysqld
  • 配置Grafana模板
# 选择模板
# 11323
https://grafana.com/grafana/dashboards/11323
 
# 7362
https://grafana.com/grafana/dashboards/7362
  
# 参考模板
9623  6239

9.Haproxy

9.1.haproxy_exporter
# haproxy_exporter
 
# github
https://github.com/prometheus/haproxy_exporter
 
# dockerhub
prom/haproxy-exporter
https://hub.docker.com/r/prom/haproxy-exporter
9.2.安装部署
  • 运行docker
# 运行docker
 
docker run -d --network host --name haproxy-exporter --restart=always \
prom/haproxy-exporter --haproxy.scrape-uri="http://172.17.88.18:8999/haproxy?stats;csv"
# 访问地址
 
http://47.95.238.119:9101/metrics
curl '172.17.88.22:9101/metrics'
# 配置prometheus
 
  - job_name: haproxy
    static_configs:
      - targets: ['172.17.88.18:9101']
        labels:
          instance: ha1
  • 配置Grafana模板
# 选择模板
# 2428
https://grafana.com/grafana/dashboards/2428
 
# 12030
https://grafana.com/grafana/dashboards/12030
 
# 参考模板
367

10.Elasticsearch

10.1.elasticsearch_exporter
# elasticsearch_exporter
 
# github
https://github.com/justwatchcom/elasticsearch_exporter
 
# dockerhub
justwatch/elasticsearch_exporter
https://hub.docker.com/r/justwatch/elasticsearch_exporter
10.2.安装部署
  • 运行docker
# 运行docker
 
# 直接运行
./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.22:9200
 
./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.19:9200
 
./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.18:9200
 
 
# 后台运行
nohup ./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.22:9200 &
 
nohup ./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.19:9200 &
 
nohup ./elasticsearch_exporter \
--es.all --es.indices --es.cluster_settings \
--es.indices_settings --es.shards --es.snapshots \
--es.timeout=10s --web.listen-address=":9114" \
--web.telemetry-path="/metrics" \
--es.uri http://172.17.88.18:9200 &
# 访问地址
 
http://47.95.238.119:9114/metrics
curl '172.17.88.22:9114/metrics'
# 配置prometheus
 
  - job_name: elasticsearch-1
    static_configs:
      - targets: ['172.17.88.22:9114']
        labels:
          instance: es-1     
 
  - job_name: elasticsearch-2
    static_configs:
      - targets: ['172.17.88.19:9114']
        labels:
          instance: es-2  
 
  - job_name: elasticsearch-3
    static_configs:
      - targets: ['172.17.88.18:9114']
        labels:
          instance: es-3
  • 配置Grafana模板
# 选择模板
# 6483
https://grafana.com/grafana/dashboards/6483
 
# 2322
https://grafana.com/grafana/dashboards/2322
 
# 参考模板
9746    266
  • 开源中间件
# Prometheus

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/prometheus/prome-deploy/

http://www.niftyadmin.cn/n/5425009.html

相关文章

STM32外设分类--学习笔记

简介: 本文在于根据自己的理解,将stm32f103外设按照功能分个类别,便于记忆。下面的几张图一定要熟悉,后期编写代码时能够快速找到想要的功能和对应的引脚。 我使用的工具链是:使用CubeMX完成keil5工程搭建和引脚初始化功能,然后用…

爬虫之矛---JavaScript基石篇5<JS混淆问题(2)>

前言: 继续上一篇:https://blog.csdn.net/m0_56758840/article/details/136633897 正文: 在这一篇讲混淆的时候,需要先清除一个概念!! 什么是Unicode~ Unicode编码 定义 Unicode是一种字符编码标准,用于表示世界上几乎所有的字符集。它为每个字符分配了一个唯一…

数学建模-多目标规划算法(美赛建模)

单目标优化的情况下,只有一个目标,任何两解都可以依据单一目标比较其好坏,可以得出没有争议的最优解。 多目标化与传统的单目标优化相对。多目标优化的概念是在某个情景中在需要达到多个目标时,由于容易存在目标间的内在冲突&…

自然语言处理(NLP)—— 语义关系提取

语义关系是指名词或名词短语之间的联系。这些关系可以是表面形式(名词性实体)之间的联系,也可以是知识工程中概念之间的联系。在自然语言处理(NLP)和文本挖掘领域,识别和理解这些语义关系对于信息提取、知识…

【前端Vue】社交信息头条项目完整笔记第1篇:一、项目初始化【附代码文档】

社交媒体-信息头条项目完整开发笔记完整教程(附代码资料)主要内容讲述:一、项目初始化使用 Vue CLI 创建项目,加入 Git 版本管理,调整初始目录结构,导入图标素材。二、登录注册准备,实现基本登录功能,登录状态提示,表单验证。三、个人中心&am…

Python pip通过requirements.txt 文件快速安装依赖

1.在现有环境导出requirements.txt pip freeze > requirements.txtrequirements.txt 内容: avro1.11.0 certifi2021.10.8 charset-normalizer2.0.12 crypto1.4.1 future0.18.2 idna3.3 k3cloud-webapi-sdk3.0.3 Naked0.1.31 numpy1.21.5 pandas1.3.5 pycryptodo…

C#编程技巧--2

1.使用泛型: 泛型允许你编写更加灵活和可重用的代码,同时提高类型安全性。 C# 中的泛型功能允许你编写更加灵活和可重用的代码,并且可以增加类型安全性。通过使用泛型,你可以编写适用于不同类型的代码,而无需为每种类型单独重写代…

软考75-上午题-【面向对象技术3-设计模式】-设计模式的要素

一、题型概括 上午、下午题(试题五、试题六,二选一) 每一个设计模式都有一个对应的类图。 二、23种设计模式 创建型设计模式:5 结构型设计模式:7 行为设计模式:11 考试考1-2种。 三、设计模式的要素 3…