cloudwatch-sender 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/cloudwatch/sender/base.rb +1 -0
- data/lib/cloudwatch/sender/cli.rb +30 -9
- data/lib/cloudwatch/sender/credentials.rb +30 -0
- data/lib/cloudwatch/sender/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff1a63e62d0660b2cf330f15aa145c9012f69750
|
4
|
+
data.tar.gz: 987bd2e9c50204530cab7e1d5d211aeae9d011f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4210d48cd37b9390a139193a1e24a86b7dd20705de7399159c8140cb56cc37ee7218b14b517075bf253c3c57b2ebda18c9573b2c9abd79c29fff58358e54416
|
7
|
+
data.tar.gz: ace96313d3ed532c539166bc83d88fa7ccdb2403e047a96f9448e8336af695bf6618a958fb49834c5b4fe29fdba716d1cda20d2b3a410683f986d31043a67507
|
data/README.md
CHANGED
@@ -37,24 +37,28 @@ gem install cloudwatch-sender
|
|
37
37
|
### Command Line
|
38
38
|
|
39
39
|
```sh
|
40
|
-
cloudwatch-sender send_metrics /path/to/config.yaml
|
40
|
+
cloudwatch-sender send_metrics /path/to/config.yaml --region=eu-west-1 --access-key-id=$AWS_ACCESS_KEY --secret-access-key= $AWS_SECRET_KEY
|
41
41
|
```
|
42
42
|
|
43
43
|
If you would like to stream metrics to your endpoint at a set interval, use `continuous`:
|
44
44
|
|
45
45
|
```sh
|
46
|
-
cloudwatch-sender continuous /path/to/config.yaml $AWS_ACCESS_KEY $AWS_SECRET_KEY
|
46
|
+
cloudwatch-sender continuous /path/to/config.yaml --region=eu-west-1 $INTERVAL --access-key-id=$AWS_ACCESS_KEY --secret-access-key= $AWS_SECRET_KEY
|
47
47
|
```
|
48
48
|
|
49
49
|
**Note** - the default `$INTERVAL` is 60 seconds.
|
50
50
|
|
51
|
+
```sh
|
52
|
+
cloudwatch-sender continuous /path/to/config.yaml --region=eu-west-1 $INTERVAL --provider=iam
|
53
|
+
```
|
54
|
+
|
51
55
|
### Programmatically
|
52
56
|
|
53
57
|
```ruby
|
54
58
|
require "cloudwatch/sender/cli"
|
55
59
|
|
56
60
|
loop do
|
57
|
-
Cloudwatch::Sender::CLI.new.send_metrics(config_path
|
61
|
+
Cloudwatch::Sender::CLI.new.send_metrics(config_path = './configs/default.yml', { 'region' => 'eu-west-1', 'provider' => 'iam'})
|
58
62
|
sleep 120
|
59
63
|
end
|
60
64
|
```
|
@@ -62,7 +66,7 @@ end
|
|
62
66
|
```ruby
|
63
67
|
require "cloudwatch/sender/cli"
|
64
68
|
|
65
|
-
Cloudwatch::Sender::CLI.new.continuous(config_path
|
69
|
+
Cloudwatch::Sender::CLI.new.continuous(config_path = './configs/default.yml', 60, { 'region' => 'eu-west-1', 'provider' => 'iam'})
|
66
70
|
```
|
67
71
|
|
68
72
|
## Configs
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "logger"
|
3
3
|
require "cloudwatch/sender/ec2"
|
4
|
+
require "cloudwatch/sender/credentials"
|
4
5
|
require "cloudwatch/sender/metric_definition"
|
5
6
|
require "cloudwatch/sender/fetcher/base"
|
6
7
|
require "cloudwatch/sender/fetcher/ec2"
|
@@ -12,34 +13,54 @@ module Cloudwatch
|
|
12
13
|
class CLI < Thor
|
13
14
|
include Thor::Actions
|
14
15
|
|
15
|
-
desc "
|
16
|
-
|
17
|
-
|
16
|
+
class_option :provider, :desc => "AWS security provider", :required => false, :enum => ["iam", "instance_profile"]
|
17
|
+
class_option :access_key_id, :desc => "AWS access_key_id", :required => false
|
18
|
+
class_option :secret_access_key, :desc => "AWS secret_key_id", :required => false
|
19
|
+
class_option :region, :desc => "AWS region", :required => false
|
20
|
+
|
21
|
+
desc "send_metrics [metrics_file]", "Gets metrics from Cloudwatch and sends them to influx"
|
22
|
+
def send_metrics(metrics_file, opts = {})
|
23
|
+
setup_aws(options.merge(opts), opts["provider"])
|
18
24
|
MetricDefinition.metric_type load_metrics(metrics_file)
|
19
25
|
end
|
20
26
|
|
21
|
-
desc "continuous [metrics_file] [
|
22
|
-
def continuous(metrics_file,
|
27
|
+
desc "continuous [metrics_file] [sleep time]", "Continuously sends metrics to Influx/Cloudwatch"
|
28
|
+
def continuous(metrics_file, sleep_time = 60, opts = {})
|
23
29
|
logger = Logger.new(STDOUT)
|
24
30
|
|
25
31
|
loop do
|
26
32
|
begin
|
27
|
-
send_metrics(metrics_file,
|
33
|
+
send_metrics(metrics_file, options.merge(opts))
|
28
34
|
sleep sleep_time.to_i
|
35
|
+
rescue RequiredArgumentMissingError, ArgumentError => e
|
36
|
+
logger.error("Required argument invalid or missing '#{e}'")
|
37
|
+
exit(1)
|
38
|
+
rescue Aws::Errors::MissingCredentialsError => e
|
39
|
+
logger.error("#{e}")
|
40
|
+
exit(1)
|
29
41
|
rescue => e
|
30
42
|
logger.debug("Unable to complete operation #{e}")
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
47
|
+
|
35
48
|
no_commands do
|
36
49
|
def load_metrics(metrics_file)
|
37
50
|
YAML.load(File.open(metrics_file))
|
38
51
|
end
|
39
52
|
|
40
|
-
def setup_aws(
|
41
|
-
|
42
|
-
|
53
|
+
def setup_aws(options, provider)
|
54
|
+
SetupAwsCredentials.send("#{validate_provider(provider)}".to_sym, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def validate_provider(provider)
|
58
|
+
return "access_key_id" if provider.nil?
|
59
|
+
if %w(iam instance_profile).include? provider.downcase
|
60
|
+
provider.downcase
|
61
|
+
else
|
62
|
+
fail ArgumentError.new("'--provider' invalid argument '#{options['provider']}'")
|
63
|
+
end
|
43
64
|
end
|
44
65
|
end
|
45
66
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Cloudwatch
|
2
|
+
module Sender
|
3
|
+
class SetupAwsCredentials
|
4
|
+
def self.iam(options)
|
5
|
+
provider(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.instance_profile(options)
|
9
|
+
provider(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.access_key_id(options)
|
13
|
+
credentials = Aws::Credentials.new(options["access_key_id"], options["secret_access_key"])
|
14
|
+
Aws.config.update(:region => (options["region"] || ENV["AWS_REGION"]), :credentials => credentials)
|
15
|
+
rescue
|
16
|
+
RequiredArgumentMissingError.new("'--access_key_id' and '--secret_access_key' required")
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.credentials
|
22
|
+
Aws::InstanceProfileCredentials.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.provider(options)
|
26
|
+
Aws.config.update(:region => (options["region"] || ENV["AWS_REGION"]), :credentials => credentials)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudwatch-sender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DaveBlooman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- configs/example.yaml
|
88
88
|
- lib/cloudwatch/sender/base.rb
|
89
89
|
- lib/cloudwatch/sender/cli.rb
|
90
|
+
- lib/cloudwatch/sender/credentials.rb
|
90
91
|
- lib/cloudwatch/sender/ec2.rb
|
91
92
|
- lib/cloudwatch/sender/fetcher/base.rb
|
92
93
|
- lib/cloudwatch/sender/fetcher/custom.rb
|