-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRedisMetricProvider.java
68 lines (61 loc) · 2.52 KB
/
RedisMetricProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.db.redis;
import sirius.kernel.commons.Value;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
import sirius.kernel.health.metrics.MetricProvider;
import sirius.kernel.health.metrics.MetricState;
import sirius.kernel.health.metrics.MetricsCollector;
/**
* Provides metrics for Redis (if configured).
*/
@Register
public class RedisMetricProvider implements MetricProvider {
@Part
private Redis redis;
/**
* Contains the entry name of the info section under which redis reports the amount of consumed ram
*/
public static final String INFO_USED_MEMORY = "used_memory";
/**
* Contains the entry name of the info section under which redis reports the maximal amount of available ram
*/
public static final String INFO_MAXMEMORY = "maxmemory";
@Override
public void gather(MetricsCollector collector) {
if (redis.isConfigured()) {
collector.metric("redis_calls", "redis-calls", "Redis Calls", redis.callDuration.getCount(), "/min");
collector.metric("redis_call_duration",
"redis-call-duration",
"Redis Call Duration",
redis.callDuration.getAndClear(),
"ms");
collector.metric("redis_memory_usage",
"redis-memory-usage",
"Redis Memory Usage",
Value.of(redis.getInfo().get(INFO_USED_MEMORY)).asLong(0) / 1024d / 1024d,
"MB");
collector.metric("redis_max_memory",
"Redis Max Memory",
Value.of(redis.getInfo().get(INFO_MAXMEMORY)).asLong(0) / 1024d / 1024d,
"MB",
MetricState.GRAY);
collector.metric("redis_messages",
"redis-messages",
"Redis PubSub Messages",
redis.messageDuration.getCount(),
"/min");
collector.metric("redis_message_duration",
"redis-message-duration",
"Redis PubSub Message Duration",
redis.messageDuration.getAndClear(),
"ms");
}
}
}