pulse_meter_visualizer 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +19 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +22 -0
  8. data/Procfile +3 -0
  9. data/README.md +40 -0
  10. data/Rakefile +72 -0
  11. data/examples/basic.ru +145 -0
  12. data/examples/basic_sensor_data.rb +96 -0
  13. data/lib/pulse_meter/visualize/app.rb +78 -0
  14. data/lib/pulse_meter/visualize/base.rb +15 -0
  15. data/lib/pulse_meter/visualize/coffee/application.coffee +40 -0
  16. data/lib/pulse_meter/visualize/coffee/collections/page_info_list.coffee +17 -0
  17. data/lib/pulse_meter/visualize/coffee/collections/sensor_info_list.coffee +4 -0
  18. data/lib/pulse_meter/visualize/coffee/collections/widget_list.coffee +14 -0
  19. data/lib/pulse_meter/visualize/coffee/extensions.coffee +26 -0
  20. data/lib/pulse_meter/visualize/coffee/models/dinamic_widget.coffee +34 -0
  21. data/lib/pulse_meter/visualize/coffee/models/page_info.coffee +2 -0
  22. data/lib/pulse_meter/visualize/coffee/models/sensor_info.coffee +2 -0
  23. data/lib/pulse_meter/visualize/coffee/models/widget.coffee +54 -0
  24. data/lib/pulse_meter/visualize/coffee/presenters/area.coffee +2 -0
  25. data/lib/pulse_meter/visualize/coffee/presenters/gauge.coffee +11 -0
  26. data/lib/pulse_meter/visualize/coffee/presenters/line.coffee +2 -0
  27. data/lib/pulse_meter/visualize/coffee/presenters/pie.coffee +20 -0
  28. data/lib/pulse_meter/visualize/coffee/presenters/series.coffee +44 -0
  29. data/lib/pulse_meter/visualize/coffee/presenters/table.coffee +10 -0
  30. data/lib/pulse_meter/visualize/coffee/presenters/timeline.coffee +13 -0
  31. data/lib/pulse_meter/visualize/coffee/presenters/widget.coffee +65 -0
  32. data/lib/pulse_meter/visualize/coffee/router.coffee +21 -0
  33. data/lib/pulse_meter/visualize/coffee/views/dynamic_chart.coffee +91 -0
  34. data/lib/pulse_meter/visualize/coffee/views/dynamic_widget.coffee +58 -0
  35. data/lib/pulse_meter/visualize/coffee/views/page_title.coffee +17 -0
  36. data/lib/pulse_meter/visualize/coffee/views/page_titles.coffee +15 -0
  37. data/lib/pulse_meter/visualize/coffee/views/sensor_info_list.coffee +19 -0
  38. data/lib/pulse_meter/visualize/coffee/views/widget.coffee +99 -0
  39. data/lib/pulse_meter/visualize/coffee/views/widget_chart.coffee +13 -0
  40. data/lib/pulse_meter/visualize/coffee/views/widget_list.coffee +15 -0
  41. data/lib/pulse_meter/visualize/dsl/base.rb +131 -0
  42. data/lib/pulse_meter/visualize/dsl/errors.rb +40 -0
  43. data/lib/pulse_meter/visualize/dsl/layout.rb +27 -0
  44. data/lib/pulse_meter/visualize/dsl/page.rb +33 -0
  45. data/lib/pulse_meter/visualize/dsl/sensor.rb +20 -0
  46. data/lib/pulse_meter/visualize/dsl/widget.rb +37 -0
  47. data/lib/pulse_meter/visualize/dsl/widgets/area.rb +20 -0
  48. data/lib/pulse_meter/visualize/dsl/widgets/gauge.rb +12 -0
  49. data/lib/pulse_meter/visualize/dsl/widgets/line.rb +21 -0
  50. data/lib/pulse_meter/visualize/dsl/widgets/pie.rb +16 -0
  51. data/lib/pulse_meter/visualize/dsl/widgets/table.rb +19 -0
  52. data/lib/pulse_meter/visualize/layout.rb +79 -0
  53. data/lib/pulse_meter/visualize/page.rb +25 -0
  54. data/lib/pulse_meter/visualize/public/css/application.css +56 -0
  55. data/lib/pulse_meter/visualize/public/css/bootstrap.css +4883 -0
  56. data/lib/pulse_meter/visualize/public/css/bootstrap.min.css +729 -0
  57. data/lib/pulse_meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  58. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  59. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  60. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  61. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  62. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  63. data/lib/pulse_meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  64. data/lib/pulse_meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  65. data/lib/pulse_meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
  66. data/lib/pulse_meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
  67. data/lib/pulse_meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
  68. data/lib/pulse_meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
  69. data/lib/pulse_meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  70. data/lib/pulse_meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
  71. data/lib/pulse_meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +1320 -0
  72. data/lib/pulse_meter/visualize/public/favicon.ico +208 -0
  73. data/lib/pulse_meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
  74. data/lib/pulse_meter/visualize/public/img/glyphicons-halflings.png +0 -0
  75. data/lib/pulse_meter/visualize/public/js/application.js +973 -0
  76. data/lib/pulse_meter/visualize/public/js/backbone-min.js +38 -0
  77. data/lib/pulse_meter/visualize/public/js/bootstrap.js +1835 -0
  78. data/lib/pulse_meter/visualize/public/js/jquery-1.7.2.min.js +4 -0
  79. data/lib/pulse_meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +791 -0
  80. data/lib/pulse_meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +21 -0
  81. data/lib/pulse_meter/visualize/public/js/jquery-ui-timepicker-addon.js +1687 -0
  82. data/lib/pulse_meter/visualize/public/js/json2.js +487 -0
  83. data/lib/pulse_meter/visualize/public/js/underscore-min.js +32 -0
  84. data/lib/pulse_meter/visualize/sensor.rb +63 -0
  85. data/lib/pulse_meter/visualize/series_extractor.rb +107 -0
  86. data/lib/pulse_meter/visualize/views/main.haml +30 -0
  87. data/lib/pulse_meter/visualize/views/sensors.haml +76 -0
  88. data/lib/pulse_meter/visualize/views/widgets/area.haml +53 -0
  89. data/lib/pulse_meter/visualize/views/widgets/extend_options.haml +11 -0
  90. data/lib/pulse_meter/visualize/views/widgets/gauge.haml +13 -0
  91. data/lib/pulse_meter/visualize/views/widgets/line.haml +54 -0
  92. data/lib/pulse_meter/visualize/views/widgets/pie.haml +13 -0
  93. data/lib/pulse_meter/visualize/views/widgets/table.haml +45 -0
  94. data/lib/pulse_meter/visualize/widget.rb +38 -0
  95. data/lib/pulse_meter/visualize/widgets/gauge.rb +47 -0
  96. data/lib/pulse_meter/visualize/widgets/pie.rb +36 -0
  97. data/lib/pulse_meter/visualize/widgets/timeline.rb +114 -0
  98. data/lib/pulse_meter/visualizer.rb +38 -0
  99. data/lib/pulse_meter_visualizer.rb +2 -0
  100. data/pulse_meter_visualizer.gemspec +41 -0
  101. data/spec/pulse_meter/visualize/app_spec.rb +27 -0
  102. data/spec/pulse_meter/visualize/dsl/layout_spec.rb +64 -0
  103. data/spec/pulse_meter/visualize/dsl/page_spec.rb +62 -0
  104. data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +30 -0
  105. data/spec/pulse_meter/visualize/dsl/widget_spec.rb +6 -0
  106. data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +44 -0
  107. data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +22 -0
  108. data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +44 -0
  109. data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +35 -0
  110. data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +36 -0
  111. data/spec/pulse_meter/visualize/layout_spec.rb +54 -0
  112. data/spec/pulse_meter/visualize/page_spec.rb +153 -0
  113. data/spec/pulse_meter/visualize/sensor_spec.rb +120 -0
  114. data/spec/pulse_meter/visualize/series_extractor_spec.rb +80 -0
  115. data/spec/pulse_meter/visualize/widgets/area_spec.rb +6 -0
  116. data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +63 -0
  117. data/spec/pulse_meter/visualize/widgets/line_spec.rb +6 -0
  118. data/spec/pulse_meter/visualize/widgets/pie_spec.rb +73 -0
  119. data/spec/pulse_meter/visualize/widgets/table_spec.rb +6 -0
  120. data/spec/pulse_meter/visualizer_spec.rb +42 -0
  121. data/spec/shared_examples/dsl_widget.rb +106 -0
  122. data/spec/shared_examples/widget.rb +97 -0
  123. data/spec/spec_helper.rb +36 -0
  124. metadata +518 -0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.sw?
