pulse-meter 0.4.9 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -48
- data/lib/pulse-meter.rb +1 -68
- data/lib/pulse-meter/visualizer.rb +1 -40
- data/pulse-meter.gemspec +4 -26
- metadata +10 -558
- data/Procfile +0 -3
- data/bin/pulse +0 -6
- data/examples/basic.ru +0 -145
- data/examples/basic_sensor_data.rb +0 -96
- data/examples/udp_benchmark.rb +0 -29
- data/lib/cmd.rb +0 -171
- data/lib/pulse-meter/command_aggregator/async.rb +0 -83
- data/lib/pulse-meter/command_aggregator/sync.rb +0 -18
- data/lib/pulse-meter/command_aggregator/udp.rb +0 -48
- data/lib/pulse-meter/extensions/enumerable.rb +0 -24
- data/lib/pulse-meter/mixins/cmd.rb +0 -46
- data/lib/pulse-meter/mixins/dumper.rb +0 -87
- data/lib/pulse-meter/mixins/utils.rb +0 -155
- data/lib/pulse-meter/observer.rb +0 -120
- data/lib/pulse-meter/observer/extended.rb +0 -34
- data/lib/pulse-meter/sensor.rb +0 -61
- data/lib/pulse-meter/sensor/base.rb +0 -88
- data/lib/pulse-meter/sensor/configuration.rb +0 -106
- data/lib/pulse-meter/sensor/counter.rb +0 -39
- data/lib/pulse-meter/sensor/hashed_counter.rb +0 -36
- data/lib/pulse-meter/sensor/hashed_indicator.rb +0 -24
- data/lib/pulse-meter/sensor/indicator.rb +0 -35
- data/lib/pulse-meter/sensor/multi.rb +0 -97
- data/lib/pulse-meter/sensor/timeline.rb +0 -236
- data/lib/pulse-meter/sensor/timeline_reduce.rb +0 -68
- data/lib/pulse-meter/sensor/timelined/average.rb +0 -32
- data/lib/pulse-meter/sensor/timelined/counter.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +0 -31
- data/lib/pulse-meter/sensor/timelined/hashed_indicator.rb +0 -30
- data/lib/pulse-meter/sensor/timelined/indicator.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/max.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/median.rb +0 -14
- data/lib/pulse-meter/sensor/timelined/min.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/multi_percentile.rb +0 -34
- data/lib/pulse-meter/sensor/timelined/percentile.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/uniq_counter.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/zset_based.rb +0 -38
- data/lib/pulse-meter/sensor/uniq_counter.rb +0 -24
- data/lib/pulse-meter/server.rb +0 -0
- data/lib/pulse-meter/server/command_line_options.rb +0 -0
- data/lib/pulse-meter/server/config_options.rb +0 -0
- data/lib/pulse-meter/server/sensors.rb +0 -0
- data/lib/pulse-meter/udp_server.rb +0 -45
- data/lib/pulse-meter/version.rb +0 -3
- data/lib/pulse-meter/visualize/app.rb +0 -78
- data/lib/pulse-meter/visualize/base.rb +0 -15
- data/lib/pulse-meter/visualize/coffee/application.coffee +0 -40
- data/lib/pulse-meter/visualize/coffee/collections/page_info_list.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/collections/sensor_info_list.coffee +0 -4
- data/lib/pulse-meter/visualize/coffee/collections/widget_list.coffee +0 -14
- data/lib/pulse-meter/visualize/coffee/extensions.coffee +0 -26
- data/lib/pulse-meter/visualize/coffee/models/dinamic_widget.coffee +0 -34
- data/lib/pulse-meter/visualize/coffee/models/page_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/sensor_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/widget.coffee +0 -54
- data/lib/pulse-meter/visualize/coffee/presenters/area.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/gauge.coffee +0 -11
- data/lib/pulse-meter/visualize/coffee/presenters/line.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/pie.coffee +0 -20
- data/lib/pulse-meter/visualize/coffee/presenters/series.coffee +0 -44
- data/lib/pulse-meter/visualize/coffee/presenters/table.coffee +0 -10
- data/lib/pulse-meter/visualize/coffee/presenters/timeline.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/presenters/widget.coffee +0 -65
- data/lib/pulse-meter/visualize/coffee/router.coffee +0 -21
- data/lib/pulse-meter/visualize/coffee/views/dynamic_chart.coffee +0 -91
- data/lib/pulse-meter/visualize/coffee/views/dynamic_widget.coffee +0 -58
- data/lib/pulse-meter/visualize/coffee/views/page_title.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/views/page_titles.coffee +0 -15
- data/lib/pulse-meter/visualize/coffee/views/sensor_info_list.coffee +0 -19
- data/lib/pulse-meter/visualize/coffee/views/widget.coffee +0 -99
- data/lib/pulse-meter/visualize/coffee/views/widget_chart.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/views/widget_list.coffee +0 -15
- data/lib/pulse-meter/visualize/dsl/base.rb +0 -131
- data/lib/pulse-meter/visualize/dsl/errors.rb +0 -40
- data/lib/pulse-meter/visualize/dsl/layout.rb +0 -27
- data/lib/pulse-meter/visualize/dsl/page.rb +0 -33
- data/lib/pulse-meter/visualize/dsl/sensor.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widget.rb +0 -37
- data/lib/pulse-meter/visualize/dsl/widgets/area.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widgets/gauge.rb +0 -12
- data/lib/pulse-meter/visualize/dsl/widgets/line.rb +0 -21
- data/lib/pulse-meter/visualize/dsl/widgets/pie.rb +0 -16
- data/lib/pulse-meter/visualize/dsl/widgets/table.rb +0 -19
- data/lib/pulse-meter/visualize/layout.rb +0 -79
- data/lib/pulse-meter/visualize/page.rb +0 -25
- data/lib/pulse-meter/visualize/public/css/application.css +0 -56
- data/lib/pulse-meter/visualize/public/css/bootstrap.css +0 -4883
- data/lib/pulse-meter/visualize/public/css/bootstrap.min.css +0 -729
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +0 -1320
- data/lib/pulse-meter/visualize/public/favicon.ico +0 -208
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings.png +0 -0
- data/lib/pulse-meter/visualize/public/js/application.js +0 -973
- data/lib/pulse-meter/visualize/public/js/backbone-min.js +0 -38
- data/lib/pulse-meter/visualize/public/js/bootstrap.js +0 -1835
- data/lib/pulse-meter/visualize/public/js/jquery-1.7.2.min.js +0 -4
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +0 -791
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +0 -21
- data/lib/pulse-meter/visualize/public/js/jquery-ui-timepicker-addon.js +0 -1687
- data/lib/pulse-meter/visualize/public/js/json2.js +0 -487
- data/lib/pulse-meter/visualize/public/js/underscore-min.js +0 -32
- data/lib/pulse-meter/visualize/sensor.rb +0 -63
- data/lib/pulse-meter/visualize/series_extractor.rb +0 -107
- data/lib/pulse-meter/visualize/views/main.haml +0 -30
- data/lib/pulse-meter/visualize/views/sensors.haml +0 -76
- data/lib/pulse-meter/visualize/views/widgets/area.haml +0 -53
- data/lib/pulse-meter/visualize/views/widgets/extend_options.haml +0 -11
- data/lib/pulse-meter/visualize/views/widgets/gauge.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/line.haml +0 -54
- data/lib/pulse-meter/visualize/views/widgets/pie.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/table.haml +0 -45
- data/lib/pulse-meter/visualize/widget.rb +0 -38
- data/lib/pulse-meter/visualize/widgets/gauge.rb +0 -47
- data/lib/pulse-meter/visualize/widgets/pie.rb +0 -36
- data/lib/pulse-meter/visualize/widgets/timeline.rb +0 -114
- data/spec/pulse_meter/command_aggregator/async_spec.rb +0 -53
- data/spec/pulse_meter/command_aggregator/sync_spec.rb +0 -25
- data/spec/pulse_meter/command_aggregator/udp_spec.rb +0 -45
- data/spec/pulse_meter/extensions/enumerable_spec.rb +0 -58
- data/spec/pulse_meter/mixins/cmd_spec.rb +0 -117
- data/spec/pulse_meter/mixins/dumper_spec.rb +0 -162
- data/spec/pulse_meter/mixins/utils_spec.rb +0 -212
- data/spec/pulse_meter/observer/extended_spec.rb +0 -92
- data/spec/pulse_meter/observer_spec.rb +0 -207
- data/spec/pulse_meter/sensor/base_spec.rb +0 -106
- data/spec/pulse_meter/sensor/configuration_spec.rb +0 -103
- data/spec/pulse_meter/sensor/counter_spec.rb +0 -54
- data/spec/pulse_meter/sensor/hashed_counter_spec.rb +0 -43
- data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +0 -39
- data/spec/pulse_meter/sensor/indicator_spec.rb +0 -43
- data/spec/pulse_meter/sensor/multi_spec.rb +0 -137
- data/spec/pulse_meter/sensor/timeline_spec.rb +0 -88
- data/spec/pulse_meter/sensor/timelined/average_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/counter_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/hashed_indicator_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/indicator_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/max_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/median_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/min_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +0 -21
- data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +0 -17
- data/spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb +0 -9
- data/spec/pulse_meter/sensor/uniq_counter_spec.rb +0 -28
- data/spec/pulse_meter/udp_server_spec.rb +0 -36
- data/spec/pulse_meter/visualize/app_spec.rb +0 -27
- data/spec/pulse_meter/visualize/dsl/layout_spec.rb +0 -64
- data/spec/pulse_meter/visualize/dsl/page_spec.rb +0 -62
- data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +0 -30
- data/spec/pulse_meter/visualize/dsl/widget_spec.rb +0 -6
- data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +0 -22
- data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +0 -35
- data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +0 -36
- data/spec/pulse_meter/visualize/layout_spec.rb +0 -54
- data/spec/pulse_meter/visualize/page_spec.rb +0 -153
- data/spec/pulse_meter/visualize/sensor_spec.rb +0 -120
- data/spec/pulse_meter/visualize/series_extractor_spec.rb +0 -80
- data/spec/pulse_meter/visualize/widgets/area_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +0 -63
- data/spec/pulse_meter/visualize/widgets/line_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/pie_spec.rb +0 -73
- data/spec/pulse_meter/visualize/widgets/table_spec.rb +0 -6
- data/spec/pulse_meter/visualizer_spec.rb +0 -42
- data/spec/pulse_meter_spec.rb +0 -73
- data/spec/shared_examples/dsl_widget.rb +0 -106
- data/spec/shared_examples/timeline_sensor.rb +0 -439
- data/spec/shared_examples/timelined_subclass.rb +0 -23
- data/spec/shared_examples/widget.rb +0 -97
- data/spec/spec_helper.rb +0 -40
- data/spec/support/matchers.rb +0 -34
- data/spec/support/observered.rb +0 -40
@@ -1,32 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Average value over interval
|
5
|
-
class Average < Timeline
|
6
|
-
|
7
|
-
def aggregate_event(key, value)
|
8
|
-
command_aggregator.hincrby(key, :count, 1)
|
9
|
-
command_aggregator.hincrby(key, :sum, value)
|
10
|
-
end
|
11
|
-
|
12
|
-
def summarize(key)
|
13
|
-
count = redis.hget(key, :count)
|
14
|
-
sum = redis.hget(key, :sum)
|
15
|
-
if count && !count.empty?
|
16
|
-
sum.to_f / count.to_f
|
17
|
-
else
|
18
|
-
0
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def deflate(value)
|
25
|
-
value.to_f
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Counts events per interval
|
5
|
-
class Counter < Timeline
|
6
|
-
def aggregate_event(key, value)
|
7
|
-
command_aggregator.incrby(key, value.to_i)
|
8
|
-
end
|
9
|
-
|
10
|
-
def summarize(key)
|
11
|
-
redis.get(key)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def deflate(value)
|
17
|
-
value.to_i
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module PulseMeter
|
4
|
-
module Sensor
|
5
|
-
module Timelined
|
6
|
-
# Counts multiple types of events per interval.
|
7
|
-
# Good replacement for multiple counters to be visualized together
|
8
|
-
class HashedCounter < Timeline
|
9
|
-
def aggregate_event(key, data)
|
10
|
-
data.each_pair do |k, v|
|
11
|
-
command_aggregator.hincrby(key, k, v)
|
12
|
-
command_aggregator.hincrby(key, :total, v)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def summarize(key)
|
17
|
-
redis.
|
18
|
-
hgetall(key).
|
19
|
-
inject({}) {|h, (k, v)| h[k] = v.to_i; h}.
|
20
|
-
to_json
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def deflate(value)
|
26
|
-
JSON.parse(value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module PulseMeter
|
4
|
-
module Sensor
|
5
|
-
module Timelined
|
6
|
-
# Saves last registered values for multiple flags per interval.
|
7
|
-
# Good replacement for multiple indicators to be visualized together
|
8
|
-
class HashedIndicator < Timeline
|
9
|
-
def aggregate_event(key, data)
|
10
|
-
data.each_pair do |k, v|
|
11
|
-
command_aggregator.hset(key, k, v) if v.respond_to?(:to_f)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def summarize(key)
|
16
|
-
redis.
|
17
|
-
hgetall(key).
|
18
|
-
inject({}) {|h, (k, v)| h[k] = v.to_f; h}.
|
19
|
-
to_json
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def deflate(value)
|
25
|
-
JSON.parse(value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Saves last registered flag float value for each interval
|
5
|
-
class Indicator < Timeline
|
6
|
-
def aggregate_event(key, value)
|
7
|
-
command_aggregator.set(key, value.to_f)
|
8
|
-
end
|
9
|
-
|
10
|
-
def summarize(key)
|
11
|
-
redis.get(key)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def deflate(value)
|
17
|
-
value.to_f
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Calculates max value in interval
|
5
|
-
class Max < ZSetBased
|
6
|
-
|
7
|
-
def update(key)
|
8
|
-
command_aggregator.zremrangebyrank(key, 0, -2)
|
9
|
-
end
|
10
|
-
|
11
|
-
def calculate(key, _)
|
12
|
-
max_el = redis.zrange(key, -1, -1)[0]
|
13
|
-
redis.zscore(key, max_el)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Calculates min value in interval
|
5
|
-
class Min < ZSetBased
|
6
|
-
|
7
|
-
def update(key)
|
8
|
-
command_aggregator.zremrangebyrank(key, 1, -1)
|
9
|
-
end
|
10
|
-
|
11
|
-
def calculate(key, _)
|
12
|
-
min_el = redis.zrange(key, 0, 0)[0]
|
13
|
-
redis.zscore(key, min_el)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Calculates n'th percentile in interval
|
5
|
-
class MultiPercentile < ZSetBased
|
6
|
-
attr_reader :p_value
|
7
|
-
|
8
|
-
def initialize(name, options)
|
9
|
-
@p_value = assert_array!(options, :p, [])
|
10
|
-
@p_value.each {|p| assert_ranged_float!({:percentile => p}, :percentile, 0, 1)}
|
11
|
-
super(name, options)
|
12
|
-
end
|
13
|
-
|
14
|
-
def calculate(key, count)
|
15
|
-
count =
|
16
|
-
@p_value.each_with_object({}) { |p, acc|
|
17
|
-
position = p > 0 ? (p * count).round - 1 : 0
|
18
|
-
el = redis.zrange(key, position, position)[0]
|
19
|
-
acc[p] = redis.zscore(key, el)
|
20
|
-
}.to_json
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def deflate(value)
|
26
|
-
hash = JSON.parse(value)
|
27
|
-
hash.each {|p, v| hash[p] = v.to_f}
|
28
|
-
hash
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Calculates n'th percentile in interval
|
5
|
-
class Percentile < ZSetBased
|
6
|
-
attr_reader :p_value
|
7
|
-
|
8
|
-
def initialize(name, options)
|
9
|
-
@p_value = assert_ranged_float!(options, :p, 0, 1)
|
10
|
-
super(name, options)
|
11
|
-
end
|
12
|
-
|
13
|
-
def calculate(key, count)
|
14
|
-
position = @p_value > 0 ? (@p_value * count).round - 1 : 0
|
15
|
-
el = redis.zrange(key, position, position)[0]
|
16
|
-
redis.zscore(key, el)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Counts unique events per interval
|
5
|
-
class UniqCounter < Timeline
|
6
|
-
def aggregate_event(key, value)
|
7
|
-
command_aggregator.sadd(key, value)
|
8
|
-
end
|
9
|
-
|
10
|
-
def summarize(key)
|
11
|
-
redis.scard(key)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def deflate(value)
|
17
|
-
value.to_i
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module PulseMeter
|
2
|
-
module Sensor
|
3
|
-
module Timelined
|
4
|
-
# Calculates min value in interval
|
5
|
-
class ZSetBased < Timeline
|
6
|
-
|
7
|
-
def update(_)
|
8
|
-
end
|
9
|
-
|
10
|
-
def calculate(key)
|
11
|
-
0
|
12
|
-
end
|
13
|
-
|
14
|
-
def aggregate_event(key, value)
|
15
|
-
command_aggregator.zadd(key, value, "#{value}::#{uniqid}")
|
16
|
-
update(key)
|
17
|
-
end
|
18
|
-
|
19
|
-
def summarize(key)
|
20
|
-
count = redis.zcard(key)
|
21
|
-
if count > 0
|
22
|
-
calculate(key, count)
|
23
|
-
else
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def deflate(value)
|
31
|
-
value.to_f
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
# Static counter to count unique values
|
4
|
-
module PulseMeter
|
5
|
-
module Sensor
|
6
|
-
class UniqCounter < Counter
|
7
|
-
|
8
|
-
# Returs number of unique values ever sent to counter
|
9
|
-
# @return [Fixnum]
|
10
|
-
def value
|
11
|
-
redis.scard(value_key)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
# Processes event
|
17
|
-
# @param name [String] value to be counted
|
18
|
-
def process_event(name)
|
19
|
-
command_aggregator.sadd(value_key, name)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/pulse-meter/server.rb
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
require 'timeout'
|
3
|
-
|
4
|
-
module PulseMeter
|
5
|
-
class UDPServer
|
6
|
-
MAX_PACKET = 1024
|
7
|
-
|
8
|
-
def initialize(host, port)
|
9
|
-
@socket = UDPSocket.new
|
10
|
-
@socket.do_not_reverse_lookup = true
|
11
|
-
@socket.bind(host, port)
|
12
|
-
end
|
13
|
-
|
14
|
-
def start(max_packets = nil)
|
15
|
-
while true do
|
16
|
-
if max_packets
|
17
|
-
break if max_packets <= 0
|
18
|
-
max_packets -= 1
|
19
|
-
end
|
20
|
-
process_packet
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def process_packet
|
27
|
-
raw_data, _ = @socket.recvfrom(MAX_PACKET)
|
28
|
-
data = parse_data(raw_data)
|
29
|
-
PulseMeter.redis.multi do
|
30
|
-
data.each do |command|
|
31
|
-
PulseMeter.redis.send(*command)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
rescue StandardError => e
|
35
|
-
PulseMeter.error "Error processing packet: #{e}"
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_data(data)
|
39
|
-
JSON.parse(data)
|
40
|
-
rescue
|
41
|
-
PulseMeter.error "Bad redis data: #{data.inspect}"
|
42
|
-
[]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/pulse-meter/version.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'gon-sinatra'
|
2
|
-
require 'haml'
|
3
|
-
require 'sinatra/base'
|
4
|
-
require 'sinatra/partial'
|
5
|
-
|
6
|
-
module PulseMeter
|
7
|
-
module Visualize
|
8
|
-
class App < Sinatra::Base
|
9
|
-
include PulseMeter::Mixins::Utils
|
10
|
-
register Gon::Sinatra
|
11
|
-
register Sinatra::Partial
|
12
|
-
|
13
|
-
set :partial_template_engine, :haml
|
14
|
-
|
15
|
-
def initialize(layout)
|
16
|
-
@layout = layout
|
17
|
-
super()
|
18
|
-
end
|
19
|
-
|
20
|
-
configure :production, :development do
|
21
|
-
enable :logging
|
22
|
-
end
|
23
|
-
|
24
|
-
get '/' do
|
25
|
-
@title = @layout.title
|
26
|
-
gon.pageInfos = camelize_keys(@layout.page_infos)
|
27
|
-
gon.options = camelize_keys(@layout.options)
|
28
|
-
haml :main
|
29
|
-
end
|
30
|
-
|
31
|
-
get '/pages/:id/widgets' do
|
32
|
-
id = params[:id].to_i
|
33
|
-
|
34
|
-
content_type :json
|
35
|
-
camelize_keys(@layout.widgets(id - 1)).to_json
|
36
|
-
end
|
37
|
-
|
38
|
-
get '/pages/:page_id/widgets/:id' do
|
39
|
-
page_id = params[:page_id].to_i
|
40
|
-
id = params[:id].to_i
|
41
|
-
timespan = params[:timespan].to_i
|
42
|
-
start_time = params[:startTime].to_i
|
43
|
-
end_time = params[:endTime].to_i
|
44
|
-
|
45
|
-
content_type :json
|
46
|
-
camelize_keys(
|
47
|
-
@layout.widget(
|
48
|
-
page_id - 1,
|
49
|
-
id - 1,
|
50
|
-
timespan: timespan,
|
51
|
-
start_time: start_time,
|
52
|
-
end_time: end_time
|
53
|
-
)
|
54
|
-
).to_json
|
55
|
-
end
|
56
|
-
|
57
|
-
get '/sensors' do
|
58
|
-
content_type :json
|
59
|
-
camelize_keys(@layout.sensor_list).to_json
|
60
|
-
end
|
61
|
-
|
62
|
-
get '/dynamic_widget' do
|
63
|
-
start_time = params[:startTime].to_i
|
64
|
-
end_time = params[:endTime].to_i
|
65
|
-
timespan = params[:timespan].to_i
|
66
|
-
|
67
|
-
content_type :json
|
68
|
-
camelize_keys(@layout.dynamic_widget(
|
69
|
-
timespan: timespan,
|
70
|
-
start_time: start_time,
|
71
|
-
end_time: end_time,
|
72
|
-
sensors: params[:sensor],
|
73
|
-
type: params[:type])
|
74
|
-
).to_json
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|