statsdserver 0.8 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
data/bin/statsd CHANGED
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  config = {}
32
32
  %w(daemonize inputs flush_interval outputs prefix percentile
33
- suffix preserve_counters).each do |key|
33
+ suffix preserve_counters timer_names_before_suffix).each do |key|
34
34
  config[key.to_sym] = config_file[key] if config_file[key]
35
35
  end
36
36
 
data/lib/statsdserver.rb CHANGED
@@ -29,6 +29,7 @@ class StatsdServer
29
29
  :flush_interval => 30,
30
30
  :prefix => "stats",
31
31
  :preserve_counters => "true",
32
+ :timer_names_before_suffix => "true",
32
33
  }.merge(opts)
33
34
  @input_config = input_config
34
35
  @output_config = output_config
@@ -165,11 +166,18 @@ class StatsdServer
165
166
  now = Time.now.to_i
166
167
 
167
168
  timers = {}
169
+ gauges = {}
170
+ counters = {}
171
+
168
172
  @stats.timers.keys.each do |k|
169
173
  timers[k] = @stats.timers.delete(k)
170
174
  end
171
175
 
172
- counters = {}
176
+ @stats.gauges.keys.each do |k|
177
+ #gauges[k] = @stats.gauges.delete(k)
178
+ gauges[k] = stats.gauges[k]
179
+ end
180
+
173
181
  @stats.counters.keys.each do |k|
174
182
  counters[k] = @stats.counters.delete(k)
175
183
  end
@@ -184,17 +192,29 @@ class StatsdServer
184
192
  timers.each do |key, values|
185
193
  next if values.length == 0
186
194
  summary = ::StatsdServer::Math.summarize(values, @opts)
187
-
188
- updates << [metric_name("timers.#{key}.mean"),
189
- summary[:mean], now].join(" ")
190
- updates << [metric_name("timers.#{key}.upper"),
191
- summary[:max], now].join(" ")
192
- updates << [metric_name("timers.#{key}.lower"),
193
- summary[:min], now].join(" ")
194
- updates << [metric_name("timers.#{key}.count"),
195
- values.length, now].join(" ")
196
- updates << [metric_name("timers.#{key}.upper_#{@opts[:percentile].to_i}"),
197
- summary[:max_at_threshold], now].join(" ")
195
+ if @opts[:timer_names_before_suffix] == "true"
196
+ updates << [metric_name("timers.#{key}.mean"),
197
+ summary[:mean], now].join(" ")
198
+ updates << [metric_name("timers.#{key}.upper"),
199
+ summary[:max], now].join(" ")
200
+ updates << [metric_name("timers.#{key}.lower"),
201
+ summary[:min], now].join(" ")
202
+ updates << [metric_name("timers.#{key}.count"),
203
+ values.length, now].join(" ")
204
+ updates << [metric_name("timers.#{key}.upper_#{@opts[:percentile].to_i}"),
205
+ summary[:max_at_threshold], now].join(" ")
206
+ else
207
+ updates << [metric_name("timers.#{key}") + ".mean",
208
+ summary[:mean], now].join(" ")
209
+ updates << [metric_name("timers.#{key}") + ".upper",
210
+ summary[:max], now].join(" ")
211
+ updates << [metric_name("timers.#{key}") + ".lower",
212
+ summary[:min], now].join(" ")
213
+ updates << [metric_name("timers.#{key}") + ".count",
214
+ values.length, now].join(" ")
215
+ updates << [metric_name("timers.#{key}") + ".upper_#{@opts[:percentile].to_i}",
216
+ summary[:max_at_threshold], now].join(" ")
217
+ end
198
218
  end # timers.each
199
219
 
200
220
  counters.each do |key, value|
@@ -203,6 +223,12 @@ class StatsdServer
203
223
  now].join(" ")
204
224
  end # counters.each
205
225
 
226
+ gauges.each do |key, value|
227
+ updates << [metric_name(key),
228
+ value,
229
+ now].join(" ")
230
+ end # gauges.each
231
+
206
232
  return updates.length == 0 ? nil : updates.join("\n") + "\n"
207
233
  end # def carbon_update_str
208
234
 
@@ -25,23 +25,25 @@ class StatsdServer
25
25
  if fields[1] == "ms" or fields[1] == "t" # timer update
26
26
  if fields[0].index(",")
27
27
  fields[0].split(",").each do |value_str|
28
- value = Integer(value_str) rescue nil
28
+ value = Float(value_str) rescue nil
29
29
  stats.timers[key] << value if value
30
30
  end
31
31
  else
32
- value = Integer(fields[0]) rescue nil
32
+ value = Float(fields[0]) rescue nil
33
33
  if value.nil?
34
- raise ParseError, "invalid timer value: #{fields[0]}"
34
+ raise ParseError, "invalid timer value for #{key}: #{fields[0]}"
35
35
  end
36
- stats.timers[key] << fields[0].to_i
36
+ stats.timers[key] << value
37
37
  end
