Java Dropwizard默认使用哪些核心度量标准?
我一直在试图找出我的一个项目的MetricRegistry详细信息 这里的一个小混乱是,我看到我的服务用于Java Dropwizard默认使用哪些核心度量标准?,java,maven,guice,dropwizard,codahale-metrics,Java,Maven,Guice,Dropwizard,Codahale Metrics,我一直在试图找出我的一个项目的MetricRegistry详细信息 这里的一个小混乱是,我看到我的服务用于localhost:8181/metrics(adminConnector)的版本是3.1.3,它不是最新版本,并且包含在dropwizard-core(注意:+-io.dropwizard.metrics:metrics-core:jar:3.2在下面的依赖项树中) 使用的相对POM依赖项包括: <dependency> <groupId>io.dropw
localhost:8181/metrics
(adminConnector)的版本是3.1.3,它不是最新版本,并且包含在dropwizard-core
(注意:+-io.dropwizard.metrics:metrics-core:jar:3.2在下面的依赖项树中)
使用的相对POM依赖项包括:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>io.federecio</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>0.7.0</version>
</dependency>
我只是想知道Dropwizard是如何配置MetricRegistry的
更多详细信息(如需要):- 我正在使用guice注入将
MetricRegistry
绑定到扩展为AbstractModule
的模块中
bind(MetricRegistry.class).toInstance(environment.metrics());
在服务类中,将此注入器称为
public static void main(String[] args) throws Exception {
new Service().run(args);
}
@Override
public void run(ServiceConfig config, Environment environment) throws Exception {
Injector injector = Guice.createInjector(new ExtendingModule(config, environment));
.... // not altering metrics here
}
DW只是创建了一个度量注册表,不需要任何魔法或其他东西。请参阅引导类以了解:
public Bootstrap(Application<T> application) {
this.application = application;
this.objectMapper = Jackson.newObjectMapper();
this.bundles = new ArrayList<>();
this.configuredBundles = new ArrayList<>();
this.commands = new ArrayList<>();
this.validatorFactory = Validators.newValidatorFactory();
this.metricRegistry = new MetricRegistry();
this.configurationSourceProvider = new FileConfigurationSourceProvider();
this.classLoader = Thread.currentThread().getContextClassLoader();
this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
this.healthCheckRegistry = new HealthCheckRegistry();
}
差不多就是这样
忘记了,他们还注册了一些标准模块:
/**
* Registers the JVM metrics to the metric registry and start to report
* the registry metrics via JMX.
*/
public void registerMetrics() {
if (metricsAreRegistered) {
return;
}
getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory
.getPlatformMBeanServer()));
getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());
JmxReporter.forRegistry(metricRegistry).build().start();
metricsAreRegistered = true;
}
该版本不绑定到您正在使用的度量库版本,而是绑定到向ObjectMapper注册以进行序列化的MetricsModule。在我的例子中,类看起来是这样的:
public class MetricsModule extends Module {
static final Version VERSION = new Version(3, 0, 0, "", "com.codahale.metrics", "metrics-json");
在serialiser中,第一行执行以下操作:
@Override
public void serialize(MetricRegistry registry,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("version", VERSION.toString());
这就是您的版本的来源
诚然,这不是很直观。我认为这更像是一个内部版本控制,每当特定序列化模块中的代码发生变化时,它就会得到更新——但您必须向DW人员询问这方面的详细信息。我的指标是3.1.2或类似的,它为我打印了3.0.0
--ArturDW只创建一个度量注册表,不需要魔法或任何东西。请参阅引导类以了解:
public Bootstrap(Application<T> application) {
this.application = application;
this.objectMapper = Jackson.newObjectMapper();
this.bundles = new ArrayList<>();
this.configuredBundles = new ArrayList<>();
this.commands = new ArrayList<>();
this.validatorFactory = Validators.newValidatorFactory();
this.metricRegistry = new MetricRegistry();
this.configurationSourceProvider = new FileConfigurationSourceProvider();
this.classLoader = Thread.currentThread().getContextClassLoader();
this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
this.healthCheckRegistry = new HealthCheckRegistry();
}
差不多就是这样
忘记了,他们还注册了一些标准模块:
/**
* Registers the JVM metrics to the metric registry and start to report
* the registry metrics via JMX.
*/
public void registerMetrics() {
if (metricsAreRegistered) {
return;
}
getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory
.getPlatformMBeanServer()));
getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());
JmxReporter.forRegistry(metricRegistry).build().start();
metricsAreRegistered = true;
}
该版本不绑定到您正在使用的度量库版本,而是绑定到向ObjectMapper注册以进行序列化的MetricsModule。在我的例子中,类看起来是这样的:
public class MetricsModule extends Module {
static final Version VERSION = new Version(3, 0, 0, "", "com.codahale.metrics", "metrics-json");
在serialiser中,第一行执行以下操作:
@Override
public void serialize(MetricRegistry registry,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("version", VERSION.toString());
这就是您的版本的来源
诚然,这不是很直观。我认为这更像是一个内部版本控制,每当特定序列化模块中的代码发生变化时,它就会得到更新——但您必须向DW人员询问这方面的详细信息。我的指标是3.1.2或类似的,它为我打印了3.0.0
--Arturjar与api响应中列出的版本冲突的原因是什么?@nullpointer该版本在用于序列化的MetricModule中硬编码。这并不代表您使用的库,而是用于序列化的内部模块的版本。jar与api响应中列出的版本冲突的原因是什么?@nullpointer该版本在用于序列化的MetricsModule中硬编码。这并不代表您使用的库,而是用于序列化的内部模块的版本。