Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Improve riemann-redis client #29

Merged
merged 5 commits into from about 1 year ago

3 participants

Leandro López Gavin Sandie Kyle Kingsbury
Leandro López
inkel commented March 29, 2013

Currently riemann-redis tool only accepts host, port and (optional) password to connect to a Redis server. However it's better if it would additionally would accept an URL in case the user want to connect using via TCP or via socket. Auth is also possible to be specified from there for TCP connections.

Also it currently issues an INFO and sends all the data converted to float by using #to_f. While this conversion is possible for most of the values returned by INFO, some values are actually strings, which will be converted to 0 in that case, most notably aof_last_bgrewrite_status and rdb_last_bgsave_status, which reports ok or error.

Last but not least, Redis 2.6+ allows to query just for a section of the metrics, so it would be nice if each metric could be tagged properly depending on its section:

  • server: General information about the Redis server
  • clients: Client connections section
  • memory: Memory consumption related information
  • persistence: RDB and AOF related information
  • stats: General statistics
  • replication: Master/slave replication information
  • cpu: CPU consumption statistics
  • commandstats: Redis command statistics
  • cluster: Redis Cluster section
  • keyspace: Database related statistics

If anybody wants to join me, feel free to leave a comment, criticism or suggestion.

added some commits March 29, 2013
Leandro López Add redis-url and redis-socket parameters
Add additional Redis connection parameters URL and socket, in case the
user wants to connect to monitor a Redis server by using a Redis URL
that can have the following format:

* redis://server:port
* redis://:password@server:port/db
* unix:///path/to/redis.sock
d2fe78a
Leandro López Send Redis string INFO values as description
Send the values of the different Redis INFO metrics that are strings in
the description field of the report.
f13d770
Leandro López Send persistence last status in state field
Send the values of the persistence last status
metrics (rdb_last_bgsave_status and aof_last_bgrewrite_status) in the
state field of the report.
29b05a0
Leandro López
inkel commented March 29, 2013

This is still a work in progress

Leandro López inkel referenced this pull request in monitorama/hackathon March 29, 2013
Closed

Improve riemann-redis tool #60

Leandro López
inkel commented March 29, 2013

So far this completes the list of things I was planning to add. It'd be nice that metrics were properly tagged. If there's interest in doing that, please let me know.

Gavin Sandie gsandie commented on the diff March 29, 2013
bin/riemann-redis
((32 lines not shown))
23 39
         :host    => opts[:redis_host],
24 40
         :service => "redis #{property}",
25 41
         :metric  => value.to_f,
26 42
         :state   => 'ok',
27 43
         :tags    => ['redis']
28  
-      )
  44
+      }
  45
+
  46
+      if STRING_VALUES.include?(property) || property.match(/^db\d+/)
  47
+        if %w{ rdb_last_bgsave_status aof_last_bgrewrite_status }.include?(property)
  48
+          data[:state] = value
  49
+        else
  50
+          data[:description] = value
4
Gavin Sandie Collaborator
gsandie added a note March 29, 2013

In my testing, the description always gets set to nil. Do want to set it to the property name?

Leandro López
inkel added a note March 29, 2013

Hey, @gsandie, I just did a test run and I'm the description as it's supposed to. Are you here at Monitorama?

Gavin Sandie Collaborator
gsandie added a note March 29, 2013

Yeah I am. In the R workshop but just about to leave it.

Leandro López
inkel added a note March 29, 2013

I'm sitting to the left of the registration table, come and see me if you like :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Gavin Sandie
Collaborator

:+1: This is neat.

Gavin Sandie gsandie commented on the diff March 29, 2013
bin/riemann-redis
@@ -11,21 +11,47 @@ class Riemann::Tools::Redis
11 11
   opt :redis_host, "Redis hostname", :default => 'localhost'
12 12
   opt :redis_port, "Redis port", :default => 6379
13 13
   opt :redis_password, "Redis password", :default => ''
  14
+  opt :redis_url, "Redis URL", :default => ''
3
Gavin Sandie Collaborator
gsandie added a note March 29, 2013

Do you want to set a default value here, maybe redis://localhost:6379 ?

Leandro López
inkel added a note March 29, 2013

