riemann-redis 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODEzOWFkNTY1ZTgzMjVlY2I1MjRkODcwYjVjNjZhODQxMWQ5YTIyYw==
5
+ data.tar.gz: !binary |-
6
+ Mzc4OWU0M2FlODNhODhmNGVjYmUxYmM5NmY2NjFmNjI0YWE1MDE2NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjRhZjYxNWQwMDU3ZDUzMGQ3NDBhODUzOThlNThjOTNkNGE2NDQxNzM3Zjc0
10
+ Zjg0YWY1YjcwMDdlM2UwOGYwYzViMzg3N2MwNzc2YzNkOTQ0MTBlM2M1ZDIw
11
+ MTFmZjAwMDEzM2ZmNzI5Nzc4MjM2NWMzZTE3ODNjMDI5YTQyNWQ=
12
+ data.tar.gz: !binary |-
13
+ YzBjYWJjMDMwOWM2YzdiMjBkZDhmYmM2ZWFkYzgwNzNhNjg5YzViMGYxNTFh
14
+ N2VhMjU0MzBjYzVlOTY0YjJlZTQ3OWYwMzk0ZWE2OWNkOTJhNmFhYTEyZWUw
15
+ N2FmZjNiY2I3MDY0OTMzYzRlZTY4NWVmZTBiOWI4MzIxZGJmNDE=
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Kyle Kingsbury
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ Riemann Redis
2
+ =============
3
+
4
+ Simple redis riemann client.
5
+
6
+ Submits the result of INFO [section] and SLOWLOG query into riemann.
7
+
8
+ Supports multiple sections by performing multiple INFO queries.
9
+
10
+ Get started
11
+ ==========
12
+
13
+ ``` bash
14
+ gem install riemann-redis
15
+ riemann-redis --help
16
+ riemann-redis-slowlog --help
17
+ ```
data/bin/riemann-redis ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Gathers redis INFO statistics and submits them to Riemann.
4
+
5
+ require 'riemann/tools'
6
+
7
+ class Riemann::Tools::Redis
8
+ include Riemann::Tools
9
+ require 'redis'
10
+
11
+ opt :redis_host, "Redis hostname", :default => 'localhost'
12
+ opt :redis_port, "Redis port", :default => 6379
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, multiple values separated by spaces", :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 }
22
+
23
+ def initialize
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)
32
+ @redis.auth(opts[:redis_password]) unless opts[:redis_password] == ''
33
+ @section = opts[:redis_section].split
34
+ end
35
+
36
+ def tick
37
+ begin
38
+ @section.each do |section|
39
+ @redis.info(section).each do |property, value|
40
+ data = {
41
+ :host => opts[:redis_host].dup,
42
+ :service => "redis #{property}",
43
+ :metric => value.to_f,
44
+ :state => value.to_s,
45
+ :tags => ['redis']
46
+ }
47
+
48
+ if STRING_VALUES.include?(property) || property.match(/^db\d+/)
49
+ if %w{ rdb_last_bgsave_status aof_last_bgrewrite_status }.include?(property)
50
+ data[:state] = value
51
+ else
52
+ data[:description] = value
53
+ end
54
+ end
55
+
56
+ if property == "run_id"
57
+ data[:metric] = 0
58
+ end
59
+
60
+ report(data)
61
+ end
62
+ end
63
+ rescue ::Redis::CommandError => e
64
+ if e.message == "ERR operation not permitted"
65
+ @redis.auth(opts[:redis_password]) unless opts[:redis_password] == ''
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ Riemann::Tools::Redis.run
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Gathers Redis SLOWLOG statistics and submits them to Riemann.
4
+
5
+ require 'riemann/tools'
6
+
7
+ class Riemann::Tools::RedisSlowlog
8
+ include Riemann::Tools
9
+ require 'redis'
10
+
11
+ opt :redis_url, "Redis URL", :default => 'redis://127.0.0.1:6379/'
12
+ opt :redis_password, "Redis password", :default => ''
13
+ opt :slowlog_len, "Number of SLOWLOG entries to get", :default => 10
14
+ opt :slowlog_reset, "Reset SLOWLOG after querying it", :default => false
15
+
16
+ def initialize
17
+ @redis = ::Redis.new(url: opts[:redis_url])
18
+
19
+ @slowlog_len = opts[:slowlog_len]
20
+ @slowlog_reset = opts[:slowlog_reset]
21
+
22
+ @redis.auth(opts[:redis_password]) unless opts[:redis_password] == ''
23
+ end
24
+
25
+ def tick
26
+ @redis.slowlog("GET", @slowlog_len).each do |id, timestamp, us, cmd|
27
+ data = {
28
+ :host => @redis.client.host,
29
+ :service => "redis",
30
+ :time => timestamp,
31
+ :metric => us.to_f,
32
+ :state => 'warning',
33
+ :tags => ['redis', 'slowlog'],
34
+ :description => cmd.inspect
35
+ }
36
+ report(data)
37
+ end
38
+
39
+ @redis.slowlog("RESET") if @slowlog_reset
40
+ end
41
+
42
+ end
43
+
44
+ Riemann::Tools::RedisSlowlog.run
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fede Borgnia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.2
41
+ description:
42
+ email: fborgnia@gmail.com
43
+ executables:
44
+ - riemann-redis
45
+ - riemann-redis-slowlog
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/riemann-redis
50
+ - bin/riemann-redis-slowlog
51
+ - LICENSE
52
+ - README.md
53
+ homepage: https://github.com/riemann/riemann-redis
54
+ licenses: []
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 1.8.7
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: riemann-redis
72
+ rubygems_version: 2.1.11
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Redis client that submits events to Riemann.
76
+ test_files: []