私は単純なMavenのSpring-Boot Application(Java)を持っており、Prometheusを使ってメトリック情報を収集しています。私はpomファイルに必要なすべてのPrometheus依存関係を持っていますが、@EnablePrometheusEndpointアノテーションを@SpringBootApplicationクラスに含めましたが、アプリケーションを実行してlocalhost:8080/prometheusのメトリクスにアクセスしようとしましたプロメテウスが計測メトリックを送信するデフォルトのエンドポイント)、401エラーが発生します。 @EnablePrometheusEndpoint注釈を使用してPrometheusがメトリクスを収集できるように、アプリケーションを正しく計測しましたか? Prometheusは計測されたメトリックをどこに表示しますか(localhost:8080/prometheusにありますか)?また、localhost:8080/metricsでこれらのメトリックを探してみましたが、運はありません。どんな助けでも大歓迎です。以下はSpring BootアプリケーションからメトリックをPrometheusにどのようにエクスポートしますか?
@SpringBootApplication
@RestController
@EnablePrometheusEndpoint
public class Example {
//Just a logger that keeps track of relevant information:
private static final Logger LOGGER = Logger.getLogger(Example.class.getName());
//counter for counting how many times an endpoint has been hit
static final Counter myCounter = Counter.build()
.name("CounterName") //note: by convention, counters should have "_total" suffix
.help("Total requests recorded by a specific endpoint")
.labelNames("status")
.register();
@RequestMapping("/hello")
String hello() {
myCounter.labels("customLabel1").inc(); //increment the number of requests by one
LOGGER.log(Level.INFO, "Number of times /hello has been hit: " + myCounter.labels("customLabel1").get());
return "Hello world! This is an example response!";
}
@RequestMapping("/homepage")
String homePage() {
myCounter.labels("customLabel2").inc(); //increment the number of requests by one
LOGGER.log(Level.INFO, "Number of times /homepage has been hit: " + myCounter.labels("customLabel2").get());
return "this is the home page!!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
私のpom.xmlファイルです:最後に8080:ローカルホスト上の私の春ブートアプリをこすりする
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Prometheus dependencies -->
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Hotspot JVM metrics -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Exposition HTTPServer -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Pushgateway exposition -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Spring Boot Actuator for exposing metrics -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>
</dependencies>
</project>
そして、以下は私のprometheus.ymlファイルで、セット(と思います)数行:9090
0123:
# 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).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# 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'.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
#The following lines are meant to monitor my spring boot app
- job_name: 'hello_world_spring_boot'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080']
これは私が私のプロメテウスのダッシュボードを見ると、私はローカルホスト上で実行されている、見るものです@EnablePrometheusEndpoint
がhttp://localhost:8080/prometheus
でメトリックを公開するのに対し、の
私のprometheus.ymlファイル( "job_name: 'hello_world_spring_boot'タグの下)に" metrics_path:/ prometheus "を追加しましたが、同じ401エラーが表示されています。 prometheus.ymlファイル? – kramsiv94
また、構成を「metrics_path: '/ prometheus'」(/ prometheusに一重引用符を追加する)に変更すると、401エラーではなく406エラーが発生します。 – kramsiv94