public class RedisMetricRepository extends Object implements MetricRepository
MetricRepository
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 and Description |
---|
RedisMetricRepository(RedisConnectionFactory redisConnectionFactory)
Create a RedisMetricRepository with a default prefix to apply to all metric names.
|
RedisMetricRepository(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(RedisConnectionFactory redisConnectionFactory,
String prefix,
String key)
Allows user to set the prefix and key to use to store the index of other keys.
|
Modifier and Type | Method and 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.
|
public RedisMetricRepository(RedisConnectionFactory redisConnectionFactory)
redisConnectionFactory
- the redis connection factorypublic RedisMetricRepository(RedisConnectionFactory redisConnectionFactory, String prefix)
redisConnectionFactory
- the redis connection factoryprefix
- the prefix to set for all metrics keyspublic RedisMetricRepository(RedisConnectionFactory redisConnectionFactory, String prefix, String key)
findAll()
and count()
,
will only be accurate if the key is unique to the prefix of this repository.redisConnectionFactory
- the redis connection factoryprefix
- the prefix to set for all metrics keyskey
- the key to setpublic Metric<?> findOne(String metricName)
MetricReader
findOne
in interface MetricReader
metricName
- the name of the metric to findpublic Iterable<Metric<?>> findAll()
MetricReader
findAll
in interface MetricReader
public long count()
MetricReader
count
in interface MetricReader
public void increment(Delta<?> delta)
MetricWriter
increment
in interface MetricWriter
delta
- the amount to increment bypublic void set(Metric<?> value)
MetricWriter
set
in interface MetricWriter
value
- the valuepublic void reset(String metricName)
MetricWriter
reset
in interface MetricWriter
metricName
- the name to resetCopyright © 2015 Pivotal Software, Inc.. All rights reserved.