19
+ /.idea
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p125
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -fd
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ branches:
6
+ only:
7
+ - master
8
+ - develop
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pulse-meter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ilya Averyanov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Procfile ADDED
@@ -0,0 +1,3 @@
1
+ watch_coffee: bundle exec rake coffee:watch
2
+ web_sample: bundle exec rackup examples/basic.ru
3
+ sensor_sample: bundle exec ruby examples/basic_sensor_data.rb
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ [![Gem Version](https://badge.fury.io/rb/pulse_meter_visualizer.png)](http://badge.fury.io/rb/pulse_meter_visualizer)
2
+ [![Build Status](https://secure.travis-ci.org/savonarola/pulse_meter_visualizer.png)](http://travis-ci.org/savonarola/pulse_meter_visualizer)
3
+ [![Dependency Status](https://gemnasium.com/savonarola/pulse_meter_visualizer.png)](https://gemnasium.com/savonarola/pulse_meter_visualizer)
4
+ [![Code Climate](https://codeclimate.com/github/savonarola/pulse_meter_visualizer.png)](https://codeclimate.com/github/savonarola/pulse_meter_visualizer)
5
+
6
+ # PulseMeter
7
+
8
+ PulseMeter is a gem for fast and convenient realtime aggregating of software internal stats through Redis.
9
+
10
+ ## Live Demo
11
+
12
+ A small live demo for [pulse-meter](https://github.com/savonarola/pulse-meter) gem is located here: [rubybox.ru](http://rubybox.ru), its source code can be found here: [https://github.com/savonarola/pulse-meter-demo](https://github.com/savonarola/pulse-meter-demo)
13
+
14
+ ## Features
15
+
16
+ The gem contains customizable web interface for [pulse-meter](https://github.com/savonarola/pulse-meter) gem.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'pulse_meter_visualizer'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install pulse_meter_visualizer
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'coffee-script'
4
+ require 'listen'
5
+ require 'rspec/core/rake_task'
6
+ require 'sprockets'
7
+ require 'tilt'
8
+ require 'yard'
9
+ require 'yard/rake/yardoc_task'
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ YARD::Rake::YardocTask.new(:yard)
14
+
15
+ ROOT = File.dirname(__FILE__)
16
+
17
+ task :default => :spec
18
+
19
+ namespace :coffee do
20
+ COFFEE_PATH = "#{ROOT}/lib/pulse_meter/visualize/coffee"
21
+
22
+ def compile_js
23
+ Tilt::CoffeeScriptTemplate.default_bare = true
24
+ env = Sprockets::Environment.new
25
+ env.append_path COFFEE_PATH
26
+ data = env['application.coffee']
27
+ open("#{ROOT}/lib/pulse_meter/visualize/public/js/application.js", "w").write(data)
28
+ puts "application.js compiled"
29
+ end
30
+
31
+ desc "Compile coffee to js"
32
+ task :compile do
33
+ compile_js
34
+ end
35
+
36
+ desc "Watch coffee files and recomplile them immediately"
37
+ task :watch do
38
+ Listen.to(COFFEE_PATH) do |modified, added, removed|
39
+ puts "Modified: #{modified}" unless modified.empty?
40
+ puts "Added: #{added}" unless added.empty?
41
+ puts "Removed: #{removed}" unless removed.empty?
42
+ puts "Recompiling..."
43
+ compile_js
44
+ end
45
+ end
46
+ end
47
+
48
+ namespace :yard do
49
+ desc "Open doc index in a browser"
50
+ task :open do
51
+ system 'open', "#{ROOT}/doc/index.html"
52
+ end
53
+ end
54
+
55
+ namespace :example do
56
+ desc "Run minimal example"
57
+ task :minimal do
58
+ chdir(ROOT) do
59
+ system "bundle"
60
+ system "cd examples/minimal && bundle exec foreman start"
61
+ end
62
+ end
63
+
64
+ desc "Run full example"
65
+ task :full do
66
+ chdir(ROOT) do
67
+ system "bundle"
68
+ system "cd examples/full && bundle exec foreman start"
69
+ end
70
+ end
71
+
72
+ end
data/examples/basic.ru ADDED
@@ -0,0 +1,145 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'pulse_meter_visualizer'
4
+
5
+ PulseMeter.redis = Redis.new
6
+
7
+ layout = PulseMeter::Visualizer.draw do |l|
8
+
9
+ l.title "WunderZoo Stats"
10
+
11
+ l.page "Counts" do |p|
12
+
13
+ p.line "Lama count" do |c|
14
+ c.sensor :lama_count, color: '#CC1155'
15
+ c.redraw_interval 5
16
+ c.values_label 'Count'
17
+ c.width 5
18
+ c.show_last_point true
19
+ c.timespan 1200
20
+ end
21
+
22
+ p.line "Lama count 1 min" do |c|
23
+ c.sensor :lama_count_1min, color: '#FA295C'
24
+ c.redraw_interval 5
25
+ c.values_label 'Count'
26
+ c.width 5
27
+ c.show_last_point true
28
+ c.timespan 1200
29
+ end
30
+
31
+ p.area "Rhino count", sensor: :rhino_count do |c|
32
+ c.redraw_interval 5
33
+ c.values_label 'Count'
34
+ c.width 5
35
+ c.show_last_point true
36
+ c.timespan 1200
37
+ end
38
+
39
+ p.line "Rhino & Lama & Goose count comparison" do |c|
40
+ c.redraw_interval 5
41
+ c.values_label 'Count'
42
+ c.width 5
43
+ c.show_last_point true
44
+ c.timespan 1200
45
+
46
+ c.sensor :rhino_count, color: '#AAAAAA'
47
+ c.sensor :lama_count, color: '#CC1155'
48
+ c.sensor :goose_count
49
+ end
50
+
51
+ p.pie "Rhino & Lama & Gooze count comparison" do |c|
52
+ c.redraw_interval 5
53
+ c.values_label 'Count'
54
+ c.width 5
55
+ c.show_last_point false
56
+ c.timespan 1200
57
+
58
+ c.sensor :rhino_count, color: '#AAAAAA'
59
+ c.sensor :lama_count, color: '#CC1155'
60
+ c.sensor :goose_count
61
+ end
62
+
63
+ p.gauge "CPU Usage" do |g|
64
+ g.redraw_interval 5
65
+ g.values_label '%'
66
+ g.width 5
67
+
68
+ g.red_from 90
69
+ g.red_to 100
70
+ g.yellow_from 75
71
+ g.yellow_to 90
72
+ g.minor_ticks 5
73
+ g.height 200
74
+
75
+ g.sensor :cpu
76
+ g.sensor :memory
77
+ g.sensor :temperature
78
+ end
79
+
80
+ p.table "Rhino & Lama & Goose count comparison" do |c|
81
+ c.redraw_interval 5
82
+ c.values_label 'Count'
83
+ c.width 10
84
+ c.show_last_point true
85
+ c.timespan 1200
86
+
87
+ c.sensor :rhino_count, color: '#AAAAAA'
88
+ c.sensor :lama_count, color: '#CC1155'
89
+ c.sensor :goose_count
90
+ end
91
+
92
+
93
+ end
94
+
95
+ l.page "Ages" do |p|
96
+
97
+ p.line "Lama average age", sensor: :lama_average_age do |c|
98
+ c.redraw_interval 5
99
+ c.values_label 'Age'
100
+ c.width 5
101
+ c.show_last_point true
102
+ c.timespan 1200
103
+ end
104
+
105
+ p.line "Rhino average age", sensor: :rhino_average_age do |c|
106
+ c.redraw_interval 5
107
+ c.values_label 'Age'
108
+ c.width 5
109
+ c.show_last_point true
110
+ c.timespan 1200
111
+ end
112
+
113
+ p.area "Rhino & Lama average age comparison" do |c|
114
+ c.redraw_interval 5
115
+ c.values_label 'Age'
116
+ c.width 5
117
+ c.show_last_point true
118
+ c.timespan 1200
119
+
120
+ c.sensor :lama_average_age
121
+ c.sensor :rhino_average_age
122
+ end
123
+
124
+ p.pie "Rhino & Lama average age comparison" do |c|
125
+ c.redraw_interval 5
126
+ c.values_label 'Age'
127
+ c.width 5
128
+ c.show_last_point false
129
+ c.timespan 1200
130
+
131
+ c.sensor :lama_average_age
132
+ c.sensor :rhino_average_age
133
+ end
134
+
135
+ p.gchart_options({
136
+ background_color: '#CCC'
137
+ })
138
+ end
139
+
140
+ l.gchart_options({
141
+ height: 300
142
+ })
143
+ end
144
+
145
+ run layout.to_app
@@ -0,0 +1,96 @@
1
+ $: << File.join(File.absolute_path(__FILE__), '..', 'lib')
2
+
3
+ require "pulse_meter_core"
4
+
5
+ PulseMeter.redis = Redis.new
6
+
7
+ cfg = PulseMeter::Sensor::Configuration.new(
8
+ lama_count: {
9
+ sensor_type:'timelined/counter',
10
+ args: {
11
+ annotation: 'Lama Count',
12
+ interval: 10,
13
+ ttl: 3600
14
+ }
15
+ },
16
+
17
+ lama_count_1min: {
18
+ sensor_type:'timelined/counter',
19
+ args: {
20
+ annotation: 'Lama Count (1 min)',
21
+ interval: 60,
22
+ ttl: 3600
23
+ }
24
+ },
25
+
26
+ lama_average_age: {
27
+ sensor_type:'timelined/average',
28
+ args: {
29
+ annotation: 'Lama Average Age',
30
+ interval: 20,
31
+ ttl: 3600
32
+ }
33
+ },
34
+
35
+ rhino_count: {
36
+ sensor_type:'timelined/counter',
37
+ args: {
38
+ annotation: 'Rhino Count',
39
+ interval: 10,
40
+ ttl: 3600
41
+ }
42
+ },
43
+
44
+ goose_count: {
45
+ sensor_type:'timelined/hashed_counter',
46
+ args: {
47
+ annotation: 'Goose Count',
48
+ interval: 10,
49
+ ttl: 3600
50
+ }
51
+ },
52
+
53
+ rhino_average_age: {
54
+ sensor_type:'timelined/average',
55
+ args: {
56
+ annotation: 'Rhino average age',
57
+ interval: 20,
58
+ ttl: 3600
59
+ }
60
+ },
61
+
62
+ sensor_without_annotation: {
63
+ sensor_type:'timelined/average',
64
+ args: {
65
+ interval: 20,
66
+ ttl: 3600
67
+ }
68
+ },
69
+
70
+ cpu: {sensor_type: 'indicator'},
71
+ memory: {sensor_type: 'indicator'},
72
+ temperature: {
73
+ sensor_type: 'hashed_indicator',
74
+ args: {
75
+ annotation: 'T'
76
+ }
77
+ }
78
+ )
79
+
80
+ while true
81
+ sleep(Random.rand)
82
+ STDERR.puts "tick"
83
+ cfg.lama_count(100000)
84
+ cfg.rhino_count(2)
85
+ cfg.lama_average_age(Random.rand(50))
86
+ cfg.rhino_average_age(Random.rand(100))
87
+
88
+ 10.times do
89
+ goose_n = Random.rand(4)
90
+ cfg.goose_count("g_#{goose_n}" => 1)
91
+ cfg.temperature("g_#{goose_n}" => Random.rand(50))
92
+ end
93
+
94
+ cfg.cpu(Random.rand(100))
95
+ cfg.memory(Random.rand(100))
96
+ end
@@ -0,0 +1,78 @@
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