[英]How to override prometheus by default endpoint /metrics
I am trying to expose metrics using prometheus httpserver (io.prometheus.client.exporter.HTTPServer) for which i am using below given dependency. 我正在尝试使用普罗米修斯httpserver(io.prometheus.client.exporter.HTTPServer)公开指标,而我正在使用以下给定依赖性。
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.2.0</version>
</dependency>
Prometheus httpserver by default exposes all the metrics in "/metrics" endpoint and i want to override it and restrict it to expose metrics for any particular endpoint only (like "/prometheusMetrics"). 默认情况下,Prometheus httpserver公开“ / metrics”端点中的所有度量,我想覆盖它并限制它仅公开任何特定端点的度量(例如“ / prometheusMetrics”)。 Using below code i running prometheus httpserver and exposing metrics.
使用下面的代码,我运行prometheus httpserver并公开指标。
@ServiceBean(singleton = true)
public class PrometheusCustomHTTPServer {
private static Logger s_logger = LoggerFactory.getLogger(PrometheusCustomHTTPServer.class);
private HTTPServer httpServer;
private static CollectorRegistry registry = CollectorRegistry.defaultRegistry;
private static boolean initailized = false;
@PostConstruct
public void start() {
if(httpServer == null) {
String hostAddress;
try {
int port = 9090;
httpServer = new HTTPServer(port,true);
s_logger.error("started prometheus at http://"+port);
} catch (IOException e) {
System.out.println("Exception occured while starting of prometheus server" + e);
}
initialize(registry);
}
}
private static synchronized void initialize(CollectorRegistry registryToUse) {
if(!initailized) {
new StandardExports().register(registry);
new MemoryPoolsExports().register(registry);
new GarbageCollectorExports().register(registry);
new ThreadExports().register(registry);
new ClassLoadingExports().register(registry);
System.out.println("StandardExports initialized");
initailized = true;
}
}
} }
You are changing the client side configuration, but it's not enough. 您正在更改客户端配置,但这还不够。 You should also update the scrapping endpoint of Prometheus "server side" configuration.
您还应该更新Prometheus“服务器端”配置的抓取端点。
Take a look into Prometheus Configuration : 看一下Prometheus配置 :
The job name assigned to scraped metrics by default.
默认情况下,作业名称分配给抓取的指标。 job_name:
job_name:
# How frequently to scrape targets from this job.
#从这项工作中抓取目标的频率。 [ scrape_interval: |
[scrape_interval:| default = ]
默认=]
Per-scrape timeout when scraping this job.
抓取此作业时的每抓取超时。 [ scrape_timeout: |
[scrape_timeout:| default = ]
默认=]
# The HTTP resource path on which to fetch metrics from targets.
#从目标获取指标的HTTP资源路径。 [ metrics_path: |
[metrics_path:| default = /metrics ]
默认= / metrics]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.