focuslight 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.env +13 -0
  3. data/.gitignore +21 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +21 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/Procfile +3 -0
  9. data/Procfile-gem +3 -0
  10. data/README.md +162 -0
  11. data/Rakefile +37 -0
  12. data/bin/focuslight +7 -0
  13. data/config.ru +6 -0
  14. data/focuslight.gemspec +41 -0
  15. data/lib/focuslight.rb +6 -0
  16. data/lib/focuslight/cli.rb +56 -0
  17. data/lib/focuslight/config.rb +27 -0
  18. data/lib/focuslight/data.rb +258 -0
  19. data/lib/focuslight/graph.rb +240 -0
  20. data/lib/focuslight/init.rb +13 -0
  21. data/lib/focuslight/logger.rb +89 -0
  22. data/lib/focuslight/rrd.rb +393 -0
  23. data/lib/focuslight/validator.rb +220 -0
  24. data/lib/focuslight/version.rb +3 -0
  25. data/lib/focuslight/web.rb +614 -0
  26. data/lib/focuslight/worker.rb +97 -0
  27. data/public/css/bootstrap.min.css +7 -0
  28. data/public/favicon.ico +0 -0
  29. data/public/fonts/glyphicons-halflings-regular.eot +0 -0
  30. data/public/fonts/glyphicons-halflings-regular.svg +229 -0
  31. data/public/fonts/glyphicons-halflings-regular.ttf +0 -0
  32. data/public/fonts/glyphicons-halflings-regular.woff +0 -0
  33. data/public/js/bootstrap.min.js +7 -0
  34. data/public/js/jquery-1.10.2.min.js +6 -0
  35. data/public/js/jquery-1.10.2.min.map +0 -0
  36. data/public/js/jquery.storageapi.min.js +2 -0
  37. data/public/js/site.js +214 -0
  38. data/spec/spec_helper.rb +3 -0
  39. data/spec/syntax_spec.rb +9 -0
  40. data/spec/validator_predefined_rules_spec.rb +177 -0
  41. data/spec/validator_result_spec.rb +27 -0
  42. data/spec/validator_rule_spec.rb +68 -0
  43. data/spec/validator_spec.rb +121 -0
  44. data/view/add_complex.erb +143 -0
  45. data/view/base.erb +200 -0
  46. data/view/docs.erb +125 -0
  47. data/view/edit.erb +102 -0
  48. data/view/edit_complex.erb +158 -0
  49. data/view/index.erb +19 -0
  50. data/view/list.erb +22 -0
  51. data/view/view.erb +42 -0
  52. data/view/view_graph.erb +16 -0
  53. metadata +345 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fbeba2724566d237bb40f671a73cdb4d65af7207
