librato-metrics-memcached 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/bin/librato-metrics-memcached +137 -0
- data/lib/librato-metrics-memcached.rb +11 -0
- data/lib/librato-metrics-memcached/version.rb +7 -0
- data/librato-metrics-memcached.gemspec +29 -0
- data/test/helper.rb +18 -0
- data/test/test_librato-metrics-memcached.rb +7 -0
- metadata +185 -0
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
librato-metrics-memcached (0.0.1)
|
5
|
+
librato-metrics (~> 0.5.0)
|
6
|
+
memcached (~> 1.4.1)
|
7
|
+
trollop (~> 1.16.2)
|
8
|
+
yajl-ruby (~> 1.1.0)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.2.7)
|
14
|
+
faraday (0.7.6)
|
15
|
+
addressable (~> 2.2)
|
16
|
+
multipart-post (~> 1.1)
|
17
|
+
rack (~> 1.1)
|
18
|
+
json (1.6.6)
|
19
|
+
librato-metrics (0.5.0)
|
20
|
+
faraday (~> 0.7.6)
|
21
|
+
multi_json
|
22
|
+
memcached (1.4.1)
|
23
|
+
multi_json (1.3.2)
|
24
|
+
multipart-post (1.1.5)
|
25
|
+
rack (1.4.1)
|
26
|
+
rake (0.9.2.2)
|
27
|
+
rdoc (3.12)
|
28
|
+
json (~> 1.4)
|
29
|
+
shoulda (3.0.1)
|
30
|
+
shoulda-context (~> 1.0.0)
|
31
|
+
shoulda-matchers (~> 1.0.0)
|
32
|
+
shoulda-context (1.0.0)
|
33
|
+
shoulda-matchers (1.0.0)
|
34
|
+
trollop (1.16.2)
|
35
|
+
yajl-ruby (1.1.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
librato-metrics-memcached!
|
42
|
+
rake
|
43
|
+
rdoc (~> 3.12)
|
44
|
+
shoulda
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Mike Heffner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# librato-metrics-memcached
|
2
|
+
|
3
|
+
Pull statistics from one or more memcached servers and submit them to
|
4
|
+
[Librato Metrics](https://metrics.librato.com). Intended to be run
|
5
|
+
periodically, for example, from cron.
|
6
|
+
|
7
|
+
### Install
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install librato-metrics-memcached
|
11
|
+
```
|
12
|
+
|
13
|
+
### Run
|
14
|
+
|
15
|
+
```
|
16
|
+
$ librato-metrics-memcached --hosts mem1.server.com:11211 \
|
17
|
+
--email foobar@example.com \
|
18
|
+
--token 1234567890
|
19
|
+
```
|
20
|
+
|
21
|
+
### Options
|
22
|
+
|
23
|
+
* `hosts`: One or more memcached servers in the form
|
24
|
+
`server:port`. Separate multiple servers with a comma ",".
|
25
|
+
* `email`: Email associated with your Librato Metrics account.
|
26
|
+
* `token`: API token for your Librato Metrics accounts.
|
27
|
+
* `prefix`: Prefix to use for metric names. Defaults to
|
28
|
+
**memcached.**.
|
29
|
+
* `floor-in-secs`: By default all measurements are posted with
|
30
|
+
the current time as the measure_time. This option,
|
31
|
+
specified as a value in seconds, will floor the
|
32
|
+
time by this value. For example, 300 would floor
|
33
|
+
all measure times to the 5 minute mark.
|
34
|
+
|
35
|
+
|
36
|
+
## Contributing to librato-metrics-memcached
|
37
|
+
|
38
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
39
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
40
|
+
* Fork the project.
|
41
|
+
* Start a feature/bugfix branch.
|
42
|
+
* Commit and push until you are happy with your contribution.
|
43
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
44
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
45
|
+
|
46
|
+
## Copyright
|
47
|
+
|
48
|
+
Copyright (c) 2012 Mike Heffner. See LICENSE.txt for
|
49
|
+
further details.
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
# require 'rubygems'
|
5
|
+
# require 'bundler'
|
6
|
+
|
7
|
+
# Bundler.require
|
8
|
+
|
9
|
+
require 'trollop'
|
10
|
+
require 'memcached'
|
11
|
+
require 'yajl'
|
12
|
+
require 'librato/metrics'
|
13
|
+
|
14
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
15
|
+
|
16
|
+
require 'librato-metrics-memcached'
|
17
|
+
|
18
|
+
parser = Trollop::Parser.new do
|
19
|
+
version "librato-metrics-memcached version %s" %
|
20
|
+
[Librato::Metrics::Memcached.version]
|
21
|
+
|
22
|
+
opt :api, "Change the API endpoint", {
|
23
|
+
:type => :string, :default => "metrics-api.librato.com"
|
24
|
+
}
|
25
|
+
|
26
|
+
opt :hosts, "Memcached hosts (host1,host2,etc)", {
|
27
|
+
:type => :string, :default => ENV['MEMCACHED_SERVERS']
|
28
|
+
}
|
29
|
+
|
30
|
+
opt :email, "Librato Metrics Email", {
|
31
|
+
:type => :string, :default => ENV['LIBRATO_METRICS_EMAIL']
|
32
|
+
}
|
33
|
+
|
34
|
+
opt :token, "Librato Metrics API Token", {
|
35
|
+
:type => :string, :default => ENV['LIBRATO_METRICS_TOKEN']
|
36
|
+
}
|
37
|
+
|
38
|
+
opt :prefix, "Metric name prefix", {
|
39
|
+
:type => :string, :default => "memcached."
|
40
|
+
}
|
41
|
+
|
42
|
+
opt :floor_in_secs, "floor() measure times to this interval", {
|
43
|
+
:type => :int
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
opts = Trollop::with_standard_exception_handling(parser) do
|
48
|
+
if ARGV.length == 0
|
49
|
+
raise Trollop::HelpNeeded
|
50
|
+
end
|
51
|
+
|
52
|
+
opts = parser.parse ARGV
|
53
|
+
%w{ hosts email token }.each do |f|
|
54
|
+
unless opts[f.to_sym]
|
55
|
+
$stderr.puts "Error: Must specify option --%s." % [f]
|
56
|
+
puts
|
57
|
+
raise Trollop::HelpNeeded
|
58
|
+
end
|
59
|
+
end
|
60
|
+
opts
|
61
|
+
end
|
62
|
+
|
63
|
+
mt = Time.now.tv_sec
|
64
|
+
if opts[:floor_in_secs]
|
65
|
+
mt = (mt / opts[:floor_in_secs]) * opts[:floor_in_secs]
|
66
|
+
end
|
67
|
+
|
68
|
+
servers = opts[:hosts].split(",")
|
69
|
+
|
70
|
+
begin
|
71
|
+
cache = Memcached.new(servers)
|
72
|
+
stats = cache.stats
|
73
|
+
rescue => err
|
74
|
+
$stderr.puts "Failed to read stats from memcached: #{err.message}"
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def server_name(n)
|
79
|
+
n.split(":").first
|
80
|
+
end
|
81
|
+
|
82
|
+
def metric_name(n, opts)
|
83
|
+
("%s%s" % [opts[:prefix], n]).to_sym
|
84
|
+
end
|
85
|
+
|
86
|
+
endpoint = "https://#{opts[:api]}"
|
87
|
+
client = Librato::Metrics::Client.new
|
88
|
+
client.api_endpoint = endpoint
|
89
|
+
client.authenticate opts[:email], opts[:token]
|
90
|
+
|
91
|
+
q = client.new_queue
|
92
|
+
|
93
|
+
stats.each_pair do |stat, values|
|
94
|
+
if values.length != servers.length
|
95
|
+
$stderr.puts "Unable to grab stat #{stat} for each server"
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
|
99
|
+
# Skip static stats
|
100
|
+
if %w{pointer_size time version pid}.include?(stat.to_s)
|
101
|
+
next
|
102
|
+
end
|
103
|
+
|
104
|
+
servers.each_with_index do |srv, i|
|
105
|
+
gauges = [:curr_connections, :limit_maxbytes, :bytes,
|
106
|
+
:connection_structures, :curr_items,
|
107
|
+
:rusage_user, :rusage_system, :threads]
|
108
|
+
|
109
|
+
if gauges.include?(stat.to_sym)
|
110
|
+
q.add metric_name(stat, opts) => {
|
111
|
+
:type => :gauge,
|
112
|
+
:value => values[i],
|
113
|
+
:source => server_name(srv),
|
114
|
+
:measure_time => mt
|
115
|
+
}
|
116
|
+
else
|
117
|
+
q.add metric_name(stat, opts) => {
|
118
|
+
:type => :counter,
|
119
|
+
:value => values[i],
|
120
|
+
:source => server_name(srv),
|
121
|
+
:measure_time => mt
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
begin
|
128
|
+
q.submit
|
129
|
+
rescue => err
|
130
|
+
$stderr.puts "Failed to submit stats to Librato Metrics: %s" %
|
131
|
+
[err.message]
|
132
|
+
exit 1
|
133
|
+
end
|
134
|
+
|
135
|
+
# Local Variables:
|
136
|
+
# mode: ruby
|
137
|
+
# End:
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "librato-metrics-memcached/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "librato-metrics-memcached"
|
7
|
+
s.version = Librato::Metrics::Memcached::VERSION
|
8
|
+
s.authors = ["Mike Heffner"]
|
9
|
+
s.email = ["mike@librato.com"]
|
10
|
+
s.homepage = "https://github.com/librato/librato-metrics-memcached"
|
11
|
+
s.summary = %q{Push memcached stats to Librato Metrics}
|
12
|
+
s.description = %q{Pull stats from memcached and push to Librato Metrics}
|
13
|
+
|
14
|
+
s.rubyforge_project = "librato-metrics-memcached"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency(%q<trollop>, ["~> 1.16.2"])
|
22
|
+
s.add_runtime_dependency(%q<memcached>, ["~> 1.4.1"])
|
23
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 1.1.0"])
|
24
|
+
s.add_runtime_dependency(%q<librato-metrics>, ["~> 0.5.0"])
|
25
|
+
|
26
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
27
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
29
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'librato-metrics-memcached'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: librato-metrics-memcached
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mike Heffner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-05-01 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 83
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 16
|
30
|
+
- 2
|
31
|
+
version: 1.16.2
|
32
|
+
requirement: *id001
|
33
|
+
name: trollop
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 5
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 4
|
46
|
+
- 1
|
47
|
+
version: 1.4.1
|
48
|
+
requirement: *id002
|
49
|
+
name: memcached
|
50
|
+
prerelease: false
|
51
|
+
type: :runtime
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 19
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 1
|
62
|
+
- 0
|
63
|
+
version: 1.1.0
|
64
|
+
requirement: *id003
|
65
|
+
name: yajl-ruby
|
66
|
+
prerelease: false
|
67
|
+
type: :runtime
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 11
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 5
|
78
|
+
- 0
|
79
|
+
version: 0.5.0
|
80
|
+
requirement: *id004
|
81
|
+
name: librato-metrics
|
82
|
+
prerelease: false
|
83
|
+
type: :runtime
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirement: *id005
|
95
|
+
name: rake
|
96
|
+
prerelease: false
|
97
|
+
type: :development
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirement: *id006
|
109
|
+
name: shoulda
|
110
|
+
prerelease: false
|
111
|
+
type: :development
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 31
|
119
|
+
segments:
|
120
|
+
- 3
|
121
|
+
- 12
|
122
|
+
version: "3.12"
|
123
|
+
requirement: *id007
|
124
|
+
name: rdoc
|
125
|
+
prerelease: false
|
126
|
+
type: :development
|
127
|
+
description: Pull stats from memcached and push to Librato Metrics
|
128
|
+
email:
|
129
|
+
- mike@librato.com
|
130
|
+
executables:
|
131
|
+
- librato-metrics-memcached
|
132
|
+
extensions: []
|
133
|
+
|
134
|
+
extra_rdoc_files: []
|
135
|
+
|
136
|
+
files:
|
137
|
+
- .document
|
138
|
+
- .gitignore
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/librato-metrics-memcached
|
145
|
+
- lib/librato-metrics-memcached.rb
|
146
|
+
- lib/librato-metrics-memcached/version.rb
|
147
|
+
- librato-metrics-memcached.gemspec
|
148
|
+
- test/helper.rb
|
149
|
+
- test/test_librato-metrics-memcached.rb
|
150
|
+
homepage: https://github.com/librato/librato-metrics-memcached
|
151
|
+
licenses: []
|
152
|
+
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 3
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
requirements: []
|
177
|
+
|
178
|
+
rubyforge_project: librato-metrics-memcached
|
179
|
+
rubygems_version: 1.8.10
|
180
|
+
signing_key:
|
181
|
+
specification_version: 3
|
182
|
+
summary: Push memcached stats to Librato Metrics
|
183
|
+
test_files:
|
184
|
+
- test/helper.rb
|
185
|
+
- test/test_librato-metrics-memcached.rb
|