Commit a4c034bf authored by 赵啸非's avatar 赵啸非

添加prometheus指标测算

parent ace0e6cb
package com.mortals.xhx;
import com.mortals.framework.springcloud.boot.BaseWebApplication;
import com.mortals.framework.util.HttpUtil;
import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
......@@ -24,18 +23,28 @@ public class ManagerBaseApplication extends BaseWebApplication {
SpringApplication.run(ManagerBaseApplication.class, args);
}
@Bean
/* @Bean
MeterRegistryCustomizer meterRegistryCustomizer(MeterRegistry meterRegistry) {
return meterRegistry1 -> {
meterRegistry.config()
.commonTags("application", "Tenantapp");
};
}*/
/* @Bean
public ServletRegistrationBean<MetricsServlet> getServletRegistrationBean() {
ServletRegistrationBean<MetricsServlet> bean = new ServletRegistrationBean<MetricsServlet>(new MetricsServlet());
bean.addUrlMappings("/metrics");
return bean;
}
}*/
@PostConstruct
/* @PostConstruct
public void init() {
DefaultExports.initialize();
}
}*/
}
package com.mortals.xhx.metrics;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class Counter {
//注册数据
static final io.prometheus.client.Counter REQUESTS = io.prometheus.client.Counter.build().name("requests_total")
.help("Total requests.").labelNames("label").register();
//初始化数据方法一
{
REQUESTS.labels("trace").inc(0D);
}
//初始化数据方法二
@PostConstruct
public void processRequest() {
REQUESTS.labels("error").inc();
}
}
\ No newline at end of file
......@@ -51,4 +51,19 @@ application:
unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/padsign/*,/terminal/*,/resource/list,/api/asset/*,/api/*,/flow/*,/uploads/*,/project/file/*,/file/*,/assessment/*
uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/padsign/*,/terminal/*,/resource/list,/api/asset/*,/api/*,/flow/*,/uploads/*,/project/file/*,/file/*,/assessment/*
holidayUrl: @profiles.holidayUrl@
management:
security:
enabled: false
#prometheus+grafana+springboot2监控集成配置
metrics:
export:
prometheus:
enabled: true
jmx:
enabled: true
endpoints:
web:
exposure:
include: '*'
base-path: /metrics
......@@ -91,22 +91,18 @@
<version>1.6.12</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.16.0</version>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.16.0</version>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
<build>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment