prometheus简易推送demo

发布时间 2023-08-10 18:55:06作者: KeepSmiling_me
  public static void main(String[] args) throws Exception {  
  
        InetAddress ia = InetAddress.getLocalHost();  
        Map<String,String> map = new HashMap<>();  
        map.put("serverip",ia.getHostAddress());  
        map.put("interfacename","http://ip:8194/gw/ent/hot");  
        map.put("instance",ia.getHostName());  
  
        /**  
         * 推送指标到pushgetway,prometheus从pushgetway中pull  
         */  
        PushGateway pg = new PushGateway("ip:9091");  
        Gauge gauge = Gauge.build().name("springboot_push").help("服务接口监听").register();  
        gauge.set(0);  
        pg.push(gauge, "springboot_push",map);  
  }  
<dependency>  
      <groupId>org.springframework.boot<\/groupId>  
      <artifactId>spring-boot-starter-web<\/artifactId>  
  <\/dependency>  
  
  <dependency>  
      <groupId>io.micrometer<\/groupId>  
      <artifactId>micrometer-registry-prometheus<\/artifactId>  
  <\/dependency>  
  
  <dependency>  
      <groupId>org.springframework.boot<\/groupId>  
      <artifactId>spring-boot-starter-actuator<\/artifactId>  
  <\/dependency>