graphite 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/graphite.gemspec +2 -2
- data/lib/graphite/client.rb +19 -10
- data/lib/graphite/logger.rb +7 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/graphite.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{graphite}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian Ragsdale", "Mike Subelsky"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-15}
|
13
13
|
s.description = %q{Ruby client for sending stats to Graphite}
|
14
14
|
s.email = %q{mike@capitalthought.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/graphite/client.rb
CHANGED
@@ -8,8 +8,8 @@ module Graphite
|
|
8
8
|
# to identify this server. Example:
|
9
9
|
# Graphite::Client.new("graphite.example.com", "yourapp.#{Rails.env}.instances.#{hostname}.#{$$}")
|
10
10
|
|
11
|
-
def initialize(server, prefix)
|
12
|
-
@logger = Graphite::Logger.new(server)
|
11
|
+
def initialize(server, prefix, logger = nil)
|
12
|
+
@logger = Graphite::Logger.new(server,logger)
|
13
13
|
@prefix = prefix
|
14
14
|
@metrics = {}
|
15
15
|
@counters = {}
|
@@ -27,6 +27,15 @@ module Graphite
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def previous_day_metric(name)
|
31
|
+
@scheduler.every("1d", :first_in => '1m') do
|
32
|
+
date = Date.today - 1
|
33
|
+
result = yield date
|
34
|
+
log({name + ".daily" => result})
|
35
|
+
cleanup
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
30
39
|
def metric(name, frequency = 1.minute, options = {})
|
31
40
|
add_shifts(name,options[:shifts]) if options[:shifts]
|
32
41
|
@scheduler.every(frequency, :first_in => '1m') do
|
@@ -36,13 +45,6 @@ module Graphite
|
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
39
|
-
def add_shifts(name, shifts)
|
40
|
-
shifts.each do |seconds|
|
41
|
-
@shifts[seconds] ||= []
|
42
|
-
@shifts[seconds] << name
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
48
|
def metrics(frequency = 1.minute)
|
47
49
|
@scheduler.every(frequency, :first_in => '1m') do
|
48
50
|
results = yield
|
@@ -59,6 +61,13 @@ module Graphite
|
|
59
61
|
|
60
62
|
private
|
61
63
|
|
64
|
+
def add_shifts(name, shifts)
|
65
|
+
shifts.each do |seconds|
|
66
|
+
@shifts[seconds] ||= []
|
67
|
+
@shifts[seconds] << name
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
62
71
|
def log(results)
|
63
72
|
results.keys.each do |k,v|
|
64
73
|
@metrics["#{@prefix}.#{k}"] = results.delete(k)
|
@@ -106,4 +115,4 @@ module Graphite
|
|
106
115
|
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
|
107
116
|
end
|
108
117
|
end
|
109
|
-
end
|
118
|
+
end
|
data/lib/graphite/logger.rb
CHANGED
@@ -33,8 +33,13 @@ module Graphite
|
|
33
33
|
message << "#{key} #{value.to_f} #{time.to_i}\n"
|
34
34
|
end
|
35
35
|
logger.info("Graphite: #{message}") if logger
|
36
|
-
|
36
|
+
begin
|
37
|
+
socket.write(message)
|
38
|
+
rescue Errno::EPIPE
|
39
|
+
@socket = nil
|
40
|
+
retry
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
end
|
40
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ragsdale
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-03-15 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|