snowman-io 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +4 -6
- data/bin/snowman +1 -1
- data/lib/config/mongoid.yml +5 -0
- data/lib/snowman-io.rb +62 -30
- data/lib/snowman-io/aggregate.rb +97 -0
- data/lib/snowman-io/api.rb +33 -65
- data/lib/snowman-io/api/agent.rb +27 -0
- data/lib/snowman-io/api/apps.rb +45 -0
- data/lib/snowman-io/api/auth_helpers.rb +76 -0
- data/lib/snowman-io/api/checks.rb +59 -0
- data/lib/snowman-io/api/extra/meteor.rb +45 -0
- data/lib/snowman-io/api/fridge.rb +14 -0
- data/lib/snowman-io/api/info.rb +30 -0
- data/lib/snowman-io/api/metrics.rb +115 -0
- data/lib/snowman-io/api/users.rb +231 -0
- data/lib/snowman-io/cli.rb +69 -0
- data/lib/snowman-io/launcher.rb +12 -11
- data/lib/snowman-io/loop/check_processor.rb +29 -0
- data/lib/snowman-io/loop/checks.rb +59 -0
- data/lib/snowman-io/loop/main.rb +43 -0
- data/lib/snowman-io/loop/ping.rb +25 -0
- data/lib/snowman-io/migration.rb +79 -0
- data/lib/snowman-io/models/aggregation.rb +15 -0
- data/lib/snowman-io/models/app.rb +61 -0
- data/lib/snowman-io/models/check.rb +48 -0
- data/lib/snowman-io/models/concerns/tokenable.rb +15 -0
- data/lib/snowman-io/models/data_point.rb +9 -0
- data/lib/snowman-io/models/deleted.rb +9 -0
- data/lib/snowman-io/models/following.rb +8 -0
- data/lib/snowman-io/models/metric.rb +36 -0
- data/lib/snowman-io/models/setting.rb +24 -0
- data/lib/snowman-io/models/user.rb +73 -0
- data/lib/snowman-io/options.rb +11 -3
- data/lib/snowman-io/report_mailer.rb +88 -0
- data/lib/snowman-io/reports.rb +16 -0
- data/lib/snowman-io/ui/AUTO_GENERATED_FOLDER +2 -0
- data/lib/snowman-io/ui/assets/ui-0e39dafcb798020fb855e325931c8451.css +1 -0
- data/lib/snowman-io/ui/assets/ui-d30809d0ae0a003d841fa95a352d624b.js +9 -0
- data/lib/snowman-io/ui/assets/vendor-7edfd1432c1bbd806306d5583c75b1fc.css +5 -0
- data/lib/snowman-io/ui/assets/vendor-c22e2ccc87c9bc7609b95939c308bc7f.js +24 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap-theme.css +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap-theme.css.map +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap-theme.min.css +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap.css +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap.css.map +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/css/bootstrap.min.css +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/fonts/glyphicons-halflings-regular.svg +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/js/bootstrap.js +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/js/bootstrap.min.js +0 -0
- data/lib/snowman-io/{api/public/bootstrap → ui/bootstrap-3.3.1}/js/npm.js +0 -0
- data/lib/snowman-io/ui/crossdomain.xml +15 -0
- data/lib/snowman-io/ui/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/snowman-io/ui/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/snowman-io/ui/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/snowman-io/ui/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/snowman-io/ui/index.html +175 -0
- data/lib/snowman-io/ui/robots.txt +2 -0
- data/lib/snowman-io/utils.rb +66 -0
- data/lib/snowman-io/version.rb +1 -1
- data/lib/snowman-io/views/layouts/custom.css +42 -0
- data/lib/snowman-io/views/layouts/main.html.erb +38 -0
- data/lib/snowman-io/views/layouts/styles.css +264 -0
- data/lib/snowman-io/views/layouts/transactional-email-templates-LICENSE +21 -0
- data/lib/snowman-io/views/report_mailer/check_triggered.html.erb +16 -0
- data/lib/snowman-io/views/report_mailer/checks/_human_last_value_limit.html.erb +2 -0
- data/lib/snowman-io/views/report_mailer/checks/_human_prev_day_datapoints_limit.html.erb +2 -0
- data/lib/snowman-io/views/report_mailer/daily_report.html.erb +40 -0
- data/lib/snowman-io/views/report_mailer/restore_password.html.erb +28 -0
- data/lib/snowman-io/views/report_mailer/send_invite.html.erb +32 -0
- data/lib/snowman-io/web.rb +28 -0
- data/lib/snowman-io/web_server.rb +107 -0
- data/snowman-io.gemspec +15 -5
- metadata +220 -49
- data/lib/snowman-io/api/public/README.md +0 -36
- data/lib/snowman-io/api/public/css/normalize.css +0 -406
- data/lib/snowman-io/api/public/css/style.css +0 -4
- data/lib/snowman-io/api/public/js/app.js +0 -13
- data/lib/snowman-io/api/public/js/libs/ember-1.8.1.js +0 -49740
- data/lib/snowman-io/api/public/js/libs/handlebars-v1.3.0.js +0 -2746
- data/lib/snowman-io/api/public/js/libs/jquery-1.10.2.js +0 -9789
- data/lib/snowman-io/api/public/tests/runner.css +0 -14
- data/lib/snowman-io/api/public/tests/runner.js +0 -13
- data/lib/snowman-io/api/public/tests/tests.js +0 -30
- data/lib/snowman-io/api/public/tests/vendor/qunit-1.12.0.css +0 -244
- data/lib/snowman-io/api/public/tests/vendor/qunit-1.12.0.js +0 -2212
- data/lib/snowman-io/api/views/index.erb +0 -26
- data/lib/snowman-io/api/views/layout.erb +0 -24
- data/lib/snowman-io/api/views/login.erb +0 -21
- data/lib/snowman-io/api/views/unpacking.erb +0 -21
- data/lib/snowman-io/check.rb +0 -49
- data/lib/snowman-io/check_result.rb +0 -15
- data/lib/snowman-io/checks/hosted_graphite.rb +0 -23
- data/lib/snowman-io/handler.rb +0 -27
- data/lib/snowman-io/notifiers/slack.rb +0 -76
- data/lib/snowman-io/processor.rb +0 -32
- data/lib/snowman-io/scheduler.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8591ccf2ab370cd2962171434bb77f454ebec94e
|
4
|
+
data.tar.gz: 5efbb7cf4889b13354864479cc5b32eece3b16bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 781a22f544cde6adf1108d0a56d8ac4b002a3cab6e07f9baeed197d76a50b2ef40b65c32f99c40f999a1530c3130a3aae5fac509f4e98a29f6de5a8e372b6fc4
|
7
|
+
data.tar.gz: f5b85766a6f5702f73baf8948279c861ce84a89caf858c7966465164c665b8d23910de0ae9ecc544a31df627ad83f03d05a383d781a5a9eeb468f1f9bce371e4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# SnowmanIO
|
2
2
|
|
3
|
-
|
3
|
+
Your personal assistent.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/snowman-io/snowman-io.svg)](https://travis-ci.org/snowman-io/snowman-io)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/snowman-io.svg)](http://badge.fury.io/rb/snowman-io) [![Build Status](https://travis-ci.org/snowman-io/snowman-io.svg)](https://travis-ci.org/snowman-io/snowman-io) [![Code Climate](https://codeclimate.com/github/snowman-io/snowman-io/badges/gpa.svg)](https://codeclimate.com/github/snowman-io/snowman-io) [![Coverage Status](https://coveralls.io/repos/snowman-io/snowman-io/badge.png)](https://coveralls.io/r/snowman-io/snowman-io)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/snowman-io/sample-app)
|
9
|
+
Please follow instructions on project site http://snowman.io.
|
12
10
|
|
13
11
|
## Authors
|
14
12
|
|
@@ -17,7 +15,7 @@ Press a button below to install your private Heroku SnowmanIO instance for free.
|
|
17
15
|
|
18
16
|
## Contributing
|
19
17
|
|
20
|
-
1. Fork it ( https://github.com/
|
18
|
+
1. Fork it ( https://github.com/snowman-io/snowman-io/fork )
|
21
19
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
22
20
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
23
21
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/snowman
CHANGED
data/lib/snowman-io.rb
CHANGED
@@ -1,46 +1,78 @@
|
|
1
1
|
require 'logger'
|
2
|
-
require 'redis'
|
3
2
|
require 'bcrypt'
|
4
3
|
require 'celluloid/autostart'
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'premailer'
|
6
|
+
require 'mongoid'
|
7
|
+
require 'active_support/core_ext/object/blank'
|
8
|
+
require 'active_support/core_ext/string/strip'
|
9
|
+
require 'active_support/core_ext/hash/slice'
|
10
|
+
require 'active_support/core_ext/hash/except'
|
11
|
+
require 'active_support/core_ext/date/calculations'
|
12
|
+
require 'active_support/core_ext/time/calculations'
|
13
|
+
require 'active_support/core_ext/numeric/time'
|
14
|
+
require 'active_support/core_ext/enumerable'
|
5
15
|
|
6
16
|
require "snowman-io/version"
|
17
|
+
require "snowman-io/utils"
|
18
|
+
require "snowman-io/web"
|
7
19
|
require "snowman-io/api"
|
8
20
|
require "snowman-io/options"
|
9
|
-
require "snowman-io/checks/hosted_graphite"
|
10
|
-
require "snowman-io/check"
|
11
|
-
require "snowman-io/check_result"
|
12
|
-
|
13
21
|
require "snowman-io/launcher"
|
22
|
+
require "snowman-io/cli"
|
23
|
+
require "snowman-io/web_server"
|
24
|
+
require "snowman-io/aggregate"
|
25
|
+
require "snowman-io/reports"
|
26
|
+
require "snowman-io/loop/ping"
|
27
|
+
require "snowman-io/loop/main"
|
28
|
+
require "snowman-io/loop/checks"
|
29
|
+
require "snowman-io/report_mailer"
|
30
|
+
require "snowman-io/migration"
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
require "snowman-io/models/concerns/tokenable"
|
33
|
+
require "snowman-io/models/user"
|
34
|
+
require "snowman-io/models/app"
|
35
|
+
require "snowman-io/models/metric"
|
36
|
+
require "snowman-io/models/check"
|
37
|
+
require "snowman-io/models/data_point"
|
38
|
+
require "snowman-io/models/aggregation"
|
39
|
+
require "snowman-io/models/setting"
|
40
|
+
require "snowman-io/models/deleted"
|
41
|
+
require "snowman-io/models/following"
|
24
42
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
ActionMailer::Base.raise_delivery_errors = true
|
44
|
+
ActionMailer::Base.view_paths = File.dirname(__FILE__) + "/snowman-io/views"
|
45
|
+
if ENV["DEV_MODE"].to_i == 1
|
46
|
+
Object.send(:remove_const, :Rails)
|
47
|
+
require "letter_opener"
|
48
|
+
ActionMailer::Base.add_delivery_method :letter_opener,
|
49
|
+
LetterOpener::DeliveryMethod,
|
50
|
+
:location => File.expand_path('../../tmp/letter_opener', __FILE__)
|
51
|
+
ActionMailer::Base.delivery_method = :letter_opener
|
52
|
+
else
|
53
|
+
ActionMailer::Base.delivery_method = :smtp
|
54
|
+
ActionMailer::Base.smtp_settings = {
|
55
|
+
:address => ENV["MAILGUN_SMTP_SERVER"],
|
56
|
+
:port => ENV["MAILGUN_SMTP_PORT"],
|
57
|
+
:authentication => :plain,
|
58
|
+
:user_name => ENV["MAILGUN_SMTP_LOGIN"],
|
59
|
+
:password => ENV["MAILGUN_SMTP_PASSWORD"],
|
60
|
+
:enable_starttls_auto => true
|
61
|
+
}
|
62
|
+
end
|
38
63
|
|
39
|
-
|
40
|
-
|
41
|
-
|
64
|
+
module SnowmanIO
|
65
|
+
BASE_URL_KEY = "base_url"
|
66
|
+
FORCE_SSL_KEY = "force_ssl"
|
67
|
+
NEXT_REPORT_DATE_KEY = "next_report_date"
|
42
68
|
|
43
69
|
def self.logger
|
44
70
|
@logger ||= Logger.new(STDERR)
|
45
71
|
end
|
72
|
+
|
73
|
+
def self.unpacked?
|
74
|
+
User.count > 0
|
75
|
+
end
|
46
76
|
end
|
77
|
+
|
78
|
+
Mongoid.load!(File.expand_path("../config/mongoid.yml", __FILE__), :production)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module SnowmanIO
|
2
|
+
module Aggregate
|
3
|
+
# Aggregate 5mins metrics
|
4
|
+
def self.metrics_aggregate_5min
|
5
|
+
Metric.all.each do |metric|
|
6
|
+
aggr = {}
|
7
|
+
|
8
|
+
# collect
|
9
|
+
metric.data_points.each do |point|
|
10
|
+
key = Utils.floor_5min(point.at)
|
11
|
+
aggr[key] ||= []
|
12
|
+
aggr[key] << point.value
|
13
|
+
end
|
14
|
+
|
15
|
+
# aggregrate
|
16
|
+
aggr.each do |at, values|
|
17
|
+
metric.aggregations.where(precision: "5min", at: at).first_or_create!.update_attributes!(
|
18
|
+
count: values.length,
|
19
|
+
min: values.min,
|
20
|
+
avg: Utils.avg(values),
|
21
|
+
up: Utils.up(values),
|
22
|
+
max: values.max,
|
23
|
+
sum: values.inject(&:+)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Aggregate hour metrics
|
30
|
+
def self.metrics_aggregate_hour
|
31
|
+
Metric.all.each do |metric|
|
32
|
+
out = {}
|
33
|
+
metric.aggregations.where(precision: "5min").each do |aggr|
|
34
|
+
key = aggr.at.beginning_of_hour
|
35
|
+
out[key] ||= {"count" => 0, "avg" => 0, "up" => 0, "sum" => 0}
|
36
|
+
out[key]["count"] += aggr["count"]
|
37
|
+
out[key]["min"] = aggr["min"] if !out[key]["min"] || out[key]["min"] > aggr["min"]
|
38
|
+
out[key]["avg"] += aggr["avg"]*aggr["count"]
|
39
|
+
out[key]["up"] += aggr["up"]*aggr["count"]
|
40
|
+
out[key]["max"] = aggr["max"] if !out[key]["max"] || out[key]["max"] < aggr["max"]
|
41
|
+
out[key]["sum"] += aggr["sum"]
|
42
|
+
end
|
43
|
+
|
44
|
+
# normalize
|
45
|
+
out.each do |__, chunk|
|
46
|
+
chunk["avg"] /= chunk["count"]
|
47
|
+
chunk["up"] /= chunk["count"]
|
48
|
+
end
|
49
|
+
|
50
|
+
# store
|
51
|
+
out.each do |at, chunk|
|
52
|
+
metric.aggregations.where(precision: "hour", at: at).first_or_create!.update_attributes!(chunk)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Aggregate daily metrics
|
58
|
+
def self.metrics_aggregate_daily
|
59
|
+
Metric.all.each do |metric|
|
60
|
+
out = {}
|
61
|
+
metric.aggregations.where(precision: "hour").each do |aggr|
|
62
|
+
key = aggr.at.beginning_of_day
|
63
|
+
out[key] ||= {"count" => 0, "avg" => 0, "up" => 0, "sum" => 0}
|
64
|
+
out[key]["count"] += aggr["count"]
|
65
|
+
out[key]["min"] = aggr["min"] if !out[key]["min"] || out[key]["min"] > aggr["min"]
|
66
|
+
out[key]["avg"] += aggr["avg"]*aggr["count"]
|
67
|
+
out[key]["up"] += aggr["up"]*aggr["count"]
|
68
|
+
out[key]["max"] = aggr["max"] if !out[key]["max"] || out[key]["max"] < aggr["max"]
|
69
|
+
out[key]["sum"] += aggr["sum"]
|
70
|
+
end
|
71
|
+
|
72
|
+
# normalize
|
73
|
+
out.each do |__, chunk|
|
74
|
+
chunk["avg"] /= chunk["count"]
|
75
|
+
chunk["up"] /= chunk["count"]
|
76
|
+
end
|
77
|
+
|
78
|
+
# store
|
79
|
+
out.each do |at, chunk|
|
80
|
+
metric.aggregations.where(precision: "daily", at: at).first_or_create!.update_attributes!(chunk)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# for meteor
|
85
|
+
App.all.each(&:touch)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Clean old records
|
89
|
+
def self.metrics_clean_old
|
90
|
+
now = Time.now
|
91
|
+
DataPoint.where(:at.lt => Utils.floor_5min(now - 6.minutes)).delete_all
|
92
|
+
SnowmanIO::Aggregation.where(precision: "5min", :at.lt => (now - 2.hours).beginning_of_hour).delete_all
|
93
|
+
SnowmanIO::Aggregation.where(precision: "hour", :at.lt => (now - 25.hours).beginning_of_day).delete_all
|
94
|
+
SnowmanIO::Aggregation.where(precision: "daily", :at.lt => (now - 365.days).beginning_of_day).delete_all
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/snowman-io/api.rb
CHANGED
@@ -1,75 +1,43 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'grape'
|
2
|
+
|
3
|
+
require 'snowman-io/api/extra/meteor'
|
4
|
+
require 'snowman-io/api/auth_helpers'
|
5
|
+
require 'snowman-io/api/users'
|
6
|
+
require 'snowman-io/api/apps'
|
7
|
+
require 'snowman-io/api/info'
|
8
|
+
require 'snowman-io/api/metrics'
|
9
|
+
require 'snowman-io/api/checks'
|
10
|
+
require 'snowman-io/api/agent'
|
11
|
+
require 'snowman-io/api/fridge'
|
3
12
|
|
4
13
|
module SnowmanIO
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
set :views, File.dirname(__FILE__) + "/api/views"
|
16
|
-
# TODO: fix it
|
17
|
-
set :session_secret, 'super secret'
|
18
|
-
|
19
|
-
ADMIN_PASSWORD_KEY = "admin_password_hash"
|
20
|
-
|
21
|
-
def admin_exists?
|
22
|
-
!!SnowmanIO.redis.get(ADMIN_PASSWORD_KEY)
|
23
|
-
end
|
24
|
-
|
25
|
-
def admin_authenticated?
|
26
|
-
admin_exists? && !!session[:user]
|
27
|
-
end
|
28
|
-
|
29
|
-
before do
|
30
|
-
if !admin_exists?
|
31
|
-
redirect to('/unpacking') if request.path_info != '/unpacking'
|
32
|
-
elsif !admin_authenticated?
|
33
|
-
redirect to('/login') if request.path_info != '/login'
|
14
|
+
module API
|
15
|
+
class Root < Grape::API
|
16
|
+
include AuthHelpers
|
17
|
+
default_format :json
|
18
|
+
format :json
|
19
|
+
default_error_formatter :json
|
20
|
+
|
21
|
+
rescue_from Mongoid::Errors::Validations do |e|
|
22
|
+
response = {errors: e.document.errors}
|
23
|
+
rack_response response.to_json, 400
|
34
24
|
end
|
35
|
-
end
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
get "/login" do
|
42
|
-
erb :login
|
43
|
-
end
|
44
|
-
|
45
|
-
post "/login" do
|
46
|
-
if BCrypt::Password.new(SnowmanIO.redis.get(ADMIN_PASSWORD_KEY)) == params["password"]
|
47
|
-
session[:user] = "admin"
|
48
|
-
redirect to('/')
|
49
|
-
else
|
50
|
-
@wrong_password_warning = true
|
51
|
-
erb :login
|
26
|
+
helpers do
|
27
|
+
def permitted_params
|
28
|
+
@permitted_params ||= declared(params, include_missing: false)
|
29
|
+
end
|
52
30
|
end
|
53
|
-
end
|
54
31
|
|
55
|
-
|
56
|
-
session[:user] = nil
|
57
|
-
redirect to("/login")
|
58
|
-
end
|
59
|
-
|
60
|
-
get "/unpacking" do
|
61
|
-
erb :unpacking
|
62
|
-
end
|
32
|
+
mount Agent
|
63
33
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
redirect to('/')
|
72
|
-
end
|
34
|
+
prefix :api
|
35
|
+
mount Users
|
36
|
+
mount Apps
|
37
|
+
mount Info
|
38
|
+
mount Metrics
|
39
|
+
mount Checks
|
40
|
+
mount Fridge
|
73
41
|
end
|
74
42
|
end
|
75
43
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SnowmanIO
|
2
|
+
module API
|
3
|
+
class Agent < Grape::API
|
4
|
+
namespace :agent do
|
5
|
+
|
6
|
+
desc "Report metrics from agent"
|
7
|
+
params do
|
8
|
+
requires :token, type: String
|
9
|
+
optional :metrics, type: Array
|
10
|
+
end
|
11
|
+
post "metrics" do
|
12
|
+
if app = App.where(token: params[:token]).first
|
13
|
+
params[:metrics].each do |metric|
|
14
|
+
if Metric.supported?(metric["kind"])
|
15
|
+
app.register_metric_value(metric["name"], metric["kind"], metric["value"].to_f, Time.now)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
"OK"
|
19
|
+
else
|
20
|
+
"WRONG APP"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SnowmanIO
|
2
|
+
module API
|
3
|
+
class Apps < Grape::API
|
4
|
+
before(&:authenticate!)
|
5
|
+
|
6
|
+
namespace :apps do
|
7
|
+
desc "Creates app"
|
8
|
+
params do
|
9
|
+
requires :app, type: Hash do
|
10
|
+
requires :name, type: String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
post do
|
14
|
+
{ app: App.create!(permitted_params[:app].to_h) }
|
15
|
+
end
|
16
|
+
|
17
|
+
route_param :id do
|
18
|
+
before do
|
19
|
+
@app = App.find(params[:id])
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Returns app"
|
23
|
+
get do
|
24
|
+
{ app: @app }
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Updates app"
|
28
|
+
params do
|
29
|
+
requires :app, type: Hash do
|
30
|
+
requires :name, type: String
|
31
|
+
end
|
32
|
+
end
|
33
|
+
put do
|
34
|
+
{ app: @app.tap { |app| app.update_attributes!(permitted_params[:app].to_h) } }
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Deletes app"
|
38
|
+
delete do
|
39
|
+
Extra::Meteor.model_destroy(App, @app)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|