我有一个简单的Maven Spring-Boot应用程序(Java),并使用Prometheus从其中收集度量信息。我在pom文件中有所有必要的Prometheus依赖项,并且我在@SpringBootApplication类中包含了@EnablePrometheusEndpoint注释,但是当我运行应用程序并尝试访问localhost:8080/Prometheus(我认为这是Prometheus发送检测度量的默认endpoint?)上的度量时,我得到一个401错误。我是否正确地对应用程序进行了测试,以便Prometheus可以使用@EnablePrometheusEndpoint注释收集度量?Prometheus在哪里显示我的仪器化度量(是否在localhost:8080/Prometheus中)?我也试着在localhost:8080/metrics中查找这些度量,但没有成功。非常感谢任何帮助。
@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文件:
<?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文件,设置(我想)在最后几行刮除localhost:8080上的spring-boot应用程序:
# 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']
这是我看到的,当我看我的prometheus仪表板,运行在localhost:9090上
Prometheus仪表板状态401消息
Prometheus配置为在http://localhost:8080/metrics
(默认值)上查找度量,而@enableprometheusendpoint
在http://localhost:8080/Prometheus
上公开度量。
因此,您应该在prometheus.yml
中将metrics_path
设置为prometheus
。
401会发生,因为默认情况下Spring Boot执行器的metrics
endpoint是受保护的。
我想启用cassandra cqlsession度量。当尝试注册cqlsession度量时,它提供可选的。springboot应用程序中的empty()。这里我使用的是cassandra datastax java驱动程序4.6。 这是我的代码: 正在引发IllegalArgumentException错误。 当参考卡桑德拉税务局的官方文件时(https://docs.datastax.com/e
大家好,我正在为Spring Boot应用程序设计Kubernetes sidecar/适配器模式,以导出Prometheus度量,我知道我们可以使用maven dependency
我在Kubernetes服务的默认命名空间上安装了一个python应用程序。它使用starlette\u exporter,并向Prometheus公开endpoint。当我访问endpoint时,我看到: 我还在库伯内特斯服务的命名空间上安装了。它没有自定义,我使用此命令进行安装: 要将我的应用程序指标添加到Prometheus堆栈中,我可以在Grafana仪表板上跟踪它们,有哪些必要步骤?据我
我的Spring Boot应用程序只是有一个计数器指标。我只是不知道如何将这些信息发送给普罗米修斯。我正在使用Maven(构建工具)和Spring Boot(Java)。
关于如何构建CPU指标的可视化和洞察力的小问题。 我有一个Spring Boot Webflux应用程序,没什么特别的。我带来了执行器,千分尺和普罗米修斯依赖。 谢谢你。