springboot2+exporter+prometheus+grafana搭建监控体系

项目中需要监控系统指标(JVM,CPU,IO,MySQL等),这时候可以使用Prometheus来做。如果是需要监控日志系统,可以使用ELK stack。监控=日志(ELK)+指标(Prometheus)。

step1 编写springboot2程序

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
<dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

step2 node_exporter安装:

在https://github.com/prometheus/node_exporter/releases找到最新的压缩包,然后wget,解压tar -zxvf到本地。
执行:./mysqld_exporter

step3 mysql_exporter安装

在https://github.com/prometheus/mysqld_exporter找到最新的压缩包,然后wget,解压tar -zxvf到本地。
详细安装参考官方文档。
1 mysql创建新用户:
CREATE USER ‘exporter‘@‘localhost‘ IDENTIFIED BY ‘XXXXXXXX‘ WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO ‘exporter‘@‘localhost‘;
2设置环境变量:
export DATA_SOURCE_NAME=‘user:password@(hostname:3306)/‘
3 启动
./mysqld_exporter

先确保mysql启动和有my.cnf文件,然后执行:./mysqld_exporter

step4 prometheus安装和配置

下载最新版的prometheus安装和配置:wget https://github.com/prometheus/prometheus/releases/download/v2.8.0-rc.0/prometheus-2.8.0-rc.0.darwin-amd64.tar.gz
解压到本地:
先配置prometheus.yml文件,需要定义一系列job和targets以连接到step1-3中的组件。
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‘]
  - job_name: ‘node‘
    static_configs:
      - targets: [‘localhost:9100‘]

  - job_name: ‘spring-boot‘
    metrics_path: /prometheus
    static_configs:
      - targets: [‘localhost:8080‘]

  - job_name: ‘mysql-monitor‘
    static_configs:
      - targets: [‘localhost:9104‘]

编写好之后启动prometheus
./prometheus --config.file=prometheus.yml

访问localhost:9090,查看targets看配置的监控是否正确:

step5 grafana安装

wget https://dl.grafana.com/oss/release/grafana-6.0.1.darwin-amd64.tar.gz
tar -zxvf grafana-6.0.1.darwin-amd64.tar.gz
./bin/grafana-server web

step6 自定义panel:jvm,mysql,cpu相关指数

完整的项目链接:https://github.com/xiaozhiliaoo/monitor-base

原文地址:https://blog.51cto.com/thinklili/2360858

时间: 2024-07-30 13:03:11

springboot2+exporter+prometheus+grafana搭建监控体系的相关文章

基于prometheus+grafana 搭建监控mysql redis mongodb等

先把题目定好,具体待这几天整理我的笔记补充进来. 官方网站 https://prometheus.io/ 参考文档: http://www.cnblogs.com/sfnz/p/6566951.html http://www.jb51.net/article/107386.htm https://www.iamle.com/archives/2130.html

k8s+Prometheus+Grafana的监控部署

一.安装部署k8s集群 可以参考https://www.cnblogs.com/liugp/p/12115945.html 二.Prometheus+Grafana的监控部署 2.1.master/node节点环境部署 在[master]可以进行安装部署安装git,并下载相关yaml文件 https://gitee.com/liugpwwwroot/k8s-prometheus-grafana.git 在[node]节点下载监控所需镜像(非必须) docker pull prom/node-ex

Prometheus+grafana搭建jenkins监控

为了便于监控Jenkins搭建后的执行情况呢,我们搭建一个完整的监控体系,使用的Prometheus监控报警  ,展示用的是grafana. 安装prometheus brew install prometheus 安装grafana brew install grafana 安装后,启动grafana brew services start grafana 启动prometheus,需要有 prometheus.yml,我们创建prometheus文件即可. global: scrape_in

Actuator + Prometheus + Grafana搭建微服务监控平台

[TOC] 前言 关于Actuator: 对Spring Boot监控能力有过了解的小伙伴都应该知道Spring Boot Actuator这个子项目,它为应用提供了强大的监控能力.从Spring Boot 2.x开始,Actuator将底层改为Micrometer,提供了更强.更灵活的监控能力.Micrometer是一个监控门面,可以类比成监控界的 Slf4j .借助Micrometer,应用能够对接各种监控系统,例如本文所要介绍的:Prometheus 关于Prometheus : Prom

istio+prometheus+grafana 流量监控

从零到一配置 OpenAP: 概要        Istio采集指标prometheus+grafana方案,搭建(promethues+prometheus-postgresql-adapter+pg_prometheus) promethues·监控存储平台, 通过Istio+grafana 进行istio流量注入grafana图表展示,实现对API流量的统计. 配置 Prometheus 并且把数据存储至  Postgres (Prometheus + Postgres[Timescale

prometheus+grafana+docker 监控tomcat jvm

说明:基于环境mesos+marathon+docker+prometheus+grafana监控tomcat一.配置环境(1)dockerfile from tomcat COPY tomcat-users.xml /usr/local/tomcat/conf/ COPY server.xml /usr/local/tomcat/conf/ COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/ COPY catalina.sh

Prometheus+Grafana部署监控docker服务

1.环境192.168.244.128 Prometheus 监控服务器192.168.244.129 docker 服务(被监控端)注:都是centos7.5系统 2.下载安装包https://prometheus.io/download/ (需要的安装包都可以下载)wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz 服务端(监控se

【集群监控】JMX exporter+Prometheus+Grafana监控Hadoop集群

下载jmx_exporter的jar包 https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar 创建配置文件namenode.yaml(datanode.yaml)放在任意位置,内容为你想要的metrics 参考配置: --- startDelaySeconds: 0 hostPort: master:1234 #maste

基于Prometheus和Grafana的监控平台 - 环境搭建

相关概念 微服务中的监控分根据作用领域分为三大类,Logging,Tracing,Metrics. Logging - 用于记录离散的事件.例如,应用程序的调试信息或错误信息.它是我们诊断问题的依据.比如我们说的ELK就是基于Logging. Metrics - 用于记录可聚合的数据.例如,队列的当前深度可被定义为一个度量值,在元素入队或出队时被更新:HTTP 请求个数可被定义为一个计数器,新请求到来时进行累.prometheus专注于Metrics领域. Tracing - 用于记录请求范围内