4
+ data.tar.gz: 6b27bc30fa0a0b60e604aa8dc5d306a1adb5e0c4
5
+ SHA512:
6
+ metadata.gz: c9de2d208beecf0709727c1dd03c0d89455dd839fe2432288558367579d98fdb42950ead758e241725b39899e763ef0189271be3abefdecbc213db091cce7969
7
+ data.tar.gz: 4eeea83871b409b5788b89e24d71e2c8fb57ada42c7012779b032929efcebc958bd64d33544ce8542a5e3b4cca33fd827974bc0a44869f18386aabdc8b4566c7
data/.env ADDED
@@ -0,0 +1,13 @@
1
+ DATADIR=./data
2
+ PORT=5125
3
+ HOST=0.0.0.0
4
+ # FRONT_PROXY
5
+ # ALLOW_FROM
6
+ # 1MIN_METRICS=n
7
+ FLOAT_SUPPORT=n # y
8
+ DBURL=sqlite://data/gforecast.db
9
+ # DBURL=mysql2://root:@localhost/focuslight
10
+ # RRDCACHED=n
11
+ # MOUNT=/
12
+ LOG_PATH=log/application.log
13
+ LOG_LEVEL=warn
data/.gitignore ADDED
@@ -0,0 +1,21 @@
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
+ data/
19
+ .ruby-version
20
+ log/
21
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.0
4
+ gemfile:
5
+ - Gemfile
6
+ before_install:
7
+ - sudo apt-get install rrdtool librrd-dev
8
+ before_script:
9
+ - bundle exec rake init
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # 0.1.1 (2014/02/27)
2
+
3
+ Enhancements:
4
+
5
+ * Use sequel database engine #17 and Support mysql #20 (thanks to koichiro)
6
+ * Remove subtract feature and improve performance #19
7
+ * Logger support #22
8
+ * Gemify focuslight #25 (thanks to koichiro)
9
+
10
+ Fixes:
11
+
12
+ * Fix Procfile name #4
13
+ * Fix color update #6 (thanks to eagletmt)
14
+ * Prepare datadir by mkdir_p #7 (thanks to eagletmt)
15
+ * Fix hash key #9 (thanks to u-ichi)
16
+ * Fix graph_id typo #10 (thanks to u-ichi)
17
+ * Fix JSON API #11 #12 #13 #14 #15 #16
18
+
19
+ # 0.1.0
20
+
21
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in focuslight.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TAGOMORI Satoshi
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
+ web: bundle exec unicorn -E production -p $PORT -o $HOST
2
+ worker1: bundle exec rake longer
3
+ worker2: bundle exec rake shorter
data/Procfile-gem ADDED
@@ -0,0 +1,3 @@
1
+ web: unicorn -E production -p $PORT -o $HOST
2
+ worker1: rake longer
3
+ worker2: rake shorter
data/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # Focuslight
2
+
3
+ [![Build Status](https://travis-ci.org/focuslight/focuslight.png?branch=master)](https://travis-ci.org/focuslight/focuslight)
4
+
5
+ Focuslight is a lightning Fast Graphing/Visualization tool, built on RRDTool. It is a Ruby clone of [GrowthForecast](http://kazeburo.github.io/GrowthForecast/).
6
+
7
+ Focuslight is compatible with:
8
+ * stored data files
9
+ * database (sqlite) and graphs (rrdtool)
10
+ * almost all HTTP API requests, except for:
11
+ * `export` support
12
+ * almost all of features, except for:
13
+ * `subtract` support (`gmode`, `stype`, `sllimit`, `sulimit` parameters)
14
+
15
+ ## Prerequisites
16
+
17
+ RRDTool and its dependencies must be installed before installing Focuslight.
18
+
19
+ * RHEL/CentOS 6.x
20
+ * Add `epel` repository, then `sudo yum install rrdtool rrdtool-devel`
21
+ * Ubuntu
22
+ * `sudo apt-get install rrdtool librrd-dev`
23
+ * OSX
24
+ * `brew install rrdtool`
25
+
26
+ ## Installation
27
+
28
+ Install focuslight with Ruby 2.0 or later. Execute after installation.
29
+
30
+ ### Using gem package
31
+
32
+ Four easy steps installation with gem.
33
+
34
+ 1. `gem install focuslight`
35
+ 2. `focuslight new` # creates focuslight resource in `pwd`/focuslight
36
+ 3. `focuslight init` # creates database scheme
37
+ 4. `focuslight start`
38
+
39
+ Then see `http://localhost:5125/`
40
+
41
+ ### Using SQLite:
42
+
43
+ 1. clone this repository
44
+ 1. `cd focuslight`
45
+ 1. install dependencies: `bundle install`
46
+ 1. initialize database: `bundle exec rake init`
47
+ 1. execute: `bundle exec foreman start`
48
+
49
+ Then see `http://localhost:5125/`
50
+
51
+ ### Using MySQL:
52
+
53
+ You need to change DBURL parameter on .env file to `mysql2` version.
54
+ You may also configure the database name, the user name, and the password. See the Configuration section.
55
+
56
+ Then, create the database and assign permissions to the user as
57
+
58
+ ```
59
+ mysql> CREATE DATABASE focuslight;
60
+ mysql> GRANT CREATE, ALTER, DELETE, INSERT, UPDATE, SELECT \\
61
+ ON focuslight.* TO 'user'\@'localhost' IDENTIFIED BY password;
62
+ ```
63
+
64
+ Then, do the same thing with SQLite case.
65
+
66
+ ## Configuration
67
+
68
+ To configure Focuslight, edit the `.env` file in the project root directory.
69
+
70
+ The default configuration is as follows:
71
+
72
+ ```
73
+ DATADIR=./data
74
+ PORT=5125
75
+ HOST=0.0.0.0
76
+ # FRONT_PROXY
77
+ # ALLOW_FROM
78
+ # 1MIN_METRICS=n
79
+ FLOAT_SUPPORT=n # y
80
+ DBURL=sqlite://data/gforecast.db
81
+ # DBURL=mysql2://root:@localhost/focuslight
82
+ # RRDCACHED=n
83
+ # MOUNT=/
84
+ LOG_PATH=log/application.log
85
+ LOG_LEVEL=warn
86
+ ```
87
+
88
+ ## Switch from GrowthForecast
89
+
90
+ 1. Copy GrowthForecast's `datadir` directory (and its contents) to `./data` (or where you specified)
91
+ 1. Execute Focuslight
92
+
93
+ ## TODO
94
+
95
+ * Merge GrowthForecast's commits after Jan 09, 2014
96
+ * api endpoint link label
97
+ * RRDCached support
98
+ * Front proxies and source address restrictions
99
+ * HTTP API mount point support
100
+ * Daemonize support
101
+ * Add tests, and tests, and more tests
102
+
103
+ ## Imcompatible Features
104
+
105
+ Focuslight has following incompatibilitie with GrowthForecast as specifications.
106
+
107
+ ### Subtract
108
+
109
+ [GrowthForecast](http://kazeburo.github.io/GrowthForecast/index.html) has subtract graph support (gmode=subtract),
110
+ but focuslight does not have it because subtract graphs can be created using mode=derive like:
111
+
112
+ ```
113
+ curl -d "number=10&mode=derive" http://localhost:5125/api/service/section/graph
114
+ ```
115
+
116
+ As a demo, you may run following shell codes.
117
+ The number is incremental, but derive graph shows you the difference as a graph, which results in 1 in this demo.
118
+
119
+ ```
120
+ number=1
121
+ while true; do
122
+ curl -d "number=${number}&mode=derive" http://localhost:5125/api/service/section/graph
123
+ number=$((number+1))
124
+ sleep 60
125
+ done
126
+ ```
127
+
128
+ In addition, because focuslight does not support subtract graphs, `gmode`, `stype`, `sllimit`, and `sulimit`
129
+ parameters on HTTP APIs are not available. In the case of POST (create, edit), they are ignored.
130
+ In the case of GET, they are not returned.
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create new Pull Request
139
+
140
+ ## License
141
+
142
+ The MIT License (MIT)
143
+
144
+ Copyright (c) 2014- tagomoris
145
+
146
+ Permission is hereby granted, free of charge, to any person obtaining a copy
147
+ of this software and associated documentation files (the "Software"), to deal
148
+ in the Software without restriction, including without limitation the rights
149
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
150
+ copies of the Software, and to permit persons to whom the Software is
151
+ furnished to do so, subject to the following conditions:
152
+
153
+ The above copyright notice and this permission notice shall be included in
154
+ all copies or substantial portions of the Software.
155
+
156
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
158
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
159
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
160
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
161
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
162
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-c", "-f progress"] # '--format specdoc'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ lib = File.expand_path('../lib', __FILE__)
10
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
11
+ require 'dotenv/tasks'
12
+ require "focuslight/worker"
13
+
14
+ task :init => :dotenv do
15
+ require "focuslight/init"
16
+ Focuslight::Init.run
17
+ end
18
+
19
+ task :console => :dotenv do
20
+ require "focuslight/init"
21
+ require 'irb'
22
+ # require 'irb/completion'
23
+ ARGV.clear
24
+ IRB.start
25
+ end
26
+ task :c => :console
27
+
28
+ task :longer => :dotenv do
29
+ Focuslight::Worker.run(interval: 300, target: :normal)
30
+ end
31
+
32
+ task :shorter => :dotenv do
33
+ Focuslight::Worker.run(interval: 60, target: :short)
34
+ end
35
+
36
+ task :test => :spec
37
+ task :default => :spec
data/bin/focuslight ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "focuslight/cli"
6
+
7
+ Focuslight::CLI.start
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ require "rubygems"
2
+ require "sinatra"
3
+
4
+ require File.expand_path '../lib/focuslight/web.rb', __FILE__
5
+
6
+ run Focuslight::Web
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'focuslight/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "focuslight"
8
+ spec.version = Focuslight::VERSION
9
+ spec.authors = ["TAGOMORI Satoshi", "Naotoshi Seo", "Shota Fukumori (sora_h)"]
10
+ spec.email = ["tagomoris@gmail.com", "sonots@gmail.com", "her@sorah.jp"]
11
+ spec.description = %q{Ruby port of GrowthForecast}
12
+ spec.summary = %q{Lightning Fast Graphing/Visualization}
13
+ spec.homepage = "https://github.com/tagomoris/focuslight"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "pry-nav"
25
+
26
+ spec.add_runtime_dependency "rake" #TODO: daemon execution without rake
27
+ spec.add_runtime_dependency "dotenv"
28
+ spec.add_runtime_dependency "foreman"
29
+ spec.add_runtime_dependency "thor"
30
+
31
+ spec.add_runtime_dependency "sinatra"
32
+ spec.add_runtime_dependency "sinatra-contrib"
33
+ spec.add_runtime_dependency "erubis"
34
+ spec.add_runtime_dependency "unicorn"
35
+
36
+ spec.add_runtime_dependency "sequel"
37
+ spec.add_runtime_dependency "sqlite3"
38
+ spec.add_runtime_dependency "mysql2"
39
+ spec.add_runtime_dependency "librrd"
40
+ spec.add_runtime_dependency "rrd-ffi"
41
+ end
data/lib/focuslight.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+ require "focuslight/version"
4
+
5
+ module Focuslight
6
+ end
@@ -0,0 +1,56 @@
1
+ require "fileutils"
2
+ require "dotenv"
3
+ require "thor"
4
+
5
+ require "focuslight"
6
+
7
+ class Focuslight::CLI < Thor
8
+ BASE_DIR = File.join(Dir.pwd, "focuslight")
9
+ DATA_DIR = File.join(BASE_DIR, "data")
10
+ DBURL = "sqlite://#{File.join(DATA_DIR, "gforecast.db")}"
11
+ LOG_DIR = File.join(BASE_DIR, "log")
12
+ LOG_FILE = File.join(LOG_DIR, "application.log")
13
+ ENV_FILE = File.join(BASE_DIR, ".env")
14
+
15
+ DEFAULT_DOTENV =<<-EOS
16
+ DATADIR=#{DATA_DIR}
17
+ PORT=5125
18
+ HOST=0.0.0.0
19
+ # FRONT_PROXY
20
+ # ALLOW_FROM
21
+ # 1MIN_METRICS=n
22
+ FLOAT_SUPPORT=n # y
23
+ DBURL=#{DBURL}
24
+ # DBURL=mysql2://root:@localhost/focuslight
25
+ # RRDCACHED=n
26
+ # MOUNT=/
27
+ LOG_PATH=#{LOG_FILE}
28
+ LOG_LEVEL=warn
29
+ EOS
30
+
31
+ default_command :start
32
+
33
+ desc "new", "Creating focuslight resource directory"
34
+ def new
35
+ FileUtils.mkdir_p(LOG_DIR)
36
+ File.write ENV_FILE, DEFAULT_DOTENV
37
+ end
38
+
39
+ desc "init", "Creating database schema"
40
+ def init
41
+ raise "Run `focuslight new` first" unless File.exist? ENV_FILE
42
+ Dotenv.load ENV_FILE
43
+ require "focuslight/init"
44
+ Focuslight::Init.run
45
+ end
46
+
47
+ desc "start", "Sartup focuslight server"
48
+ def start
49
+ raise "Run `focuslight new` first" unless File.exist? ENV_FILE
50
+
51
+ Dotenv.load ENV_FILE
52
+ require "foreman/cli"
53
+ procfile = File.expand_path("../../../Procfile-gem", __FILE__)
54
+ Foreman::CLI.new.invoke(:start, [], procfile: procfile)
55
+ end
56
+ end