如何使用Grafana监视JDBC调用和统计信息 [英] How to monitor JDBC calls and statistics with Grafana

查看:311
本文介绍了如何使用Grafana监视JDBC调用和统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Grafana/Premetheus监视我的Spring Boot应用程序的JDBC调用(Oracle/MySql/Postgre等)统计信息?

  • 我们有任何插件吗?.
  • 是否可以通过Grafana/Prometheus捕获此统计信息?

具体来说,我正在寻找统计信息,例如

Specifically I am looking for statistics like, i.e.

  • 我与数据库有多少个开放连接?
  • 我的数据库是否已启动?
  • 哪些查询导致最长的响应时间等?

推荐答案

您可以尝试使用千分尺.这是Spring Boot的指标提供程序.我目前正在研究同一件事情,但我还不完全了解人们可以使用千分尺的所有方式.因此,希望以下信息对您有用.

You can try using micrometer. This is the metrics provider for spring boot. I'm currently working on the same thing, and I'm not completely aware of all the way one can use micrometer. So, hopefully the below information will be useful for you.

有多种方法可以将Spring Boot应用程序端点公开给Prometheus,然后可以链接grafana以使用Prometheus.请查看此链接作为示例你该怎么做

There are ways to expose spring boot application endpoints to prometheus, and then you can link up grafana to use prometheus. Checkout this link for an example on how you can do it

默认情况下,千分尺将包括JvmMemoryMetrics,UptimeMetrics等.但是,您可以通过将其添加为bean,在应用程序中使用以下软件包中提供的 binders .

By default, micrometer will include the JvmMemoryMetrics, UptimeMetrics, etc,. But you can use the binders provided in the below package in your application by adding it as a bean.

io.micrometer.core.instrument.binder

例如(用Kotlin编写的代码)

For example (code written in Kotlin),

import io.micrometer.core.instrument.binder.db.PostgreSQLDatabaseMetrics
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.sql.DataSource

/**
 * Class to configure binders for micrometer metrics for this application
 */
@Configuration
open class MetricsConfiguration(private val dataSource: DataSource) {

    @Bean
    open fun jvmMemoryMetrics(): ClassLoaderMetrics {
        return ClassLoaderMetrics()
    }

    @Bean
    open fun dbMetrics(): PostgreSQLDatabaseMetrics {
        return  PostgreSQLDatabaseMetrics(dataSource, "database-name")
    }

}

您还可以编写自定义活页夹&指标(如果需要).有关这些的更多信息,请参考千分尺文档.

You can also write custom binders & metrics if needed. Refer to the micrometer docs for more information on those.

这篇关于如何使用Grafana监视JDBC调用和统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