首页 > 编程语言 >Prometheus+Node_exporter+Grafana监控

Prometheus+Node_exporter+Grafana监控

时间:2023-10-27 15:24:35浏览次数:38  
标签:Node opt exporter xxx prometheus Prometheus root

Prometheus+Node_exporter+Grafana监控

 

1.Prometheus+Grafana环境搭建

  Prometheus

  1、在官⽹下载Prometheus:https://prometheus.io/download/

  2、选择 prometheus-2.33.0-rc.0.linux-amd64.tar.gz 下载

   3、上传 prometheus-2.33.0-rc.0.linu

  4.解压安装包

    [root@prometheus opt]# tar -zxvf prometheus-2.33.0-rc.0.linux-amd64.tar.gz
  5.修改包名

    root@prometheus opt]# mv prometheus-2.33.0-rc.0.linux-amd64 prometheus/

  6.进⼊prometheus⽬录,验证安装版本

    [root@prometheus prometheus]# cd /opt/prometheus
    [root@prometheus prometheus]# ./prometheus --version

  7.prometheus.yml初始配置项说明

    # my global config # prometheus的全局配置
    global:
    # 指定抓取数据的时间间隔
    scrape_interval: 15s # Set the scrape interval to every 15 seconds.
    Default is every 1 minute.
    # 指定prometheus重新评估⼀次规则的时间间隔
    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 # 警报管理器Alertmanager的配置项
    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"
    # 指定prometheus抓取的端点数据 # 抓取指标的数据源叫做:端点
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
    # 从本机的9090端⼝抓取数据并追加到 http://localhost:9090/metrics
    # 指定抓取prometheus机器本身的作业数据
    # 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"]

  8.启动Prometheus

    root@prometheus ~]# cd /opt/prometheus
    nohup ./prometheus --config.file=prometheus.yml &

    查看nohup记录

 

  9.浏览器输⼊采集数据地址,验证启动结果

    http://服务器IP:9090/metrics

  10.浏览器输⼊可视化界⾯地址

    http://服务器IP:9090/graph

 如果浏览器弹出下图警告,多半是服务器时间与浏览器时间不匹配,解决办法:刷新服务器时间后重试

 更新服务器时间最直接的办法:

  [root@prometheus prometheus]# yum -y install ntpdate
  [root@prometheus prometheus]# ntpdate -u ntp.api.bz

 

2.Grafana搭建

  1、在官⽹下载Grafana:https://grafana.com/grafana/download
  2、也可以在Linux虚拟机中输⼊命令下载和安装

  get https://dl.grafana.com/enterprise/release/grafana-enterprise8.3.4.linux-amd64.tar.gz
  [root@prometheus opt]# tar -zxvf grafana-enterprise-8.3.4.linuxamd64.tar.gz
  [root@prometheus opt]# mv grafana-8.3.4/ grafana/

3、启动Grafana

  [root@prometheus grafana]# cd /opt/grafana
  [root@prometheus grafana]# nohup bin/grafana-server start &

4.浏览器输⼊Grafana地址,验证启动结果
  初始账号密码:admin / admin

  http://服务器IP:3000/login

