Class RedisMetricRepository
- java.lang.Object
- org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository
- All Implemented Interfaces:
MetricReader
,MetricRepository
,CounterWriter
,GaugeWriter
,MetricWriter
public class RedisMetricRepository extends Object implements MetricRepository
AMetricRepository
implementation for a redis backend. Metric values are stored as zset values plus a regular hash value for the timestamp, both against a key composed of the metric name prefixed with a constant (default "spring.metrics."). If you have multiple metrics repositories all point at the same instance of Redis, it may be useful to change the prefix to be unique (but not if you want them to contribute to the same metrics).
Constructor Summary
Constructors Constructor Description RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
Create a RedisMetricRepository with a default prefix to apply to all metric names.RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String prefix)
Create a RedisMetricRepository with a prefix to apply to all metric names (ideally unique to this repository or to a logical repository contributed to by multiple instances, where they all see the same values).RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String prefix, String key)
Allows user to set the prefix and key to use to store the index of other keys.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
count()
The number of metrics known to this reader.Iterable<Metric<?>>
findAll()
Find all the metrics known to this reader.Metric<?>
findOne(String metricName)
Find an instance of the metric with the given name (usually the latest recorded value).void
increment(Delta<?> delta)
Increment the value of a metric (or decrement if the delta is negative).void
reset(String metricName)
Reset the value of a metric, usually to zero value.void
set(Metric<?> value)
Set the value of a metric.
Constructor Detail
RedisMetricRepository
public RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
Create a RedisMetricRepository with a default prefix to apply to all metric names. If multiple repositories share a redis instance they will feed into the same global metrics.- Parameters:
redisConnectionFactory
- the redis connection factory
RedisMetricRepository
public RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String prefix)
Create a RedisMetricRepository with a prefix to apply to all metric names (ideally unique to this repository or to a logical repository contributed to by multiple instances, where they all see the same values). Recommended constructor for general purpose use.- Parameters:
redisConnectionFactory
- the redis connection factoryprefix
- the prefix to set for all metrics keys
RedisMetricRepository
public RedisMetricRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String prefix, String key)
Allows user to set the prefix and key to use to store the index of other keys. The redis store will hold a zset under the key just so the metric names can be enumerated. Read operations, especiallyfindAll()
andcount()
, will only be accurate if the key is unique to the prefix of this repository.- Parameters:
redisConnectionFactory
- the redis connection factoryprefix
- the prefix to set for all metrics keyskey
- the key to set
Method Detail
findOne
public Metric<?> findOne(String metricName)
Description copied from interface:MetricReader
Find an instance of the metric with the given name (usually the latest recorded value).- Specified by:
findOne
in interfaceMetricReader
- Parameters:
metricName
- the name of the metric to find- Returns:
- a metric value or null if there are none with that name
findAll
public Iterable<Metric<?>> findAll()
Description copied from interface:MetricReader
Find all the metrics known to this reader.- Specified by:
findAll
in interfaceMetricReader
- Returns:
- all instances of metrics known to this reader
count
public long count()
Description copied from interface:MetricReader
The number of metrics known to this reader.- Specified by:
count
in interfaceMetricReader
- Returns:
- the number of metrics
increment
public void increment(Delta<?> delta)
Description copied from interface:CounterWriter
Increment the value of a metric (or decrement if the delta is negative). The name of the delta is the name of the metric to increment.- Specified by:
increment
in interfaceCounterWriter
- Parameters:
delta
- the amount to increment by
set
public void set(Metric<?> value)
Description copied from interface:GaugeWriter
Set the value of a metric.- Specified by:
set
in interfaceGaugeWriter
- Parameters:
value
- the value
reset
public void reset(String metricName)
Description copied from interface:CounterWriter
Reset the value of a metric, usually to zero value. Implementations can discard the old values if desired, but may choose not to. This operation is optional (some implementations may not be able to fulfill the contract, in which case they should simply do nothing).- Specified by:
reset
in interfaceCounterWriter
- Parameters:
metricName
- the name to reset