I thought about it, but that would break backwards compatibility with existing clients that rely on using --redis-host and redis-port: if you check line 24 it says if opts[:redis_url] != '' and host and port are set in the else block.

Leandro López
inkel added a note March 29, 2013

What I'm trying to say is: if you use a redis URL, it will use that and no other parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Gavin Sandie
Collaborator

Cool, all looks good I think :)

:sparkles:

Gavin Sandie gsandie merged commit 4b69d9d into from March 29, 2013
Gavin Sandie gsandie closed this March 29, 2013
Kyle Kingsbury
Owner
aphyr commented March 29, 2013

Nice work guys! BTW feel free to add yourselves to the thank you page whenever you make changes! Fork https://github.com/aphyr/riemann, git checkout gh-pages, open thanks.html, and make a note in "contributors to the next release". :) Thanks for all your hard work.

Leandro López
inkel commented March 30, 2013

Thank you, Kyle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 1 author.

Mar 29, 2013
Leandro López Add redis-url and redis-socket parameters
Add additional Redis connection parameters URL and socket, in case the
user wants to connect to monitor a Redis server by using a Redis URL
that can have the following format:

* redis://server:port
* redis://:password@server:port/db
* unix:///path/to/redis.sock
d2fe78a
Leandro López Send Redis string INFO values as description
Send the values of the different Redis INFO metrics that are strings in
the description field of the report.
f13d770
Leandro López Send persistence last status in state field
Send the values of the persistence last status
metrics (rdb_last_bgsave_status and aof_last_bgrewrite_status) in the
state field of the report.
29b05a0
Leandro López Sent DB keyspace metrics in the description field 549ba9e
Leandro López Add redis-section parameter to indicate INFO section f0de6b1
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 30 additions and 4 deletions. Show diff stats Hide diff stats

  1. 34  bin/riemann-redis
34  bin/riemann-redis
@@ -11,21 +11,47 @@ class Riemann::Tools::Redis
11 11
   opt :redis_host, "Redis hostname", :default => 'localhost'
12 12
   opt :redis_port, "Redis port", :default => 6379
13 13
   opt :redis_password, "Redis password", :default => ''
  14
+  opt :redis_url, "Redis URL", :default => ''
  15
+  opt :redis_socket, "Redis socket", :default => ''
  16
+  opt :redis_section, "Redis INFO section", :default => 'default'
  17
+
  18
+  STRING_VALUES = %w{ redis_version redis_git_sha1 redis_mode os
  19
+                      multiplexing_api gcc_version run_id used_memory_human
  20
+                      used_memory_peak_human mem_allocator
  21
+                      rdb_last_bgsave_status aof_last_bgrewrite_status role }
14 22
 
15 23
   def initialize
16  
-    @redis = ::Redis.new(:host => opts[:redis_host], :port => opts[:redis_port])
  24
+    options = if opts[:redis_url] != ''
  25
+                { :url => opts[:redis_url] }
  26
+              elsif opts[:redis_socket] != ''
  27
+                { :path => opts[:redis_socket] }
  28
+              else
  29
+                { :host => opts[:redis_host], :port => opts[:redis_port] }
  30
+              end
  31
+    @redis = ::Redis.new(options)
17 32
     @redis.auth(opts[:redis_password]) unless opts[:redis_password] == ''
  33
+    @section = opts[:redis_section]
18 34
   end
19 35
 
20 36
   def tick
21  
-    @redis.info.each do |property, value|
22  
-      report(
  37
+    @redis.info(@section).each do |property, value|
  38
+      data = {
23 39
         :host    => opts[:redis_host],
24 40
         :service => "redis #{property}",
25 41
         :metric  => value.to_f,
26 42
         :state   => 'ok',
27 43
         :tags    => ['redis']
28  
-      )
  44
+      }
  45
+
  46
+      if STRING_VALUES.include?(property) || property.match(/^db\d+/)
  47
+        if %w{ rdb_last_bgsave_status aof_last_bgrewrite_status }.include?(property)
  48
+          data[:state] = value
  49
+        else
  50
+          data[:description] = value
  51
+        end
  52
+      end
  53
+
  54
+      report(data)
29 55
     end
30 56
   end
31 57
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.