Skip to content

Micrometer

Browse implementations

Note

Micrometer provides a static global registry. This registry is used as default if no registry is given in action's inputs.

Counter🔗

Use this action to report a count metric.

Required Name Type Description
if counter is null name String Counter name.
if name is null counter Counter Counter instance.
description String Counter description
unit String Count unit
tags List<String> key,value list representing tags. A tag is a Key/value pair representing a dimension of a meter used to classify and drill into measurements.
registry MeterRegistry Creates and manages your application's set of meters
* increment Integer as String Positive number by which the counter will be incremented.
Name Type Description
micrometerCounter Counter The incremented counter

Example🔗

1
2
3
4
5
6
7
8
9
MicrometerCounterAction(
    name = "products_likes",
    description = "products likes counter",
    tags = listOf(
        "product", "1",
        "liked_feature", "color"
    ),
    increment = "1"
)

Gauge🔗

Use this action to report a gauge metric.

Required Name Type Description
* name String Gauge name.
description String Gauge description
if gaugeFunction is null gaugeObject Object Gauge will return the current value of this object .
if gaugeObject is null gaugeFunction String Gauge function.
unit String Count unit
tags List<String> key,value list representing tags. A tag is a Key/value pair representing a dimension of a meter used to classify and drill into measurements.
registry MeterRegistry Creates and manages your application's set of meters
strongReference Boolean Indicates that the gauge should maintain a strong reference on the object upon which its instantaneous value is determined. Default is False

Info

  1. GaugeObject is required and must be a Number, a Collection or a Map if no gaugeFunction supplied.
  2. If gaugeFunction is null and gaugeObject is:
    • a number: the gauge will return it's value.
    • a collection: the gauge will return it's size.
    • a Map: the gauge will return it's size.
  3. If gaugeObject and gaugeFunction are not null: the gauge call gaugeFunction of gaugeObject and return the result value.
  4. If gaugeObject is null, gaugeFunction must be a static function.
  5. GaugeFunction is required if gaugeObject is null.
  6. GaugeFunction shouldn't have parameters.
  7. GaugeFunction should return an int, long, float, double or any Number's child class.
Name Type Description
micrometerGaugeObject Object gaugeObject input

Example🔗

Given("I declare my claims collection") {
    ContextPutAction(
        entries = mapOf(
            "claims" to mapOf(
                "1" to listOf("claim_1", "claim_2"),
                "2" to listOf("claim_3", "claim_4")
            )
        )
    )
}
When("I request my gauge metric") {
    MicrometerGaugeAction(
        name = "claims_gauge",
        description = "claims gauge",
        gaugeObject = "\${#claims}",
    )
}
Given("I set the last claim dateTime") {
    ContextPutAction(
        entries = mapOf(
            "last_claim_at" to "\${T(java.time.LocalDateTime).now()}"
        )
    )
}
When("I request my last claim day metric") {
    MicrometerGaugeAction(
        name = "last_claim_date_time_gauge",
        description = "last claim date time gauge",
        gaugeObject = "\${#last_claim_at}",
        gaugeFunction = "getDayOfMonth",
    )
}

Supposing that we have class with a static methode that return an int.

public class MyClass {
    public static int getValue(){
        int result = 0;
        /*
        do some thing
        result = ...
        */
        return result;
    }
}

Then we can use this function as gaugeFunction:

1
2
3
4
5
6
7
When("I request the gauge metric") {
    MicrometerGaugeAction(
        name = "gauge name",
        description = "gauge description",
        gaugeFunction = "my_package.myClass.getValue",
    )
}

Timer🔗

Use this action to report a timer metric.

Required Name Type Description
if timer is null name String Timer name.
description String Timer description
tags List<String> key,value list representing tags. A tag is a Key/value pair representing a dimension of a meter used to classify and drill into measurements
bufferLength Integer as String Distribution statistic buffer length
expiry Duration Distribution statistic expiry
maxValue Duration Timer max duration
minValue Duration Timer min duration
percentilePrecision Integer as String Percentile precision
publishPercentilesHistogram Boolean Publish percentile histogram or not
percentiles String Comma separated list of doublepercentiles doubles
sla String Comma separated list of doublepercentiles doubles
if name is null timer Timer Timer instance.
registry MeterRegistry Creates and manages your application's set of meters
timeunit TimeUnit as String Time unit
record Duration The timer will be updated by the record duration
Name Type Description
micrometerTimer Timer The timer

Example🔗

1
2
3
4
5
MicrometerTimerAction(
    name = "my_timer",
    description = "my timer description",
    record = "3 s",
)

Timer start🔗

Use this action to start a Timer.Sample.

Required Name Type Description
registry MeterRegistry Creates and manages your application's set of meters
Name Type Description
micrometerTimerSample Timer.Sample The sample

Example🔗

MicrometerTimerStartAction()

Timer stop🔗

Use this action to stop a Timer.Sample and record its duration into timer.

Required Name Type Description
* sample Timer.Sample The previously started sample
* timer MeterRegistry Sample's duration will be recorded into this timer
timeunit TimeUnit as String Time unit. Default is SECONDS
Name Type Description
micrometerTimerSampleDuration Duration The sample recorded duration

Example🔗

1
2
3
4
MicrometerTimerStopTask(
    sample = "\${#micrometerTimerSample}",
    timer =  "\${#micrometerTimer}"
)

Summary🔗

Use this action to report a distribution summary metric.

Required Name Type Description
if distributionSummary is null name String Distrubution summary name.
description String Distrubution summary description
tags List<String> Key,value list representing tags. A tag is a Key/value pair representing a dimension of a meter used to classify and drill into measurements
bufferLength Integer as String Distribution statistic buffer length
expiry Duration Distribution statistic expiry
maxValue Duration Distrubution max duration
minValue Duration Distrubution min duration
percentilePrecision Integer as String Percentile precision
publishPercentilesHistogram Boolean Publish percentile histogram or not
percentiles String Comma separated list of doublepercentiles doubles
sla String Comma separated list of doublepercentiles doubles
scale Double as String Scale value
if name is null distributionSummary DistributionSummary Distribution instance.
registry MeterRegistry Creates and manages your application's set of meters
timeunit TimeUnit as String Time unit
record Double as String The distribution will be updated by the record value
Name Type Description
micrometerSummary DistributionSummary The distribution summary

Example🔗

1
2
3
4
5
MicrometerSummaryAction(
    name = "response_size_summary",
    description = "response size summary",
    unit = "bytes",
)