我正在尝试使用普罗米修斯httpserver(io.prometheus.client.exporter.HTTPServer)公开指标,而我正在使用以下给定依赖性。
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.2.0</version>
</dependency>
默认情况下,Prometheus httpserver公开“ / metrics”端点中的所有度量,我想覆盖它并限制它仅公开任何特定端点的度量(例如“ / prometheusMetrics”)。使用下面的代码,我运行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;
}
}
}
答案 0 :(得分:0)
您正在更改客户端配置,但这还不够。您还应该更新Prometheus“服务器端”配置的抓取端点。
默认情况下,分配给抓取指标的作业名称。 job_name:
#从这项工作中抓取目标的频率。 [scrape_interval:|默认=]
抓取此作业时的每个抓取超时。 [scrape_timeout:|默认=]
#从目标获取指标的HTTP资源路径。 [metrics_path:|默认= /指标]