新手在这里,试图了解有关千分尺的更多信息。我目前正在探索如何实现这一点:
我正在使用启用了执行器和千分尺的 Spring boot 2。考虑以下类:
@Component
class MyService {
@Autowired
AuthorizeTransaction callbackTransaction;
@Autowired
AuthorizeTransaction immediateTransaction;
private MeterRegistry meterRegistry;
private Counter requestCounter;
private Counter responseCounter;
public MyService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
initCounters();
}
private initCounters() {
requestCounter = Counter.builder("iso_request")
.tags("mti", "0100") // how do I change the value of this tag for other request types like 0200, 0120, etc.,
.register(meterRegistry);
responseCounter = Counter.builder("iso_response")
.tags("mti", "0101")
.tags("response_code", "00") // how do I change the value of this tag for other response …Run Code Online (Sandbox Code Playgroud) 我需要在我的应用程序中查询收集的指标,我发现这样做的唯一方法是通过 Prometheus rest api,如下所述:https : //prometheus.io/docs/prometheus/latest/querying/api/是否有任何 Spring 或是否存在用于从 Prometheus 获取指标的 java api,这样我就不必从头开始实现它?
我创建了一个支持 websocket 的 Spring Boot 应用程序,我想在 acuator 提供的 prometheus scrape 端点上公开 WebSocketMessageBrokerStats。
我可以通过自动装配/注入访问 WebSocketMessageBrokerStats 对象。但是,该对象仅将相关指标(连接的套接字数量、线程池大小等)公开为汇总字符串。
这不是很有用,因为我最终希望将这些指标导出到普罗米修斯实例。有没有办法以原始形式(例如,作为 int 或 long)访问 WebSocketMessageBroker 统计信息公开的统计信息。
我们希望从 Prometheus 服务器获取按特定标签过滤的所有指标名称。
第 1 步:使用以下查询获取所有指标名称,查询成功并获得所有指标名称。
curl -g 'http://localhost:9090/api/v1/label/__name__/values
Run Code Online (Sandbox Code Playgroud)
步骤 2 :使用以下查询获取按标签过滤的所有指标名称,但查询仍然返回所有指标名称。
curl -g 'http://localhost:9090/api/v1/label/__name__/values?match[]={job!="prometheus"}'
Run Code Online (Sandbox Code Playgroud)
有人可以帮我通过 http 按标签过滤所有指标名称吗?谢谢
curl -G -XGET http://localhost:9090/api/v1/label/__name__/values --data-urlencode 'match[]={__name__=~".+", job!="prometheus"}'
Run Code Online (Sandbox Code Playgroud)
@anemyte,仍然返回所有结果。您可以检查一下查询吗
rest curl prometheus prometheus-alertmanager prometheus-java
运行 Micronaut 应用程序的本机映像时,检索 Prometheus 指标失败,因为它无法获取 jvm 指标。
当然native-image预编译应用程序并且只包含实际使用的内容,但是在运行本机映像时使用什么样的 JVM?我认为它也是标准热点虚拟机的大大简化版本。
那么在运行本机映像时甚至可以获取 jvm 指标还是应该使用其他方法来检索正在运行的应用程序的 cpu 和内存统计信息?
在这种情况下,我使用了 Micronaut,但我认为从具有 prometheus 指标的任何本机图像应用程序获取指标是很常见的。
重现:
- install Micronaut cli (e.g. via Homebrew on Mac)
- install GraalVM 19.2.0 (e.g. via Sdkman on Mac)
- install GraalVM native-image tool: gu install native-image
- create application: mn create-app --features=management,micrometer-prometheus,graal-native-image --build maven metrics-graalvm-image
- update src/main/resources/application.yml to allow anonymous access to prometheus endpoint:
endpoints:
all:
enabled: true
sensitive: false
- run application: man exec:exec
- check prometheus …Run Code Online (Sandbox Code Playgroud) 我之前可以在 Spring Boot Version 2 中使用 Prometheus,没有任何问题。将 Spring Boot 版本更新到 2.1.1 后。发布我遇到以下错误。
我将 Prometheus 版本从 0.2.0 升级到 0.6.0 但仍然遇到相同的错误。
您认为 prometheus 与 Spring Boot Version 2 不兼容吗?
问候
Error :
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:181)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at com.project.projectmine.Application.main(Application.java:26)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [io.prometheus.client.spring.boot.PrometheusEndpointConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@77556fd]
at …Run Code Online (Sandbox Code Playgroud) spring-boot prometheus spring-boot-maven-plugin prometheus-java
我正在研究一个用例,每当推送指标时就会创建新的时间序列。我正在使用计数器来衡量我的指标。我正在使用sum(increase(metric_name{_namespace_="elvis", Label1=~"d1", Label2=~"d2", Label3=~"d3"}[2m])) by (Label1, Label2, Label3)但是我的计数器被初始化为 1 而不是 0,因为当我使用上面的查询时,我无法看到计数器从 0 到 1 的跳转。我尝试初始化我的计数器,同时将其注册为如下所示,但没有帮助。任何帮助将不胜感激
SimpleCollector counter = metricsMap.get(metricName);
double cntrValue = 0d;
if (counter == null) {
synchronized (metricsMap) {
counter = metricsMap.get(metricName);
if (counter == null) {
counter = Counter.build()
.name(decorateMetricsName(metricName))
.help(decorateMetricsName(metricName) + " counter")
.register();
metricsMap.put(metricName, counter);
cntrValue = ((Counter) counter.labels(getLabelValues(labels))).get();
logger.info( "Manifested Time Series with value");
logger.info( "Registered " + metricName);
} else {
return (Counter)counter;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我不确定这是一个错误,但我试图在过去的一天中实现这个库,但没有任何结果。我认为这可能与依赖项版本冲突,但我尝试了一切。
所以我有一个非常简单的 spring boot 项目,它为/test端点提供服务,我配置
现在我在/actuator/prometheus.
期望的结果是指标将包含以下附加指标:
requests_test_totalrequests_latency_seconds我正在触发/test端点,但这些指标未显示在 prometheus 指标中。
我错过了什么吗?
这些是我的依赖项:
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')
compile "io.prometheus:simpleclient:0.8.1"
compile "io.prometheus:simpleclient_hotspot:0.8.1"
compile "io.prometheus:simpleclient_httpserver:0.8.1"
compile "io.prometheus:simpleclient_pushgateway:0.8.1"
compile group: 'io.prometheus', name: 'simpleclient_spring_boot', version: '0.8.1'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'ch.qos.logback.contrib', name: 'logback-json-classic', version: '0.1.5'
compile group: 'ch.qos.logback.contrib', name: 'logback-jackson', version: '0.1.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'net.logstash.logback', …Run Code Online (Sandbox Code Playgroud) 我们将 Spring Boot 版本从 2.1.6 升级到 2.2.2。在 2.1.6中的Prometheus端点中看到的某些属性在 2.2.2 中不可见。
kafka_consumer_records_consumed_total_records_totalkafka_consumer_records_lag_recordskafka_consumer_fetch_latency_max_secondskafka_consumer_bytes_consumed_total_bytes_total但是,此数据正在 MBean 中注册。
kafka_consumer_records_consumed_total_records_total示例
我错过了一些配置吗?如何将 MBean 中可用的数据导出到执行器端点 (" /prometheus")?
更新:我们在两个版本中使用的 Prometheus 版本是相同的。
1.3.1
Run Code Online (Sandbox Code Playgroud)
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>actuator-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>actuator-demo</name>
<description>Spring Boot Actuator Demo Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<!-- Micrometer Prometheus registry …Run Code Online (Sandbox Code Playgroud) spring-boot-actuator prometheus micrometer spring-micrometer prometheus-java
prometheus ×6
micrometer ×3
spring-boot ×2
counter ×1
curl ×1
java ×1
micronaut ×1
rest ×1
spring ×1