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/

 

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

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

此处需要在搜索栏写:

jvm_memory_bytes_used{job="prometheus"}

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

 

7.大功告成!

 

 

如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值