Skip to content

Commit

Permalink
cmd/scollector: add metadata to redis collector
Browse files Browse the repository at this point in the history
also add rejected_connections stat
  • Loading branch information
kylebrandt committed Feb 25, 2016
1 parent 217b663 commit 930aaf1
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 50 deletions.
273 changes: 223 additions & 50 deletions cmd/scollector/collectors/redis_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,216 @@ func init() {
collectors = append(collectors, &IntervalCollector{F: c_redis, init: redisInit})
}

var redisFields = map[string]bool{
"aof_enabled": true,
"aof_rewrite_in_progress": true,
"aof_rewrite_scheduled": true,
"aof_last_rewrite_time_sec": true,
"aof_current_rewrite_time_sec": true,
"aof_last_bgrewrite_status": true,
"bgrewriteaof_in_progress": true,
"bgsave_in_progress": true,
"blocked_clients": true,
"changes_since_last_save": true,
"client_biggest_input_buf": true,
"client_longest_output_list": true,
"connected_clients": true,
"connected_slaves": true,
"evicted_keys": true,
"expired_keys": true,
"hash_max_zipmap_entries": true,
"hash_max_zipmap_value": true,
"keyspace_hits": true,
"keyspace_misses": true,
"master_link_status": true,
"master_sync_in_progress": true,
"master_last_io_seconds_ago": true,
"master_sync_left_bytes": true,
"mem_fragmentation_ratio": true,
"pubsub_channels": true,
"pubsub_patterns": true,
"rdb_changes_since_last_save": true,
"rdb_bgsave_in_progress": true,
"rdb_last_save_time": true,
"rdb_last_bgsave_status": true,
"rdb_last_bgsave_time_sec": true,
"rdb_current_bgsave_time_sec": true,
"role": true,
"total_commands_processed": true,
"total_connections_received": true,
"uptime_in_seconds": true,
"used_cpu_sys": true,
"used_cpu_user": true,
"used_memory": true,
"used_memory_rss": true,
var redisMeta = map[string]MetricMeta{ // http://redis.io/commands/info)
// Persistence Section
// AOF
"aof_enabled": {
RateType: metadata.Gauge,
Unit: metadata.Enabled,
Desc: "AOF Enabled indicates that Append Only File logging is activated.",
},
"aof_cuurent_size": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

typo: aof_cuRrent_size

RateType: metadata.Gauge,
Unit: metadata.Bytes,
Desc: "The current file size of the AOF (Append Only File).",
},
"aof_rewrite_in_progress": {
RateType: metadata.Gauge,
Unit: metadata.InProgress,
Desc: "Rewrite in progress indicates that AOF (Append Only File) logging is activated.",
},
"aof_rewrite_scheduled": {
RateType: metadata.Gauge,
Unit: metadata.Scheduled,
Desc: "AOF rewrite scheduled means an Append Only file rewrite operation will be scheduled once the on-going RDB save is complete.",
},
"aof_last_rewrite_time_sec": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The duration of the last AOF (Append Only file) rewrite operation in seconds.",
},
"aof_current_rewrite_time_sec": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The duration of the ongoing AOF (Append Only file) rewrite operation in seconds -- if there is one.",
},
"aof_last_bgrewrite_status": {
RateType: metadata.Gauge,
Unit: metadata.Bool,
Desc: "The status of the last AOF (Append Only File) rewrite opperation.",
},
"changes_since_last_save": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

not present on http://ny-devbosun.ds.stackexchange.com/ while testing, but rdb_changes_since_last_save does work: http://goo.gl/tnW7rB

This comment has been minimized.

Copy link
@kylebrandt

kylebrandt Feb 25, 2016

Author Member

Ah ya, misread docs.

RateType: metadata.Gauge,
Unit: metadata.Change,
Desc: "The number of operations that produced some kind of changes in the dataset since the last time either SAVE or BGSAVE was called.",
},
// RDB
"rdb_bgsave_in_progress": {
RateType: metadata.Gauge,
Unit: metadata.InProgress,
Desc: "BGSAVE in progress indicates if a RDB save is on-going.",
},
"rdb_changes_since_last_save": {
RateType: metadata.Gauge,
Unit: metadata.Change,
Desc: "The number of changes since the last dump.",
},
"rdb_last_bgsave_status": {
RateType: metadata.Gauge,
Unit: metadata.Bool,
Desc: "The Status of the last RDB save operation.",
},
"rdb_last_bgsave_time_sec": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The duration of the last RDB save operation.",
},
"rdb_current_bgsave_time_sec": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The duration of the ongoing RDB save operation -- if there is one.",
},
"rdb_last_save_time": {
RateType: metadata.Gauge,
Unit: metadata.Timestamp,
Desc: "The epoch-based timestamp of last successful RDB save.",
},

