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

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

时间:2023-01-06 14:34:58浏览次数:41  
标签:java windows 0.5 job gradle prometheus io 9000 simpleclient


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环境的内存状况的教程_prometheus监控

 

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环境的内存状况的教程_普罗米修斯监控_02

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

此处需要在搜索栏写:

jvm_memory_bytes_used{job="prometheus"}

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

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

 

7.大功告成!

 

 

标签:java,windows,0.5,job,gradle,prometheus,io,9000,simpleclient
From: https://blog.51cto.com/u_15932265/5993536

相关文章

  • java懒人操作CURT
    1、java对象复制:BeanUtils.copyProperties(temp,reimbursement);2、流操作List对象转map:Map<String,Fields>fieldsMap=fields.stream().collect(Collectors.toMap(F......
  • AJAX跨域请求的理解,JAVA
    1.浏览器的同源策略  目前所有浏览器都由同源策略      什么是同源策略:   协议、域名、端口都一直的uri称为“同源”       不同源之间存在以下......
  • spock做post请求get请求,在springboot环境下使用gradle构建工具的demo,IDEA的开发工具
    1、创建一个springboot项目,基于gradle的创建1)new一个project2)选择springinitializr3)选择gradleproject,然后next4)选择一个web,然后next,然后finish2.打开build.gradle,设......
  • 在java中使用solrj对solr进行CRUD
    如果想要知道如何安装solr,集成IKAnalyzer中文分词器,批量导入数据库数据,java使用参照以下本博主博文:安装solr集成IKAnalyzer中文分词器solr使用浏览器批量导入数据库中数据s......
  • Linux-Windows-Mac-RabbitMQ安装教程
    本说明分一下三种方式安装,请根据具体环境选择相关版本。linux服务器安装win版服务器安装mac版安装linux服务器rabbitmq安装1、RabbitMQ是基于Erlang的,所以首先必须配置Erlan......
  • gradle普通项目构建外部依赖jar的终极方法gradle瘦身
    示例build.gradle如下加载的包可以随意主要是下面的部分plugins{id'maven-publish'}dependencies{testCompilegroup:'junit',name:'junit',version:'4.12'......
  • Java中在指定范围内生成整型、长整型、双精度随机数流
    场景Java8新特性-Stream对集合进行操作的常用API:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/126070657如果希望在指定范围内生成整型、长整型或双精度......
  • JAVA的FOR 语句
    快捷键 输入100.for等于输入for(inti=0;i<100;i++){}publicclassForDemo{publicstaticvoidmain(String[]......
  • Windows11下安装k8s
    一、Docker下载1、基于DockerDesktop安装即可下载地址 2、开启①、开启Hyper-V(Windows10比较容易,本文基于Windows11)  ②、安装WSL2内核(Windows上运行Linux,......
  • Java 获取本机IP地址
    文章目录​​前言​​​​一、规则​​​​二、获取​​​​1.使用​​​​2.工具类​​前言在Java中如何准确的获取到本机IP地址呢?网上大部分的做法是​​InetAddress.getL......