ruboty-elb_monitor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +1 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/lib/ruboty/elb_monitor.rb +57 -0
- data/lib/ruboty/elb_monitor/actions/add.rb +27 -0
- data/lib/ruboty/elb_monitor/actions/base.rb +12 -0
- data/lib/ruboty/elb_monitor/actions/delete.rb +26 -0
- data/lib/ruboty/elb_monitor/actions/list.rb +24 -0
- data/lib/ruboty/elb_monitor/actions/state.rb +79 -0
- data/lib/ruboty/elb_monitor/actions/state_trend.rb +15 -0
- data/lib/ruboty/elb_monitor/aws.rb +3 -0
- data/lib/ruboty/elb_monitor/aws/cloudwatch.rb +114 -0
- data/lib/ruboty/elb_monitor/aws/elb.rb +21 -0
- data/lib/ruboty/elb_monitor/version.rb +5 -0
- data/lib/ruboty/handlers/elb_monitor.rb +44 -0
- data/ruboty-elb_monitor.gemspec +27 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ff65eea61affe7466edd627c6c9de3138d640a53
|
4
|
+
data.tar.gz: ab3b439e96979ad7d025bc80d0ab0e8311149b2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b866ef205e88281596cbf975820b98f9e5bc5dfe5e8b445e9de491152d6aaf125b18c2d35c6a63deb9ce6c7fd30bcb10242fdcf0b63a3ef7e280435463da2eb
|
7
|
+
data.tar.gz: 843f50c10c69ba2537dd93715364af538890a4ef62b09ca592d62fcc37406d7048abb7795eac53aa0086e4b38e9030ea37adf7a09bfdf1b590a4120a8b4528eb
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruboty-elb (0.1.0)
|
5
|
+
aws-sdk
|
6
|
+
ruboty
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.2.6)
|
12
|
+
i18n (~> 0.7)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
aws-sdk (2.2.28)
|
18
|
+
aws-sdk-resources (= 2.2.28)
|
19
|
+
aws-sdk-core (2.2.28)
|
20
|
+
jmespath (~> 1.0)
|
21
|
+
aws-sdk-resources (2.2.28)
|
22
|
+
aws-sdk-core (= 2.2.28)
|
23
|
+
dotenv (2.1.0)
|
24
|
+
i18n (0.7.0)
|
25
|
+
jmespath (1.1.3)
|
26
|
+
json (1.8.3)
|
27
|
+
mem (0.1.5)
|
28
|
+
minitest (5.8.4)
|
29
|
+
rake (10.5.0)
|
30
|
+
ruboty (1.2.2)
|
31
|
+
activesupport
|
32
|
+
bundler
|
33
|
+
dotenv
|
34
|
+
mem
|
35
|
+
slop
|
36
|
+
slop (4.3.0)
|
37
|
+
thread_safe (0.3.5)
|
38
|
+
tzinfo (1.2.2)
|
39
|
+
thread_safe (~> 0.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 1.10)
|
46
|
+
rake (~> 10.0)
|
47
|
+
ruboty-elb!
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 arukoh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Ruboty::ElbMonitor
|
2
|
+
|
3
|
+
[Ruboty](https://github.com/r7kamura/ruboty) plug-in to monitor AWS ELB.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruboty-elb_monitor'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruboty-elb_monitor
|
20
|
+
|
21
|
+
## ENV
|
22
|
+
```
|
23
|
+
ELB_REGION - AWS region for ELB (default: ENV["AWS_REGION"])
|
24
|
+
ELB_ACCESS_KEY_ID - AWS access key for ELB (default: ENV["AWS_ACCESS_KEY_ID"])
|
25
|
+
ELB_SECRET_ACCESS_KEY - AWS secret key for ELB (default: ENV["AWS_SECRET_ACCESS_KEY"])
|
26
|
+
ELB_METRICS - Metric list to monitor (default: "RequestCount,HealthyHostCount,UnHealthyHostCount,HTTPCode_ELB_4XX,HTTPCode_ELB_5XX,HTTPCode_Backend_2XX,HTTPCode_Backend_4XX,HTTPCode_Backend_5XX,BackendConnectionErrors,SurgeQueueLength,SpilloverCount,Latency")
|
27
|
+
ELB_TREND_SEPARATOR - Trend separator (default: ' ')
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
```
|
32
|
+
$ bundle exec ruboty
|
33
|
+
Type `exit` or `quit` to end the session.
|
34
|
+
> @ruboty help elb
|
35
|
+
ruboty /add elb (?<name>.+) (?<real_name>.+)/ - Add a new alias name of elb to monitor.
|
36
|
+
ruboty /delete elb (?<name>.+)/ - Delete a alias name of elb to monitor.
|
37
|
+
ruboty /list elb names\z/ - List all elb names.
|
38
|
+
ruboty /show elb state (?<from>(?:(?!last).)+) (?<to>.+)/ - Show all elb status of the specified period.
|
39
|
+
ruboty /show elb state last (?<time>\d+)(?<format>(w|d|h|m))\z/ - Show all elb status of the last [w]eeks, [d]ays, [h]ours or [m]inutes.
|
40
|
+
ruboty /show elb state last (?<time>\d+)(?<format>(w|d|h|m)) trend\z/ - Show all elb status with trend of the last [w]eeks, [d]ays, [h]ours or [m]inutes.
|
41
|
+
```
|
42
|
+
|
43
|
+
### Example
|
44
|
+
```
|
45
|
+
$ bundle exec ruboty
|
46
|
+
Type `exit` or `quit` to end the session.
|
47
|
+
> @ruboty add elb foo elb-name-xxx
|
48
|
+
ELB foo registerd.
|
49
|
+
> @ruboty list elb names
|
50
|
+
foo: elb-name-xxx
|
51
|
+
> @ruboty show elb state 20160320 20160323
|
52
|
+
2016-03-20T00:00:00Z - 2016-03-23T00:00:00Z
|
53
|
+
*** foo(elb-name-xxx) ***
|
54
|
+
- RequestCount(Sum) 37
|
55
|
+
- HealthyHostCount(Average) 1
|
56
|
+
- UnHealthyHostCount(Average) 0
|
57
|
+
- HTTPCode_ELB_4XX(Sum) 0
|
58
|
+
- HTTPCode_ELB_5XX(Sum) 1
|
59
|
+
- HTTPCode_Backend_2XX(Sum) 23
|
60
|
+
- HTTPCode_Backend_4XX(Sum) 12
|
61
|
+
- HTTPCode_Backend_5XX(Sum) 1
|
62
|
+
- BackendConnectionErrors(Sum) 0
|
63
|
+
- SurgeQueueLength(Maximum) 0
|
64
|
+
- SpilloverCount(Sum) 0
|
65
|
+
- Latency(Maximum) 61.41
|
66
|
+
> @ruboty show elb state last 3d
|
67
|
+
2016-03-20T00:00:00Z - 2016-03-23T00:00:00Z
|
68
|
+
*** foo(elb-name-xxx) ***
|
69
|
+
- RequestCount(Sum) 37
|
70
|
+
- HealthyHostCount(Average) 1
|
71
|
+
- UnHealthyHostCount(Average) 0
|
72
|
+
- HTTPCode_ELB_4XX(Sum) 0
|
73
|
+
- HTTPCode_ELB_5XX(Sum) 1
|
74
|
+
- HTTPCode_Backend_2XX(Sum) 23
|
75
|
+
- HTTPCode_Backend_4XX(Sum) 12
|
76
|
+
- HTTPCode_Backend_5XX(Sum) 1
|
77
|
+
- BackendConnectionErrors(Sum) 0
|
78
|
+
- SurgeQueueLength(Maximum) 0
|
79
|
+
- SpilloverCount(Sum) 0
|
80
|
+
- Latency(Maximum) 61.41
|
81
|
+
> @ruboty show elb state last 3d trend
|
82
|
+
2016-03-20T00:00:00Z - 2016-03-23T00:00:00Z
|
83
|
+
*** foo(elb-name-xxx) ***
|
84
|
+
- RequestCount(Sum) 0 0 37
|
85
|
+
- HealthyHostCount(Average) 1 1 1
|
86
|
+
- UnHealthyHostCount(Average) 0 0 0
|
87
|
+
- HTTPCode_ELB_4XX(Sum) 0 0 0
|
88
|
+
- HTTPCode_ELB_5XX(Sum) 0 0 1
|
89
|
+
- HTTPCode_Backend_2XX(Sum) 0 0 23
|
90
|
+
- HTTPCode_Backend_4XX(Sum) 0 0 12
|
91
|
+
- HTTPCode_Backend_5XX(Sum) 0 0 1
|
92
|
+
- BackendConnectionErrors(Sum) 0 0 0
|
93
|
+
- SurgeQueueLength(Maximum) 0 0 0
|
94
|
+
- SpilloverCount(Sum) 0 0 0
|
95
|
+
- Latency(Maximum) 0 0 61.41
|
96
|
+
> @ruboty delete elb foo
|
97
|
+
ELB foo deleted
|
98
|
+
```
|
99
|
+
|
100
|
+
## Development
|
101
|
+
|
102
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
103
|
+
|
104
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-elb_monitor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
109
|
+
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
114
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruboty"
|
5
|
+
require "ruboty/elb_monitor"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "ruboty/elb_monitor/version"
|
2
|
+
require "ruboty/elb_monitor/aws"
|
3
|
+
require "ruboty/handlers/elb_monitor"
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module ElbMonitor
|
7
|
+
NAMESPACE = "elb_monitor"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def elb(name)
|
11
|
+
Aws::Elb.new(name, sdk_options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def cloudwatch(elb_name, start_time=nil, end_time=nil)
|
15
|
+
options = sdk_options.merge(
|
16
|
+
start_time: start_time,
|
17
|
+
end_time: end_time,
|
18
|
+
)
|
19
|
+
Aws::CloudWatch.new(elb_name, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def metrics
|
23
|
+
(ENV["ELB_METRICS"] || DEFAULT_METRICS).split(/,/)
|
24
|
+
end
|
25
|
+
|
26
|
+
def trend_separator
|
27
|
+
ENV["ELB_TREND_SEPARATOR"] || ' '
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
DEFAULT_METRICS = %w{
|
32
|
+
RequestCount
|
33
|
+
HealthyHostCount
|
34
|
+
UnHealthyHostCount
|
35
|
+
HTTPCode_ELB_4XX
|
36
|
+
HTTPCode_ELB_5XX
|
37
|
+
HTTPCode_Backend_2XX
|
38
|
+
HTTPCode_Backend_4XX
|
39
|
+
HTTPCode_Backend_5XX
|
40
|
+
BackendConnectionErrors
|
41
|
+
SurgeQueueLength
|
42
|
+
SpilloverCount
|
43
|
+
Latency
|
44
|
+
}.join(",")
|
45
|
+
|
46
|
+
def sdk_options
|
47
|
+
options = {
|
48
|
+
http_proxy: ENV["HTTPS_PROXY"] || ENV["https_proxy"] || ENV["HTTP_PROXY"] || ENV["http_proxy"]
|
49
|
+
}
|
50
|
+
options[:region] = ENV["ELB_REGION"] if ENV["ELB_REGION"]
|
51
|
+
options[:access_key_id] = ENV["ELB_ACCESS_KEY_ID"] if ENV["ELB_ACCESS_KEY_ID"]
|
52
|
+
options[:secret_access_key] = ENV["ELB_SECRET_ACCESS_KEY"] if ENV["ELB_SECRET_ACCESS_KEY"]
|
53
|
+
options
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module ElbMonitor
|
5
|
+
module Actions
|
6
|
+
class Add < Base
|
7
|
+
def call
|
8
|
+
message.reply(add)
|
9
|
+
rescue => e
|
10
|
+
message.reply(e.message)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def add
|
15
|
+
name = message[:name]
|
16
|
+
real = message[:real_name]
|
17
|
+
|
18
|
+
elb = Ruboty::ElbMonitor.elb(real)
|
19
|
+
elb.describe
|
20
|
+
elbs[name] = real
|
21
|
+
|
22
|
+
"ELB #{name} registerd."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module ElbMonitor
|
5
|
+
module Actions
|
6
|
+
class Delete < Base
|
7
|
+
def call
|
8
|
+
message.reply(delete)
|
9
|
+
rescue => e
|
10
|
+
message.reply(e.message)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def delete
|
15
|
+
name = message[:name]
|
16
|
+
if elbs.has_key?(name)
|
17
|
+
elbs.delete(name)
|
18
|
+
"ELB #{name} deleted"
|
19
|
+
else
|
20
|
+
"ELB #{name} does not exist"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module ElbMonitor
|
5
|
+
module Actions
|
6
|
+
class List < Base
|
7
|
+
def call
|
8
|
+
message.reply(list)
|
9
|
+
rescue => e
|
10
|
+
message.reply(e.message)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def list
|
15
|
+
if elbs.empty?
|
16
|
+
"ELB not found"
|
17
|
+
else
|
18
|
+
elbs.map{|k, v| "#{k}: #{v}"}.join("\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module ElbMonitor
|
5
|
+
module Actions
|
6
|
+
class State < Base
|
7
|
+
def call
|
8
|
+
message.reply(state)
|
9
|
+
rescue => e
|
10
|
+
message.reply(e.message)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def state(trend=false)
|
15
|
+
return "ELB not found" if elbs.empty?
|
16
|
+
|
17
|
+
start_time, end_time, period = get_time(trend)
|
18
|
+
|
19
|
+
msg = []
|
20
|
+
msg << "#{start_time.iso8601} - #{end_time.iso8601}"
|
21
|
+
elbs.each do |name, real|
|
22
|
+
msg << "*** #{name}(#{real}) ***"
|
23
|
+
|
24
|
+
resp = get_state(real, start_time, end_time, period)
|
25
|
+
label_max = resp.map(&:label).map(&:size).max
|
26
|
+
resp.each do |st|
|
27
|
+
value = get_value(st)
|
28
|
+
msg << " - #{st.label.ljust(label_max)}\t#{value}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
msg.join("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_state(name, start_time, end_time, period)
|
35
|
+
cloudwatch = Ruboty::ElbMonitor.cloudwatch(name, start_time, end_time)
|
36
|
+
Ruboty::ElbMonitor.metrics.map do |metric|
|
37
|
+
cloudwatch.get_statistics(metric, period: period)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_time(trend)
|
42
|
+
from = message[:from] rescue nil
|
43
|
+
to = message[:to] rescue nil
|
44
|
+
time = message[:time].to_i rescue nil
|
45
|
+
format = message[:format] rescue nil
|
46
|
+
if from && to
|
47
|
+
last = Time.parse(from)
|
48
|
+
now = Time.parse(to)
|
49
|
+
[ last, now, now - last ]
|
50
|
+
else
|
51
|
+
now = Time.now
|
52
|
+
last = case format.to_s
|
53
|
+
when "w"
|
54
|
+
now - (time * 7 * 24 * 60 * 60)
|
55
|
+
when "d"
|
56
|
+
now - (time * 24 * 60 * 60)
|
57
|
+
when "h"
|
58
|
+
now - (time * 60 * 60)
|
59
|
+
when "m"
|
60
|
+
now - (time * 60)
|
61
|
+
else
|
62
|
+
now
|
63
|
+
end
|
64
|
+
period = trend ? (now - last) / time : (now - last)
|
65
|
+
[ last, now, period.to_i ]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_value(st)
|
70
|
+
values = []
|
71
|
+
st.datapoints.each do |dp|
|
72
|
+
values << (dp.unit.to_s.downcase == "seconds" ? "%0.2f"%dp.value : "%d"%dp.value)
|
73
|
+
end
|
74
|
+
values.empty? ? 0 : values.join(Ruboty::ElbMonitor.trend_separator)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module ElbMonitor
|
3
|
+
module Aws
|
4
|
+
class CloudWatch
|
5
|
+
attr_reader :elb_name, :start_time, :end_time
|
6
|
+
|
7
|
+
def initialize(elb_name, options)
|
8
|
+
@elb_name = elb_name
|
9
|
+
@start_time = options[:start_time]
|
10
|
+
@end_time = options[:end_time]
|
11
|
+
|
12
|
+
opts = options.select {|k, v| CLIENT_OPTIONS.include? k.to_sym }
|
13
|
+
@client = ::Aws::CloudWatch::Client.new(opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_statistics(metric_name,
|
17
|
+
stats: nil,
|
18
|
+
start_time: nil,
|
19
|
+
end_time: nil,
|
20
|
+
period: nil)
|
21
|
+
stats ||= default_stats(metric_name)
|
22
|
+
end_time ||= @end_time || Time.now
|
23
|
+
start_time ||= @start_time || (end_time - 3600)
|
24
|
+
period ||= end_time - start_time
|
25
|
+
|
26
|
+
opts = {
|
27
|
+
namespace: "AWS/ELB",
|
28
|
+
metric_name: metric_name,
|
29
|
+
dimensions: [ {name: "LoadBalancerName", value: @elb_name} ],
|
30
|
+
start_time: start_time,
|
31
|
+
end_time: end_time,
|
32
|
+
period: period.to_i,
|
33
|
+
statistics: [stats]
|
34
|
+
}
|
35
|
+
resp = @client.get_metric_statistics(opts)
|
36
|
+
|
37
|
+
datapoints = default_datapoints(start_time, end_time, period)
|
38
|
+
resp.datapoints.each do |datapoint|
|
39
|
+
ts = datapoint.timestamp
|
40
|
+
dp = datapoints[ts.to_i]
|
41
|
+
dp.value = datapoint_to_value(datapoint)
|
42
|
+
dp.unit = datapoint.unit
|
43
|
+
dp.freeze
|
44
|
+
end
|
45
|
+
|
46
|
+
OpenStruct.new(
|
47
|
+
elb_name: @elb_name,
|
48
|
+
start_time: start_time,
|
49
|
+
end_time: end_time,
|
50
|
+
metric: resp.label,
|
51
|
+
stats: stats,
|
52
|
+
label: "#{resp.label}(#{stats})",
|
53
|
+
datapoints: datapoints.sort_by{|k,v| k}.map(&:last)
|
54
|
+
).freeze
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
CLIENT_OPTIONS = [:region, :access_key_id, :secret_access_key ]
|
59
|
+
|
60
|
+
STATS_MAXIMUM_GROUP = %w{
|
61
|
+
Latency
|
62
|
+
SurgeQueueLength
|
63
|
+
}
|
64
|
+
|
65
|
+
STATS_AVERAGE_GROUP = %w{
|
66
|
+
HealthyHostCount
|
67
|
+
UnHealthyHostCount
|
68
|
+
}
|
69
|
+
|
70
|
+
STATS_SUM_GROUP = %w{
|
71
|
+
RequestCount
|
72
|
+
SpilloverCount
|
73
|
+
HTTPCode_ELB_4XX
|
74
|
+
HTTPCode_ELB_5XX
|
75
|
+
HTTPCode_Backend_2XX
|
76
|
+
HTTPCode_Backend_4XX
|
77
|
+
HTTPCode_Backend_5XX
|
78
|
+
BackendConnectionErrors
|
79
|
+
}
|
80
|
+
|
81
|
+
def default_stats(metric)
|
82
|
+
case metric
|
83
|
+
when *STATS_MAXIMUM_GROUP
|
84
|
+
"Maximum"
|
85
|
+
when *STATS_AVERAGE_GROUP
|
86
|
+
"Average"
|
87
|
+
when *STATS_SUM_GROUP
|
88
|
+
"Sum"
|
89
|
+
else
|
90
|
+
raise ArgumentError, "#{metric} is unknown metric name"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def datapoint_to_value(dp)
|
95
|
+
dp.sample_count || dp.average || dp.sum || dp.minimum || dp.maximum
|
96
|
+
end
|
97
|
+
|
98
|
+
def sec_truncate(t)
|
99
|
+
Time.new(t.year, t.mon, t.day, t.hour, t.min, nil, t.utc_offset)
|
100
|
+
end
|
101
|
+
|
102
|
+
def default_datapoints(start_time, end_time, period)
|
103
|
+
stime = sec_truncate(start_time)
|
104
|
+
datapoints = {}
|
105
|
+
((end_time - start_time) / period).to_i.times do |i|
|
106
|
+
ts = stime + i * period
|
107
|
+
datapoints[ts.to_i] = OpenStruct.new(timestamp: ts, value: 0)
|
108
|
+
end
|
109
|
+
datapoints
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module ElbMonitor
|
3
|
+
module Aws
|
4
|
+
class Elb
|
5
|
+
def initialize(name, options)
|
6
|
+
@name = name
|
7
|
+
|
8
|
+
opts = options.select {|k, v| CLIENT_OPTIONS.include? k.to_sym }
|
9
|
+
@client = ::Aws::ElasticLoadBalancing::Client.new(opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def describe
|
13
|
+
@client.describe_load_balancers(load_balancer_names: [@name])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
CLIENT_OPTIONS = [:region, :access_key_id, :secret_access_key ]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "ruboty/elb_monitor/actions/add"
|
2
|
+
require "ruboty/elb_monitor/actions/delete"
|
3
|
+
require "ruboty/elb_monitor/actions/list"
|
4
|
+
require "ruboty/elb_monitor/actions/state"
|
5
|
+
require "ruboty/elb_monitor/actions/state_trend"
|
6
|
+
|
7
|
+
module Ruboty
|
8
|
+
module Handlers
|
9
|
+
# Monitor AWS ELB via Ruboty.
|
10
|
+
class ElbMonitor < Base
|
11
|
+
on /add elb (?<name>.+) (?<real_name>.+)/, name: 'add', description: 'Add a new alias name of elb to monitor.'
|
12
|
+
on /delete elb (?<name>.+)/, name: 'delete', description: 'Delete a alias name of elb to monitor.'
|
13
|
+
on /list elb names\z/, name: 'list', description: 'List all elb names.'
|
14
|
+
on /show elb state last (?<time>\d+)(?<format>(w|d|h|m))\z/, name: 'state', description: 'Show all elb status of the last [w]eeks, [d]ays, [h]ours or [m]inutes.'
|
15
|
+
on /show elb state (?<from>(?:(?!last).)+) (?<to>.+)/, name: 'state', description: 'Show all elb status of the specified period.'
|
16
|
+
on /show elb state last (?<time>\d+)(?<format>(w|d|h|m)) trend\z/, name: 'state_trend', description: 'Show all elb status with trend of the last [w]eeks, [d]ays, [h]ours or [m]inutes.'
|
17
|
+
|
18
|
+
env :ELB_REGION, "AWS region for ELB.", optional: true
|
19
|
+
env :ELB_ACCESS_KEY_ID, "AWS access key for ELB.", optional: true
|
20
|
+
env :ELB_SECRET_ACCESS_KEY, "AWS secret key for ELB.", optional: true
|
21
|
+
env :ELB_METRICS, "Metric list to monitor.", optional: true
|
22
|
+
|
23
|
+
def add(message)
|
24
|
+
Ruboty::ElbMonitor::Actions::Add.new(message).call
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(message)
|
28
|
+
Ruboty::ElbMonitor::Actions::Delete.new(message).call
|
29
|
+
end
|
30
|
+
|
31
|
+
def list(message)
|
32
|
+
Ruboty::ElbMonitor::Actions::List.new(message).call
|
33
|
+
end
|
34
|
+
|
35
|
+
def state(message)
|
36
|
+
Ruboty::ElbMonitor::Actions::State.new(message).call
|
37
|
+
end
|
38
|
+
|
39
|
+
def state_trend(message)
|
40
|
+
Ruboty::ElbMonitor::Actions::StateTrend.new(message).call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/elb_monitor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-elb_monitor"
|
8
|
+
spec.version = Ruboty::ElbMonitor::VERSION
|
9
|
+
spec.authors = ["arukoh"]
|
10
|
+
spec.email = ["arukoh10@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Monitor AWS ELB via Ruboty.}
|
13
|
+
spec.description = %q{Monitor AWS ELB via Ruboty.}
|
14
|
+
spec.homepage = "https://github.com/arukoh/ruboty-elb_monitor"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "ruboty"
|
26
|
+
spec.add_dependency "aws-sdk"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-elb_monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- arukoh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruboty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Monitor AWS ELB via Ruboty.
|
70
|
+
email:
|
71
|
+
- arukoh10@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/ruboty/elb_monitor.rb
|
87
|
+
- lib/ruboty/elb_monitor/actions/add.rb
|
88
|
+
- lib/ruboty/elb_monitor/actions/base.rb
|
89
|
+
- lib/ruboty/elb_monitor/actions/delete.rb
|
90
|
+
- lib/ruboty/elb_monitor/actions/list.rb
|
91
|
+
- lib/ruboty/elb_monitor/actions/state.rb
|
92
|
+
- lib/ruboty/elb_monitor/actions/state_trend.rb
|
93
|
+
- lib/ruboty/elb_monitor/aws.rb
|
94
|
+
- lib/ruboty/elb_monitor/aws/cloudwatch.rb
|
95
|
+
- lib/ruboty/elb_monitor/aws/elb.rb
|
96
|
+
- lib/ruboty/elb_monitor/version.rb
|
97
|
+
- lib/ruboty/handlers/elb_monitor.rb
|
98
|
+
- ruboty-elb_monitor.gemspec
|
99
|
+
homepage: https://github.com/arukoh/ruboty-elb_monitor
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.4.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Monitor AWS ELB via Ruboty.
|
123
|
+
test_files: []
|