0
点赞
收藏
分享

微信扫一扫

windows下gradle下使用windows版普罗米修斯prometheus和metrics简单的制作一个监控java环境的内存状况的教程


1.引入依赖(如果是maven可以自行翻译):

例如:    compile 'io.prometheus:simpleclient_hotspot:0.5.0'

groupid 为 io.prometheus

artifactid 为 simpleclient_hotspot

version 为 0.5.0

//普罗米修斯仪表盘监控依赖
compile 'io.prometheus:simpleclient_hotspot:0.5.0'
compile 'io.prometheus:simpleclient:0.5.0'
compile 'io.prometheus:simpleclient_httpserver:0.5.0'
compile 'io.prometheus:simpleclient_dropwizard:0.5.0'
compile 'io.prometheus:simpleclient_servlet:0.5.0'

2.给配置文件中添加:

此处是端口暴露为9000端口

import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
* 作者 ZYL
* 功能描述 : 普罗米修斯监控平台
* 日期 2019/6/15 0015 0:38
* 参数 null
* 返回值
*/
@Configuration
public class MetricsBean {


@PostConstruct
public void init() throws IOException {
DefaultExports.initialize();
HTTPServer server = new HTTPServer(9000);
}

}

 

此处可以启动Java项目了,我这里使用的是idea启动的

 

3.下载prometheus的windows版本

https://prometheus.io/download/

windows下gradle下使用windows版普罗米修斯prometheus和metrics简单的制作一个监控java环境的内存状况的教程_gradle的普罗米修斯监控

 

4.配置prometheus的prometheus.yml文件:此处注意-job_name:   这个参数是你的监听的应用的名称,下面的 - targets ['localhost:9000'],此处为啥是9000因为我前面的config配置文件里面暴露的是9000

# 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:9000']

5.启动windows版本的prometheus.exe

windows下gradle下使用windows版普罗米修斯prometheus和metrics简单的制作一个监控java环境的内存状况的教程_prometheus监控_02

6.访问地址:本地的是:localhost:9090,

此处需要在搜索栏写:

jvm_memory_bytes_used{job="prometheus"}

其中:job="prometheus"是自定义的,配置的什么这里写什么

windows下gradle下使用windows版普罗米修斯prometheus和metrics简单的制作一个监控java环境的内存状况的教程_metrics的prometheus监控_03

 

7.大功告成!

 

 

举报

相关推荐

0 条评论