Class DatabaseTableMetrics

java.lang.Object
io.micrometer.core.instrument.binder.db.DatabaseTableMetrics
All Implemented Interfaces:
MeterBinder

@NonNullApi @NonNullFields public class DatabaseTableMetrics extends Object implements MeterBinder
  • Constructor Details

    • DatabaseTableMetrics

      public DatabaseTableMetrics(DataSource dataSource, String dataSourceName, String tableName, Iterable<Tag> tags)
      Record the row count for an individual database table.
      Parameters:
      dataSource - The data source to use to run the row count query.
      dataSourceName - Will be used to tag metrics with "db".
      tableName - The name of the table to report table size for.
      tags - Tags to apply to all recorded metrics.
    • DatabaseTableMetrics

      public DatabaseTableMetrics(DataSource dataSource, String query, String dataSourceName, String tableName, Iterable<Tag> tags)
      Record the result based on a query.
      Parameters:
      dataSource - The data source to use to run the row count query.
      query - The query to be run against the table. The first column of the result will be the metric and it should return a single row.
      dataSourceName - The name prefix of the metrics.
      tableName - The name of the table to report table size for.
      tags - Tags to apply to all recorded metrics.
  • Method Details

    • monitor

      public static void monitor(MeterRegistry registry, String tableName, String dataSourceName, DataSource dataSource, String... tags)
      Record the row count for an individual database table.
      Parameters:
      registry - The registry to bind metrics to.
      tableName - The name of the table to report table size for.
      dataSourceName - Will be used to tag metrics with "db".
      dataSource - The data source to use to run the row count query.
      tags - Tags to apply to all recorded metrics. Must be an even number of arguments representing key/value pairs of tags.
    • monitor

      public static void monitor(MeterRegistry registry, DataSource dataSource, String dataSourceName, String tableName, Iterable<Tag> tags)
      Record the row count for an individual database table.
      Parameters:
      registry - The registry to bind metrics to.
      dataSource - The data source to use to run the row count query.
      dataSourceName - The name prefix of the metrics.
      tableName - The name of the table to report table size for.
      tags - Tags to apply to all recorded metrics.
    • bindTo

      public void bindTo(MeterRegistry registry)
      Specified by:
      bindTo in interface MeterBinder