Prometheus监控

Prometheus

1.Prometheus部署

1.1准备一台虚拟机(过程略)

1.2下载Prometheus文件

https://prometheus.io/download/
在这里插入图片描述

1.2部署(参考:https://prometheus.io/docs/prometheus/latest/getting_started/)

  • 上传jar包到服务器
  • 解压文件
tar -zxvf prometheus-2.31.1.linux-amd64.tar.gz
  • 配置文件 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"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  • 启动
./prometheus --config.file=prometheus.yml &
  • 访问Prometheus http://192.168.40.100:9090/
    在这里插入图片描述

2.监控

2.1监控远程主机

1.在被监控的主机上安装插件 node_exporter (官网下载 https://prometheus.io/download/)
在这里插入图片描述

这个插件主要收集系统信息
要收集其它信息需要找对应插件,例如MySQL是mysqld_exporter

  • 解压文件并重名
tar -zxvf node_exporter-1.2.2.linux-amd64.tar.gz
mv node_exporter-1.2.2.linux-amd64 node_exporter

2.启动 node_exporter

# 默认使用的是9100端口
nohup /root/prometheus/exporter/node_exporter/node_exporter &

3.查看被监控端数据

# http://被监控端IP:9100/metrics
http://192.168.40.110:9100/metrics
http://192.168.40.120:9100/metrics
http://192.168.40.130:9100/metrics

4.将需要监控的机器加入Prometheus配置文件

  • 修改Prometheus的配置文件prometheus.yml
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
    
  # 新增内容↓
  - job_name: "hadoop"
    static_configs:
      - targets: ["192.168.40.110:9100", "192.168.40.120:9100", "192.168.40.130:9100"]
  • 重启Prometheus
pkill prometheus

在这里插入图片描述

  • 热更新配置
    每次改配置重启显然太蠢
    为了能够热更新启动时需要加上参数 --web.enable-lifecycle
./prometheus --config.file=prometheus.yml --web.enable-lifecycle &
curl -X POST http://localhost:9090/-/reload

2.2监控MySQL

1.在被监控的主机上安装插件 mysqld_exporter(官网下载 https://prometheus.io/download/)
2.解压并重名

# 解压
tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
# 重命名
mv mysqld_exporter-0.13.0.linux-amd64 mysqld_exporter

3.在mysqld_exporter文件夹中配置数据库

vim my.conf

在这里插入图片描述

[client]
user=root
password=123456

4.启动mysql_exporter

# 进入解压后的文件夹,指定配置文件启动
nohup ./mysqld_exporter --config.my-cnf=my.conf &

5.将需要监控的数据库加入Prometheus配置文件

# 修改Prometheus的配置文件prometheus.yml
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
    
  # 新增内容
  - job_name: "mysql"
    static_configs:
      - targets: ["192.168.0.122:9104"]

6.更新配置

curl -X POST http://localhost:9090/-/reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值