3.安装指标采集器node_exporter

    exporter⽤于采集⽬标主机的各种数据,将各种主机和应⽤服务上的监控指标数据输出给Prometheus

    exporters⽬前总体上分为两种:⼀种是Prometheus官⽅在GitHub上维护的,另⼀种的其他的第三⽅开
    发提供给⼤众使⽤的,不同的exporter可以采集不同的数据信息。
    采集Linux系统主机参数和硬件指标的exporter叫做Node exporter,是⼀款⽤Go编写,可收集包括
    CPU、内存、磁盘等数据信息的主机指标采集库。
    注:需要采集哪台主机的指标数据,就部署在哪台机器上,⽬前在订单项⽬的11个系统上都部署了
  1、本次先把Node exporter搭建在Prometheus主机上,实现监控
    Prometheus主机指标监控
  2、在官⽹下载Node exporter:https://prometheus.io/download/
  3、选择 node_exporter-1.2.2.linux-amd64.tar.gz 下载

   4、上传 node_exporter-1.2.2.linux-amd64.tar.gz 到/opt⽬录

   5.解压安装包

    root@prometheus opt]# tar -zxvf node_exporter-1.2.2.linux-amd64.tar.gz
    [root@prometheus opt]# mv node_exporter-1.2.2.linux-amd64 node_exporter/

   6查验参数列表

    使⽤ ./node_exporter --help 查看参数列表,可知Node exporter的运⾏端⼝默认是9100

    --web.listen-address=":9100"
    Address on which to expose metrics and web
    interface.
    --web.telemetry-path="/metrics"
    Path under which to expose metrics.

  7.启动Node exporter

    [root@prometheus node_exporter]# nohup ./node_exporter &

  8.修改prometheus.yml
    新增Job名称叫做"node_exporter"的作业来抓取Node exporter导出的指标数据
    targets配置的是当前⽬标主机的IP和Node exporter运⾏端⼝,书写配置⽂件时注意格式

    # my global config # prometheus的全局配置
    global:
    # 指定抓取数据的时间间隔
    scrape_interval: 15s # Set the scrape interval to every 15 seconds.
    Default is every 1 minute.
    # 指定prometheus重新评估⼀次规则的时间间隔
    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 # 警报管理器Alertmanager的配置项
    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"
    # 指定prometheus抓取的端点数据 # 抓取指标的数据源叫做:端点
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
    # 从本机的9090端⼝抓取数据并追加到 http://localhost:9090/metrics
    # 指定抓取prometheus机器本身的作业数据
    # 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"]
    # Node exporter
    - job_name: "node_exporter"
    static_configs:
    - targets:
    ["xxx.xxx.xxx.xxx:9100","xxx.xxx.xxx.xxx:9100","xxx.xxx.xxx.xxx:9100"]

 

  9.重启Prometheus
    在浏览器的Targets标签中能看到新加⼊的node_exporter作业

 

 

1.4、部署可视化数据监控⼤盘
1、监控Linux主机数据

  登录Grafana,选择导航栏左侧 Configuration 选项,选择 Data sources 选项

 

 

 输⼊数据源名称,可以使⽤默认的名称:Prometheus,也可以设置Prometheus是默认数据源

 在HTTP URL选项输⼊Prometheus主机的数据源地址

 输⼊后直接点击保存,因为稍后会进⾏可视化⾯板的安装,所以在这⾥不配置图形界⾯

 Grafana官⽹提供各种监控数据的可视化数据⼤盘模板,开箱即⽤
数据⼤盘官⽅下载地址:https://grafana.com/grafana/dashboards/

 这⾥记住12884,回到Grafana界⾯,在左侧导航栏选择 Import 选项

 在弹出的界⾯中选择Prometheus作为数据源,然后选择Import

 弹出可视化⼤盘,这时可以看到主机指标监控数据

 调整数据采集频率,点击右侧的数据刷新频率按钮,选择15s⼤盘刷新⼀次

 

4.业务系统jvm数据接入

2.1再业务系统中加入jvm监控埋点
1、增加pom.xml

<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
<version>0.2.2</version>
</dependency>

2、监控依赖

<!-- prometheus 监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
</dependency>

3、增加application.yml配置

 

 

4Application启动类中加入bean

**
* prometheus监控JVM参数
*
* @param applicationName 服务应⽤名称
*/
@Bean
MeterRegistryCustomizer<MeterRegistry>
configurer(@Value("${spring.application.name}") String applicationName) {
return registry -> registry.config().commonTags("application",
applicationName);
}

5、修改prometheus.yml配置⽂件,增加监控job

# JVM
- job_name: "jvm"
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ["xxx.xxx.xxx.xxx:8005"]

 

6、进⼊Prometheus Grafana界⾯,点击左侧导航栏中的Import

 

 

7、输⼊JVM监控⼤盘ID:12856,选择Prometheus数据源并提交保存

 

5.配置邮件监控告警

1、下载alertmanager-0.23.0.linux-amd64.tar.gz,将安装包上传到被监控
的指定⽬标服务器,(需要哪台机器发送告警就部署到哪台机器上)

 

2、解压安装

[root@prometheus opt]# tar -zxvf alertmanager-0.23.0.linux-amd64.tar.gz
[root@prometheus opt]# mv alertmanager-0.23.0.linux-amd64 alertmanager/

 

3、接收告警邮箱以QQ邮箱为例,确保开通POP3和IMAP邮箱服务

 

4.修改 alertmanager.yml 增加配置邮箱

root@prometheus ~]# cd /opt/alertmanager

alertmanager.yml配置

 

5、安装邮件服务

yum -y install sendmail

6、检查配置⽂件正确性

[root@prometheus ~]# cd /opt/alertmanager
[root@prometheus alertmanager]# ./amtool check-config alertmanager.yml

7、启动alertmanager

[root@prometheus alertmanager]# nohup ./alertmanager &