// Clients Section
"blocked_clients": {
RateType: metadata.Gauge,
Unit: metadata.Client,
Desc: "The number of clients pending on a blocking call (BLPOP, BRPOP, BRPOPLPUSH).",
},
"connected_clients": {
RateType: metadata.Gauge,
Unit: metadata.Connection,
Desc: "The number of client connections (excluding connections from slaves).",
},
"client_biggest_input_buf": {
RateType: metadata.Gauge,
Unit: metadata.Count, // Need to figure out what this is, bytes?
Desc: "The biggest input buffer among current client connections.",
},
"client_longest_output_list": {
RateType: metadata.Gauge,
Unit: metadata.Count, // Need to figure out what this is, length?
Desc: "The longest output list among current client connections.",
},

// Replication Sections
"connected_slaves": {
RateType: metadata.Gauge,
Unit: metadata.Slave,
Desc: "The number of connected slaves.",
},
"master_link_status": {
RateType: metadata.Gauge,
Unit: metadata.Ok,
Desc: "The up/down status of the link to the master.",
},
"master_last_io_seconds_ago": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The number of seconds since the last interaction with master.",
},
"master_sync_in_progress": {
RateType: metadata.Gauge,
Unit: metadata.InProgress,
Desc: "Master sync in progress indicates that the master is syncing to the slave.",
},
"master_sync_left_bytes": {
RateType: metadata.Gauge,
Unit: metadata.Bytes,
Desc: "The number of bytes left before syncing is complete.",
},
"master_sync_last_io_seconds_ago": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

redis.master_sync_last_io_seconds_ago has no data in prod bosun for the last 6 months.

master_last_io_seconds_ago works so not sure if duplicate or just never used

This comment has been minimized.

Copy link
@kylebrandt

kylebrandt Feb 25, 2016

Author Member

IT is in the docs http://redis.io/commands/INFO

RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The number of seconds since last transfer I/O during a SYNC operation.",
},

// Stats Section
"evicted_keys": {
RateType: metadata.Counter,
Unit: metadata.Key,
Desc: "The number of evicted keys due to maxmemory limit.",
},
"expired_keys": {
RateType: metadata.Counter,
Unit: metadata.Key,
Desc: "The total total number of key expiration events.",
},
"keyspace_hits": {
RateType: metadata.Counter,
Unit: metadata.CacheHit,
Desc: "The number of successful lookup of keys in the main dictionary.",
},
"keyspace_misses": {
RateType: metadata.Counter,
Unit: metadata.CacheMiss,
Desc: "The number of failed lookup of keys in the main dictionary.",
},
"used_cpu_sys": {
RateType: metadata.Counter,
Unit: metadata.Pct,
Desc: "The system CPU used by the main Redis process.",
},
"used_cpu_user": {
RateType: metadata.Counter,
Unit: metadata.Pct,
Desc: "The user space CPU used by the main Redis process.",
},
"uptime_in_seconds": {
RateType: metadata.Gauge,
Unit: metadata.Second,
Desc: "The number of seconds since Redis server start.",
},
"total_connections_received": {
RateType: metadata.Counter,
Unit: metadata.Connection,
Desc: "The total number of connections accepted by the server.",
},
"total_connections_processed": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

redis.total_commands_processed is a counter and has data, but redis.total_connections_processed doesn't exist in prod or dev bosun. Is this a typo?

This comment has been minimized.

Copy link
@kylebrandt

kylebrandt Feb 25, 2016

Author Member

typo

RateType: metadata.Counter,
Unit: metadata.Connection,
Desc: "The total number of connections processed by the server.",
},
"pubsub_channels": {
RateType: metadata.Gauge,
Unit: metadata.Channel,
Desc: "Global number of pub/sub channels with client subscriptions.",
},
"pubsub_patterns": {
RateType: metadata.Gauge,
Unit: "Pattern",
Desc: "Global number of pub/sub channels with client subscriptions.",
},
"rejected_connections": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

can't verify if this is a counter as bosun redis never hits this. Will need to follow up and confirm after rollout.

This comment has been minimized.

Copy link
@kylebrandt

kylebrandt Feb 25, 2016

Author Member

redis desc is rejected_connections: Number of connections rejected because of maxclients limit, so I think it is a counter.

RateType: metadata.Counter,
Unit: metadata.Connection,
Desc: "The number of connections rejected because of maxclients limit.",
},

// Memory Section
"used_memory": {
RateType: metadata.Gauge,
Unit: metadata.Bytes,
Desc: "The total number of bytes allocated by Redis using its allocator (either standard libc, jemalloc, or an alternative allocator such as tcmalloc.",
},
"used_rss": {

This comment has been minimized.

Copy link
@gbrayut

gbrayut Feb 25, 2016

Contributor

redis.used_rss doesn't work on devbosun, but redis.used_memory_rss exists on prod bosun. Typo?

This comment has been minimized.

Copy link
@kylebrandt

kylebrandt Feb 25, 2016

Author Member

typo

RateType: metadata.Gauge,
Unit: metadata.Bytes,
Desc: "The number of bytes that Redis allocated as seen by the operating system (a.k.a resident set size). This is the number reported by tools such as top(1) and ps(1).",
},
"mem_fragmentation_ratio": {
RateType: metadata.Gauge,
Unit: metadata.Ratio,
Desc: "The ratio between used_memory_rss and used_memory.",
},

