Package org.springframework.batch.core.metrics

# Class BatchMetrics

java.lang.Object
org.springframework.batch.core.metrics.BatchMetrics

public final class BatchMetrics extends Object
Central class for batch metrics. It provides:

- the main entry point to interact with Micrometer's `Metrics.globalRegistry` with common metrics such as `Timer` and `LongTaskTimer`.
- Some utility methods like calculating durations and formatting them in a human readable format.

Only intended for internal use.

Since:
  4.2
Author:
  Mahmoud Ben Hassine

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `STATUS_FAILURE`
  `static final String`
  `STATUS_SUCCESS`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Duration`
  `calculateDuration(Date startTime, Date endTime)`
  Calculate the duration between two dates.
  `static io.micrometer.core.instrument.LongTaskTimer`
  `createLongTaskTimer(String name, String description, io.micrometer.core.instrument.Tag... tags)`
  Create a new `LongTaskTimer`.
  `static io.micrometer.core.instrument.Timer`
  `createTimer(String name, String description, io.micrometer.core.instrument.Tag... tags)`
  Create a `Timer`.
  `static io.micrometer.core.instrument.Timer.Sample`
  `createTimerSample()`
  Create a new `Timer.Sample`.
  `static String`
  `formatDuration(Duration duration)`
  Format a duration in a human readable format like: 2h32m15s10ms.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### STATUS_SUCCESS

    public static final String STATUS_SUCCESS
    See Also:
      - Constant Field Values

  - ### STATUS_FAILURE

    public static final String STATUS_FAILURE
    See Also:
      - Constant Field Values

- ## Method Details

  - ### createTimer

    public static io.micrometer.core.instrument.Timer createTimer(String name, String description, io.micrometer.core.instrument.Tag... tags)
    Create a `Timer`.
    Parameters:
      `name` - of the timer. Will be prefixed with `METRICS_PREFIX`.
      `description` - of the timer
      `tags` - of the timer
    Returns:
      a new timer instance

  - ### createTimerSample

    public static io.micrometer.core.instrument.Timer.Sample createTimerSample()
    Create a new `Timer.Sample`.
    Returns:
      a new timer sample instance

  - ### createLongTaskTimer

    public static io.micrometer.core.instrument.LongTaskTimer createLongTaskTimer(String name, String description, io.micrometer.core.instrument.Tag... tags)
    Create a new `LongTaskTimer`.
    Parameters:
      `name` - of the long task timer. Will be prefixed with `METRICS_PREFIX`.
      `description` - of the long task timer.
      `tags` - of the timer
    Returns:
      a new long task timer instance

  - ### calculateDuration

    @Nullable public static Duration calculateDuration(@Nullable Date startTime, @Nullable Date endTime)
    Calculate the duration between two dates.
    Parameters:
      `startTime` - the start time
      `endTime` - the end time
    Returns:
      the duration between start time and end time

  - ### formatDuration

    public static String formatDuration(@Nullable Duration duration)
    Format a duration in a human readable format like: 2h32m15s10ms.
    Parameters:
      `duration` - to format
    Returns:
      A human readable duration