Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/scollector: add metadata to redis collector #1622

Merged
merged 1 commit into from Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
268 changes: 218 additions & 50 deletions cmd/scollector/collectors/redis_unix.go
Expand Up @@ -20,48 +20,211 @@ 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_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.",
},
// 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 operations that produced some kind of changes in the dataset since the last time either SAVE or BGSAVE was called.",
},
"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": {
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_commands_processed": {
RateType: metadata.Counter,
Unit: metadata.Command,
Desc: "The total number of commands 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": {
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_memory_rss": {
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 +384,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 +439,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 +448,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."
)
10 changes: 10 additions & 0 deletions metadata/metadata.go
Expand Up @@ -44,15 +44,21 @@ 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"
Command = "commands"
Connection = "connections"
Consumer = "consumers"
Context = "contexts"
ContextSwitch = "context switches"
Count = ""
Document = "documents"
Enabled = "enabled"
Entropy = "entropy"
Error = "errors"
Event = ""
Expand All @@ -66,6 +72,7 @@ const (
Get = "gets"
GetExists = "get exists"
Interupt = "interupts"
InProgress = "in progress"
Item = "items"
KBytes = "kbytes"
Key = "keys"
Expand All @@ -87,20 +94,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