//Other
"role": {}, // This gets treated independtly to create the is_slave metric
}

// For master_link_status.
Expand Down Expand Up @@ -221,19 +389,23 @@ func c_redis() (opentsdb.MultiDataPoint, error) {
continue
}
sp := strings.Split(line, ":")
if len(sp) < 2 || !(redisFields[sp[0]] || strings.HasPrefix(sp[0], "cmdstat_")) {
if len(sp) < 2 {
continue
}
m, foundMeta := redisMeta[sp[0]]
if !(foundMeta || strings.HasPrefix(sp[0], "cmdstat_")) {
continue
}
if sp[0] == "master_link_status" {
Add(&md, "redis."+sp[0], redisMlsMap[sp[1]], tags, metadata.Unknown, metadata.None, "")
Add(&md, "redis."+sp[0], redisMlsMap[sp[1]], tags, m.RateType, m.Unit, m.Desc)
continue
}
if sp[0] == "role" {
Add(&md, "redis.is_slave", slave(sp[1]), tags, metadata.Gauge, metadata.Bool, "")
Add(&md, "redis.is_slave", slave(sp[1]), tags, metadata.Gauge, metadata.Bool, descRedisIsSlave)
continue
}
if sp[0] == "aof_last_bgrewrite_status" || sp[0] == "rdb_last_bgsave_status" {
Add(&md, "redis."+sp[0], status(sp[1]), tags, metadata.Unknown, metadata.None, "")
Add(&md, "redis."+sp[0], status(sp[1]), tags, m.RateType, m.Unit, m.Desc)
continue
}
if strings.HasPrefix(sp[0], "cmdstat_") {
Expand Down Expand Up @@ -272,7 +444,7 @@ func c_redis() (opentsdb.MultiDataPoint, error) {
Add(&md, "redis.cmdstats_calls", cmdStatsCalls[1], tags, metadata.Counter, metadata.Operation, descRedisCmdCalls)
continue
}
Add(&md, "redis."+sp[0], sp[1], tags, metadata.Unknown, metadata.None, "")
Add(&md, "redis."+sp[0], sp[1], tags, m.RateType, m.Unit, m.Desc)
}
Add(&md, "redis.key_count", keys, tags, metadata.Gauge, metadata.Key, descRedisKeyCount)
}
Expand All @@ -281,7 +453,8 @@ func c_redis() (opentsdb.MultiDataPoint, error) {

const (
descRedisKeyCount = "The total number of keys in the instance."
descRedisCmdMsecPc = "Average CPU consumed per command execution."
descRedisCmdMsec = "Total CPU time consumed by commands."
descRedisCmdCalls = "Number of calls."
descRedisCmdMsecPc = "The average CPU consumed per command execution."
descRedisCmdMsec = "The total CPU time consumed by commands."
descRedisCmdCalls = "The total number of calls."
descRedisIsSlave = "This indicates if the redis instance is a slave or not."
)
9 changes: 9 additions & 0 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ const (
Bytes = "bytes"
BytesPerSecond = "bytes per second"
C = "C" // Celsius
CacheHit = "cache hits"
CacheMiss = "cache misses"
Change = "changes"
Channel = "channels"
Check = "checks"
CHz = "CentiHertz"
Client = "clients"
Connection = "connections"
Consumer = "consumers"
Context = "contexts"
ContextSwitch = "context switches"
Count = ""
Document = "documents"
Enabled = "enabled"
Entropy = "entropy"
Error = "errors"
Event = ""
Expand All @@ -66,6 +71,7 @@ const (
Get = "gets"
GetExists = "get exists"
Interupt = "interupts"
InProgress = "in progress"
Item = "items"
KBytes = "kbytes"
Key = "keys"
Expand All @@ -87,20 +93,23 @@ const (
Priority = "priority"
Query = "queries"
Queue = "queues"
Ratio = "ratio"
Redispatch = "redispatches"
Refresh = "refreshes"
Replica = "replicas"
Retry = "retries"
Response = "responses"
Request = "requests"
RPM = "RPM" // Rotations per minute.
Scheduled = "scheduled"
Score = "score"
Second = "seconds"
Sector = "sectors"
Segment = "segments"
Server = "servers"
Session = "sessions"
Shard = "shards"
Slave = "slaves"
Socket = "sockets"
Suggest = "suggests"
StatusCode = "status code"
Expand Down

0 comments on commit 930aaf1

Please sign in to comment.