38
+
38
39
  elsif fields[1] == "c" # counter update
39
40
  count_str, sample_rate_str = fields[0].split("@", 2)
40
41
 
41
42
  if sample_rate_str
42
43
  sample_rate = Float(sample_rate_str) rescue nil
43
44
  if sample_rate.nil?
44
- raise ParseError, "invalid sample_rate: #{sample_rate_str}"
45
+ raise ParseError, "invalid sample_rate for #{key}: " +
46
+ "#{sample_rate_str}"
45
47
  end
46
48
  else
47
49
  sample_rate = 1
@@ -49,10 +51,19 @@ class StatsdServer
49
51
 
50
52
  count = Integer(count_str) rescue nil
51
53
  if count.nil?
52
- raise ParseError, "invalid count: #{count_str}"
54
+ raise ParseError, "invalid count for #{key}: #{count_str}"
53
55
  end
54
56
 
55
57
  stats.counters[key] += count.to_i * (1 / sample_rate.to_f)
58
+
59
+ elsif fields[1] == "g" # gauge update
60
+ value = Float(fields[0]) rescue nil
61
+ if value.nil?
62
+ raise ParseError, "invalid gauge value for #{key}: #{fields[0]}"
63
+ end
64
+
65
+ stats.gauges[key] = value
66
+
56
67
  else
57
68
  raise ParseError,
58
69
  "invalid update: #{update}: unknown type #{fields[1]}"
@@ -4,12 +4,14 @@ class StatsdServer
4
4
  class Stats
5
5
  attr_accessor :counters,
6
6
  :timers,
7
+ :gauges,
7
8
  :logger
8
9
 
9
10
  public
10
11
  def initialize
11
12
  @timers = Hash.new { |h, k| h[k] = Array.new }
12
13
  @counters = Hash.new { |h, k| h[k] = 0 }
14
+ @gauges = Hash.new { |h, k| h[k] = 0 }
13
15
  @logger = Logger.new(STDERR)
14
16
  end
15
17
  end # class Stats
metadata CHANGED
@@ -1,186 +1,146 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: statsdserver
3
- version: !ruby/object:Gem::Version
4
- version: '0.8'
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 11
9
+ version: "0.11"
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Pete Fritchman
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2013-02-25 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
22
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: daemons
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
54
32
  type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: daemons
55
36
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: eventmachine
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
70
46
  type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: eventmachine
71
50
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: parseconfig
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
86
60
  type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: parseconfig
87
64
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: sysexits
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
102
74
  type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: sysexits
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: bunny
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: em-zeromq
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :runtime
89
+ version_requirements: *id005
142
90
  description: collect and aggregate stats, flush to graphite
143
91
  email: petef@databits.net
144
- executables:
92
+ executables:
145
93
  - statsd
146
94
  extensions: []
95
+
147
96
  extra_rdoc_files: []
148
- files:
149
- - lib/statsdserver/math.rb
150
- - lib/statsdserver/input/udp.rb
97
+
98
+ files:
99
+ - lib/statsdserver.rb
151
100
  - lib/statsdserver/input/zeromq.rb
152
- - lib/statsdserver/output/stdout.rb
153
- - lib/statsdserver/output/tcp.rb
154
- - lib/statsdserver/output/amqp.rb
155
- - lib/statsdserver/stats.rb
101
+ - lib/statsdserver/input/udp.rb
156
102
  - lib/statsdserver/proto/parseerror.rb
157
103
  - lib/statsdserver/proto/v1.rb
158
- - lib/statsdserver.rb
104
+ - lib/statsdserver/stats.rb
105
+ - lib/statsdserver/math.rb
106
+ - lib/statsdserver/output/amqp.rb
107
+ - lib/statsdserver/output/stdout.rb
108
+ - lib/statsdserver/output/tcp.rb
159
109
  - bin/statsd
160
- homepage: https://github.com/fetep/ruby-statsd
161
- licenses:
110
+ has_rdoc: true
111
+ homepage: https://github.com/fetep/ruby-statsdserver
112
+ licenses:
162
113
  - Apache License 2.0
163
114
  post_install_message:
164
115
  rdoc_options: []
165
- require_paths:
116
+
117
+ require_paths:
166
118
  - lib
167
119
  - lib
168
- required_ruby_version: !ruby/object:Gem::Requirement
120
+ required_ruby_version: !ruby/object:Gem::Requirement
169
121
  none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
130
  none: false
176
- requirements:
177
- - - ! '>='
178
- - !ruby/object:Gem::Version
179
- version: '0'
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
180
138
  requirements: []
139
+
181
140
  rubyforge_project:
182
- rubygems_version: 1.8.24
141
+ rubygems_version: 1.6.0
183
142
  signing_key:
184
143
  specification_version: 3
185
144
  summary: statsd (server) -- stat collector/aggregator
186
145
  test_files: []
146
+