Skip to content

Commit

Permalink
Streams metrics support. (#237)
Browse files Browse the repository at this point in the history
* Streams metrics support.

There are new key type in Redis 5 - Streams.
So, we get ability to monitor them.

* Test for stream.
  • Loading branch information
Andrey Kuzmin authored and oliver006 committed Mar 2, 2019
1 parent ab77af4 commit 9a56425
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ REDIS_FILE | Path to file containing Redis node(s)
Most items from the INFO command are exported,
see https://redis.io/commands/info for details.\
In addition, for every database there are metrics for total keys, expiring keys and the average TTL for keys in the database.\
You can also export values of keys if they're in numeric format by using the `-check-keys` flag. The exporter will also export the size (or, depending on the data type, the length) of the key. This can be used to export the number of elements in (sorted) sets, hashes, lists, etc.
You can also export values of keys if they're in numeric format by using the `-check-keys` flag. The exporter will also export the size (or, depending on the data type, the length) of the key. This can be used to export the number of elements in (sorted) sets, hashes, lists, streams, etc.

If you require custom metric collection, you can provide a [Redis Lua script](https://redis.io/commands/eval) using the `-script` flag. An example can be found [in the contrib folder](./contrib/sample_collect_script.lua).

Expand Down
4 changes: 4 additions & 0 deletions exporter/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ func getKeyInfo(c redis.Conn, key string) (info keyInfo, err error) {
if size, err := redis.Int64(c.Do("HLEN", key)); err == nil {
info.size = float64(size)
}
case "stream":
if size, err := redis.Int64(c.Do("XLEN", key)); err == nil {
info.size = float64(size)
}
default:
err = fmt.Errorf("Unknown type: %v for key: %v", info.keyType, key)
}
Expand Down
2 changes: 2 additions & 0 deletions exporter/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ func TestGetKeyInfo(t *testing.T) {
"4", "zsetval4",
"5", "zsetval5",
}},
keyFixture{"XADD", "key_info_test_stream", []interface{}{"*", "field1", "str1"}},
}

createKeyFixtures(t, c, fixtures)
Expand All @@ -855,6 +856,7 @@ func TestGetKeyInfo(t *testing.T) {
"key_info_test_list": 3,
"key_info_test_set": 4,
"key_info_test_zset": 5,
"key_info_test_stream": 1,
}

// Test all known types
Expand Down

0 comments on commit 9a56425

Please sign in to comment.