首页 > 编程语言 >Prometheus监控各类程序

Prometheus监控各类程序

时间:2023-02-24 17:45:29浏览次数:48  
标签:node exporter 9090 prometheus grafana Prometheus 各类 监控 root

一、Prometheus安装

github:https://github.com/prometheus/prometheus

官网: https://prometheus.io

# 1下载prometheus-v2.40.7镜像
https://hub.docker.com/r/prom/prometheus/tags
[root@master prometheus]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
prom/prometheus   v2.40.7   b816c2dd5971   2 months ago   223MB

# 2.配置prometheus配置文件
# 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: ["192.168.10.60:9090"]  # 改为prometheus服务端地址

# 3.启动prometheus
docker run -di -p 9090:9090 -v /db/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:v2.40.7
[root@master prometheus]# docker ps
CONTAINER ID   IMAGE                     COMMAND                   CREATED       STATUS          PORTS                                       NAMES
780f6a30bde9   prom/prometheus:v2.40.7   "/bin/prometheus --c…"   2 hours ago   Up 11 minutes   0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   tender_haibt

# 4.访问prometheus界面
http://192.168.10.60:9090
点击:Status-->Targets

 

 通过http://192.168.10.60:9090/metrics可以看到监控的数据

在web主界面可以查看图形

二、node_exporter监控远程主机

# 下载node_exporter
https://prometheus.io/download/#node_exporter
https://github.com/prometheus/node_exporter/releases

# 安装启动node_exporter
[root@node1 node_exporter]# tar -xzvf node_exporter-1.5.0.linux-amd64.tar.gz
mv node_exporter-1.5.0.linux-amd64 node_exporter
[root@node1 node_exporter]# nohup /db/node_exporter/node_exporter &
[root@node1 node_exporter]# netstat -ntlp | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      10614/node_exporter

# 查看监控数据
http://192.168.10.61:9100/metrics

# 在prometheus 服务器上添加配置
vim /db/prometheus/prometheus.yml
  - job_name: "node1"
    static_configs:
      - targets: ["192.168.10.61:9100"]

# 重启docker
[root@master prometheus]# docker restart tender_haibt
使用热加载测试:curl -X POST http://192.168.10.60:9090/-/reload
# 查看图形化界面

三、监控远程mysql:mysqld_exporter

# 1.下载监控程序
https://prometheus.io/download/#mysqld_exporter

# 1.创建一个监控账号
grant select,replication client,process on *.* to 'monitor'@'localhost' identified by 'monitor@123';
flush privileges;

# 2.创建存放密码文件
mv mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter
# 创建存放mysql账号密码文件
[root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# cat mysqld_export.cnf 
[client]
user=monitor
password=monitor@123

# 3.启动程序
[root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# nohup /db/mysqld_exporter/mysqld_exporter --config.my-cnf=/db/mysqld_exporter/mysqld_export.cnf &

[root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# netstat -ntlp | grep 9104
tcp6       0      0 :::9104                 :::*                    LISTEN      19183/mysqld_export 

# 4.修改prometheus.yml配置,新增
  - job_name: "connect_mysql"
    static_configs:
    - targets: ["192.168.10.62:9104"]

# 5.web界面查看

 

四、Grafana链接prometheus

Grafana官网:https://grafana.com/

下载地址:https://grafana.com/grafana/download

dockerhub:https://hub.docker.com/r/grafana/grafana

4.1 grafana安装

# 直接安装
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.6-1.x86_64.rpm sudo yum install grafana-enterprise-9.3.6-1.x86_64.rpm
systemctl start grafana-server

# 镜像安装
# 镜像下载
[root@master ~]# docker pull grafana/grafana:9.2.10
[root@master ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
grafana/grafana   9.2.10    7633eefbf3e8   4 weeks ago    344MB
prom/prometheus   v2.40.7   b816c2dd5971   2 months ago   223MB

# 启动docker
[root@master ~]# docker run -di --name=grafana -p 3000:3000 grafana/grafana:9.2.10
[root@master ~]# docker ps
CONTAINER ID   IMAGE                     COMMAND                   CREATED         STATUS             PORTS                                       NAMES
ccdef48c2249   grafana/grafana:9.2.10    "/run.sh"                 4 seconds ago   Up 3 seconds       0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   grafana
780f6a30bde9   prom/prometheus:v2.40.7   "/bin/prometheus --c…"   3 hours ago     Up About an hour   0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   tender_haibt

# 页面访问
http://192.168.10.60:3000/
默认账号密码:  admin和admin

4.2 grafana 添加数据源

点击:DATA SOURCE--->选择:Prometheus--->填写对应选项--->save&test

 

创建dashboard:点击HOME,回到首页:Create your first dashboard--->Add a new panel

 

标签:node,exporter,9090,prometheus,grafana,Prometheus,各类,监控,root
From: https://www.cnblogs.com/yangmeichong/p/17151723.html

相关文章

  • 前端监控之性能与异常
    作者:京东零售李菲菲1前言现有的大部分监控方案都是针对服务端的,而针对前端的监控很少,诸如线上页面的白屏时间是多少、静态资源的加载情况如何、接口请求耗时好久、什么......
  • Android 分区和内存监控
    Android分区和内存监控Andorid之所以是分区,是因为各自有对应的功能和用途的考量,可以进行单独读写和格式化。Android设备包含两类分区:一类是启动分区,对启动过程至关重......
  • 老人用水监控报警
    点击查看代码#include"led.h"#include"delay.h"#include"sys.h"#include"pwm.h"#include"key.h"#include"usart.h"#include"string.h"#include"exti.h"#......
  • win/ubuntu/centos 安装后台监控工具btop
    之前linux平台进行后台监控一直是简单的看top,但界面太难看而且需要记的缩写太多而且不直观(对于我来说),后面有尝试替换htop,扩展支持了鼠标操作以及直观监控,但是界面还是难......
  • Prometheus&Alertmanager告警推送
    前言尽管可以通过可视化数据监控系统运行状态,但我们无法时刻关注系统运行,因此需要一些实时运行的工具能够辅助监控系统运行,当系统出现运行问题时,能够通知我们,以此确保系统......
  • Prometheus学习笔记之设置存储时间为30天不生效
    0x00概述Prometheus升级到2.23进行测试发现,设置存储时间为30天未生效,根据官方说明手册,实际运行后发现数据只能存储几个小时。。。。--storage.tsdb.retention.time=30d......
  • 导航定位状态评估专题:“特征”离群点判断与剔除 | 定位状态完整性监控
    ​1、前言:经典状态估计中协方差的计算能准确反映机器人状态的完整性吗?在每一次机器人执行各种目的的自动导航任务时,拥有高精度且可靠状态估计的能力可以说是机器人顺利、安......
  • 火山引擎推出一站式小程序监控方案
    背景小程序作为轻量级的应用发展迅速,国内已有多家小程序厂商相继推出。为了洞察用户真实体验及程序自身运行状况,监控已成为开发套件中必不可少的一环。随着业务愈来愈复杂......
  • 监控并重启 MRP 服务
    脚本执行前提:保证执行脚本的用户设置了正确的ORACLE_SID环境变量。#定义检查数据库状态函数#!/bin/shfunctionchk_db_status(){localvl_db_statusvl_db_statu......
  • 文件监控利器-Jnotify
    监听的文件变化的方式有很多,但是比较完美的还是jNotifyhttps://jnotify.sourceforge.net/对比一下监控方式的优缺点方式缺点java原生watch可能对文件时间获取......