Metrics with Dropwizard metrics

预计阅读时间:2分钟

"度量标准"功能允许您配置" 度量标准"以获取有关服务器和传入请求的有用信息.

此功能定义在类io.ktor.metrics.DropwizardMetrics在神器io.ktor:ktor-metrics:$ktor_version .
dependencies { implementation "io.ktor:ktor-metrics:$ktor_version" }
dependencies { implementation("io.ktor:ktor-metrics:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-metrics</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>

Installing

"度量标准"功能公开了一个registry属性,可用于构建和启动度量标准报告程序.

JMX Reporter

JMX Reporter允许您将所有度量标准公开给JMX,从而允许您使用带有MBeans插件的jconsolejvisualvm查看那些度量标准.

install(DropwizardMetrics) {
    JmxReporter.forRegistry(registry)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build()
        .start()
}

Ktor Metrics: JMX

SLF4J Reporter

SLF4J Reporter允许您定期将报告发送到SLF4J支持的任何输出. 例如,要每10秒输出一次指标,您可以:

install(DropwizardMetrics) {
    Slf4jReporter.forRegistry(registry)
        .outputTo(log)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build()
        .start(10, TimeUnit.SECONDS)
}

Ktor Metrics: SLF4J

Other reporters

您可以使用任何可用的Metric报告器 .

Exposed reports

此功能公开了许多与内存使用情况和线程行为有关的JVM属性.

Global:

专门针对Ktor,它公开了:

  • ktor.calls.activeCount -未完成的活动请求数
  • ktor.calls.duration有关通话时间的信息
  • ktor.calls.exceptions有关异常数量的信息
  • ktor.calls.status.NNN有关发生特定HTTP状态代码NNN的次数的信息

Per endpoint:

  • "/uri(method:VERB).NNN"有关此动词的此路径的特定HTTP状态代码NNN发生次数的信息
  • "/uri(method:VERB).meter"有关此动词的此路径的调用次数的信息
  • "/uri(method:VERB).timer"有关此端点持续时间的信息

Information per report

Durations

"/uri(method:VERB).timer"ktor.calls.duration是持续时间,它们公开:

  • 50thPercentile
  • 75thPercentile
  • 95thPercentile
  • 98thPercentile
  • 99thPercentile
  • 999thPercentile
  • Count
  • DurationUnit
  • OneMinuteRate
  • FifteenMinuteRate
  • FiveMinuteRate
  • Max
  • Mean
  • MeanRate
  • Min
  • RateUnit
  • StdDev

Counts

其他属性公开为计数:

  • Count
  • FifteenMinuteRate
  • FiveMinuteRate
  • OneMinuteRate
  • MeanRate
  • RateUnit

by  ICOPY.SITE