8、建⽴告警规则
建⽴⽤于测试监控告警的规则:内存使⽤率⼤于 1%
1、进⼊prometheus⽬录

[root@prometheus ~]# cd /opt/prometheus

2、建⽴mem_rule.yml告警规则
在 prometheus ⽬录(/opt/prometheus/prometheus)建⽴告警规则⽂件

 

3、修改prometheus.yml
保存后重启prometheus

 

⽬录下的⽂件内容:

 

9、浏览器输⼊alerts地址,验证启动结果

http://服务器IP:9090/alerts

 10、验证告警
重启prometheus服务后,稍等⽚刻,会发现内存使⽤率⼤于1%

 

 

 

标签:Node,opt,exporter,xxx,prometheus,Prometheus,root
From: https://www.cnblogs.com/wyj1997/p/17792135.html

相关文章

  • [node]package入门---简单记录,日后补充
    参考:package入门:https://cloud.tencent.com/developer/article/1195063npm i 添加包:https://www.cnblogs.com/it-wwp/p/16719235.htmlnpm i 删除包:https://blog.csdn.net/m0_46149348/article/details/1308622181. 安装node.js自行百度,不作说明。 如果本地安装速度太慢,切......
  • tus-node-server 官方基于node 实现的tus server 1.0 发布
    tus-node-server是基于typescript开发的新的nodejsserver,通过拆分为独立的包(file,s3,gcs,server)包含的特性完全基于typescript开发拆分为了独立的包提供了新的events以及hooks升级了依赖包重新设计了存储file存储添加了过去扩展更好的周边集成(express,fastify。。。)参考使用s3v......
  • graalvm 23.1.0 独立nodejs docker 镜像&简单试用
    graaljsdocker镜像很简单就是下载官方包,集成下,然后进行一些简单的配置DockerfileFROMdebian:bullseye-backportsLABELauthor="rongfengliang"LABELemail="[email protected]"WORKDIR/opt/RUN/bin/cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime\&&am......
  • prometheus监控istio
    ......
  • 每日一练:无感刷新页面(附可运行的前后端源码,前端vue,后端node)
    1、前言想象下,你正常在网页上浏览页面。突然弹出一个窗口,告诉你登录失效,跳回了登录页面,让你重新登录。你是不是很恼火。这时候无感刷新的作用就体现出来了。2、方案2.1redis设置过期时间在最新的技术当中,token一般都是在Redis服务器存着,设置过期时间。只要在有效时间内,重新发出请......
  • node开发一个接口详细步骤
    最近在做后台系统改版,由于目前接口还没出来,就自己用nodejs写了个简单的接口。我这里用的是nodejs+mysql的这里不讲nodejs和mysql的安装。这些基础略过。首先创建文件夹。cd进入文件。npminit进行初始化安装下面的包npminstallbody-parserexpressmysqlcors-S这里下......
  • node+mysql+express实现登录/注册/修改密码/删除用户 接口
    实现用户的注册、登录、修改密码、删除用户操作用到的数据库:nodecms;表:user目录结构:db目录下存放数据库操作语句:userSQL.js用户有关的操作语句router目录接口路由文件user.js用户接口路由connect.js数据库连接index.html前端测试页面index.js入口文件package.js......
  • 【nvm】关于自动切换Node版本的解决方案
    本地会开发多个不同的NodeJS项目,每个项目可能需要的Node版本不同,有的老项目还在用10.xx,有的要求12.xx/14.xx/16.xx/18.xx。总之,每个项目都需要不同的Node版本。很多时候我都是在启动项目遇到报错了才会意识到要切换Node版本。于是我开始搜寻关于多项目自动切换Node......
  • centos7安装node-v18版本真是难呢
    背景背景就是上一篇文章提到的,部署gitbook这个文档中心的话,是需要先安装node,然后,如果你的node版本过高的话,一般会报错,此时,网上很多文章就是降node版本解决,但其实用高版本也是有办法的,只是麻烦点,要改改代码;但是,我下载了高版本的node安装时,发现在centos7上还装不了,可谓一波未平一波......
  • Node.js 的ORM(Sequelize) 的使用
    Sequelize是一个Node.js的ORM。什么是ORM呢?对象关系映射(ObjectRelationalMapping)。什么意思?就是在编程语言中,很容易创建对象,如果在面向对象的语言中,它也只有对象,但在关系型数据库中,它只有关系(表)。如果想在程序中操作关系型数据库,就要在对象和表之间做转换,比如,取出对象......