tabs 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -8
- data/lib/tabs/config.rb +8 -0
- data/lib/tabs/helpers.rb +0 -5
- data/lib/tabs/metrics/counter/stats.rb +2 -1
- data/lib/tabs/metrics/task.rb +1 -1
- data/lib/tabs/metrics/value/stats.rb +2 -1
- data/lib/tabs/version.rb +1 -1
- data/spec/lib/tabs/metrics/counter/stats_spec.rb +6 -1
- data/spec/lib/tabs/metrics/value/stats_spec.rb +20 -0
- data/spec/lib/tabs/metrics/value_spec.rb +0 -1
- data/spec/lib/tabs/task_spec.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -52,7 +52,7 @@ To retrieve the counts for a given time period just call `Tabs#get_stats` with t
|
|
52
52
|
```ruby
|
53
53
|
Tabs.get_stats("website-visits", 10.days.ago..Time.now, :hour)
|
54
54
|
```
|
55
|
-
|
55
|
+
|
56
56
|
This will return stats for the last 10 days by hour in the form of a `Tabs::Metrics::Counter::Stats` object. This object is enumerable so you can iterate through the results like so:
|
57
57
|
|
58
58
|
```ruby
|
@@ -81,7 +81,7 @@ results.avg #=> The avg count for timestamps in the period
|
|
81
81
|
results.period #=> The timestamp range that was requested
|
82
82
|
results.resolution #=> The resolution requested
|
83
83
|
```
|
84
|
-
|
84
|
+
|
85
85
|
Timestamps for the given period in which no events occurred will be "filled in" with a count value to make visualizations easier.
|
86
86
|
|
87
87
|
The timestamps are also normalized. For example, in hour resolution, the minutes and seconds of the timestamps are set to 00:00. Likewise for the week resolution, the day is set to the first day of the week.
|
@@ -116,13 +116,13 @@ a metric as well:
|
|
116
116
|
```ruby
|
117
117
|
Tabs.create_metric("new-user-age", "value")
|
118
118
|
```
|
119
|
-
|
119
|
+
|
120
120
|
Retrieving the stats for a value metric is just like retrieving a counter metric.
|
121
121
|
|
122
122
|
```ruby
|
123
123
|
Tabs.get_stats("new-user-age", 6.months.ago..Time.now, :month)
|
124
124
|
```
|
125
|
-
|
125
|
+
|
126
126
|
This will return a `Tabs::Metrics::Value::Stats` object. Again, this
|
127
127
|
object is enumerable and encapsulates all the timestamps within the
|
128
128
|
given period.
|
@@ -229,7 +229,7 @@ To drop a metric, just call `Tabs#drop_metric`
|
|
229
229
|
```ruby
|
230
230
|
Tabs.drop_metric!("website-visits")
|
231
231
|
```
|
232
|
-
|
232
|
+
|
233
233
|
This will drop all recorded values for the metric so it may not be un-done...be careful.
|
234
234
|
|
235
235
|
Even more dangerous, you can drop all metrics...be very careful.
|
@@ -240,17 +240,21 @@ Tabs.drop_all_metrics!
|
|
240
240
|
|
241
241
|
### Configuration
|
242
242
|
|
243
|
-
|
243
|
+
Tabs just works out of the box. However, if you want to override the default Redis connection or decimal precision, this is how:
|
244
244
|
|
245
245
|
```ruby
|
246
246
|
Tabs.configure do |config|
|
247
247
|
|
248
248
|
# set it to an existing connection
|
249
249
|
config.redis = Redis.current
|
250
|
-
|
250
|
+
|
251
251
|
# pass a config hash that will be passed to Redis.new
|
252
252
|
config.redis = { :host => 'localhost', :port => 6379 }
|
253
|
-
|
253
|
+
|
254
|
+
# override default decimal precision (5)
|
255
|
+
# affects stat averages and task completion rate
|
256
|
+
config.decimal_precision = 2
|
257
|
+
|
254
258
|
end
|
255
259
|
```
|
256
260
|
|
data/lib/tabs/config.rb
CHANGED
data/lib/tabs/helpers.rb
CHANGED
data/lib/tabs/metrics/task.rb
CHANGED
@@ -35,7 +35,7 @@ module Tabs
|
|
35
35
|
started_tokens = tokens_for_period(range, resolution, "started")
|
36
36
|
completed_tokens = tokens_for_period(range, resolution, "completed")
|
37
37
|
matching_tokens = started_tokens & completed_tokens
|
38
|
-
completion_rate =
|
38
|
+
completion_rate = (matching_tokens.size.to_f / range.size).round(Config.decimal_precision)
|
39
39
|
elapsed_times = matching_tokens.map { |t| t.time_elapsed(resolution) }
|
40
40
|
average_completion_time = (elapsed_times.inject(&:+)) / matching_tokens.size
|
41
41
|
Stats.new(
|
data/lib/tabs/version.rb
CHANGED
@@ -31,7 +31,12 @@ describe Tabs::Metrics::Counter::Stats do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "avg returns the average for the entire set" do
|
34
|
-
expect(stats.avg).to eq 86.
|
34
|
+
expect(stats.avg).to eq 86.33333
|
35
|
+
end
|
36
|
+
|
37
|
+
it "avg returns 0 if values empty" do
|
38
|
+
stats = Tabs::Metrics::Counter::Stats.new(period, resolution, [])
|
39
|
+
expect(stats.avg).to be_zero
|
35
40
|
end
|
36
41
|
|
37
42
|
end
|
@@ -38,4 +38,24 @@ describe Tabs::Metrics::Value::Stats do
|
|
38
38
|
expect(stats.avg).to eq 16.76
|
39
39
|
end
|
40
40
|
|
41
|
+
it "avg returns 0 if set is empty" do
|
42
|
+
stats = Tabs::Metrics::Value::Stats.new(period, resolution, [])
|
43
|
+
expect(stats.avg).to be_zero
|
44
|
+
end
|
45
|
+
|
46
|
+
context "override decimal precision" do
|
47
|
+
before do
|
48
|
+
@precision = Tabs.config.decimal_precision
|
49
|
+
Tabs.config.decimal_precision = 1
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
Tabs.config.decimal_precision = @precision
|
54
|
+
end
|
55
|
+
|
56
|
+
it "allows you to override decimal precision" do
|
57
|
+
expect(stats.avg).to eq 16.8
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
end
|
@@ -95,7 +95,6 @@ describe Tabs::Metrics::Value do
|
|
95
95
|
expect(stats).to include({ "timestamp" => (now + 3.years), "count"=>1, "min"=>10, "max"=>10, "sum"=>10, "avg"=>10})
|
96
96
|
expect(stats).to include({ "timestamp" => (now + 6.years), "count"=>2, "min"=>15, "max"=>20, "sum"=>35, "avg"=>17})
|
97
97
|
end
|
98
|
-
|
99
98
|
end
|
100
99
|
|
101
100
|
describe ".drop!" do
|
data/spec/lib/tabs/task_spec.rb
CHANGED
@@ -66,7 +66,7 @@ describe Tabs::Metrics::Task do
|
|
66
66
|
expect(stats.started_within_period).to eq 3
|
67
67
|
expect(stats.completed_within_period).to eq 2
|
68
68
|
expect(stats.started_and_completed_within_period).to eq 2
|
69
|
-
expect(stats.completion_rate).to eq 0.
|
69
|
+
expect(stats.completion_rate).to eq 0.18182
|
70
70
|
expect(stats.average_completion_time).to eq 1.5
|
71
71
|
end
|
72
72
|
|