lbrt 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lbrt.gemspec +1 -1
- data/lib/lbrt/alert.rb +54 -11
- data/lib/lbrt/cli/alert.rb +9 -0
- data/lib/lbrt/cli/metric.rb +5 -0
- data/lib/lbrt/cli/service.rb +5 -0
- data/lib/lbrt/cli/space.rb +6 -1
- data/lib/lbrt/metric.rb +29 -5
- data/lib/lbrt/service.rb +31 -0
- data/lib/lbrt/space/exporter.rb +1 -1
- data/lib/lbrt/space.rb +32 -9
- data/lib/lbrt/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f78090ca27e8694fc5661159b0cd3d0bc30e1c40
|
4
|
+
data.tar.gz: a5bca51feaef822ca735d078dd5c88587fb307cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b201f773aab280ecf430d30c6cb33f66e28bcf9e45ff85f5440ee5a13c913a8e6150cebb6518a26ac2fc9e34a266b0962cc50ea5159c05323d581ab0347db4e1
|
7
|
+
data.tar.gz: 2a89819c67f14f3c8484a35fed219d1574cc51c7f69df19514edceb5517260d443474fe70a296dbd03cdc44a0e152e595565367d7e9ee2185ee26794814b455d
|
data/README.md
CHANGED
@@ -45,6 +45,7 @@ Commands:
|
|
45
45
|
lbrt alert apply FILE # Apply alerts
|
46
46
|
lbrt alert export [FILE] # Export alerts
|
47
47
|
lbrt alert help [COMMAND] # Describe subcommands or one specific subcommand
|
48
|
+
lbrt alert list # Show alerts
|
48
49
|
lbrt alert peco # Show alert by peco
|
49
50
|
|
50
51
|
Options:
|
@@ -55,7 +56,8 @@ Options:
|
|
55
56
|
$ brt help metric
|
56
57
|
Commands:
|
57
58
|
lbrt metric help [COMMAND] # Describe subcommands or one specific subcommand
|
58
|
-
lbrt metric
|
59
|
+
lbrt metric list # Show metrics
|
60
|
+
lbrt metric peco REGRXP # Show metric by peco
|
59
61
|
|
60
62
|
Options:
|
61
63
|
[--target=TARGET]
|
@@ -67,6 +69,7 @@ Commands:
|
|
67
69
|
lbrt service apply FILE # Apply services
|
68
70
|
lbrt service export [FILE] # Export services
|
69
71
|
lbrt service help [COMMAND] # Describe subcommands or one specific subcommand
|
72
|
+
lbrt service list # Show services
|
70
73
|
|
71
74
|
Options:
|
72
75
|
[--target=TARGET]
|
@@ -78,11 +81,12 @@ Commands:
|
|
78
81
|
lbrt space apply FILE # Apply spaces
|
79
82
|
lbrt space export [FILE] # Export spaces
|
80
83
|
lbrt space help [COMMAND] # Describe subcommands or one specific subcommand
|
84
|
+
lbrt space list # Show spaces
|
81
85
|
lbrt space peco # Show space by peco
|
82
86
|
|
83
87
|
Options:
|
84
88
|
[--target=TARGET]
|
85
|
-
[--
|
89
|
+
[--concurrency=N]
|
86
90
|
# Default: 32
|
87
91
|
```
|
88
92
|
|
data/lbrt.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency 'diffy'
|
23
23
|
spec.add_dependency 'hashie'
|
24
|
-
spec.add_dependency 'librato-client'
|
24
|
+
spec.add_dependency 'librato-client', '>= 0.1.1'
|
25
25
|
spec.add_dependency 'parallel'
|
26
26
|
spec.add_dependency 'peco_selector'
|
27
27
|
spec.add_dependency 'term-ansicolor'
|
data/lib/lbrt/alert.rb
CHANGED
@@ -1,27 +1,45 @@
|
|
1
1
|
class Lbrt::Alert
|
2
2
|
include Lbrt::Logger::Helper
|
3
3
|
|
4
|
+
DEFAULT_CONCURRENCY = 32
|
5
|
+
|
4
6
|
def initialize(client, options = {})
|
5
7
|
@client = client
|
6
8
|
@options = options
|
7
9
|
@driver = Lbrt::Driver.new(@client, @options)
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
11
|
-
|
12
|
+
def list
|
13
|
+
json = {}
|
14
|
+
alert_by_name = build_alert_by_name
|
12
15
|
|
13
|
-
|
14
|
-
alert_id = alrt
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
alert_by_name.each do |name, alrt|
|
17
|
+
alert_id = alrt[:id]
|
18
|
+
|
19
|
+
json[alert_id] = {
|
20
|
+
name: name,
|
21
|
+
url: alert_url(alert_id),
|
22
|
+
status: alrt[:status],
|
23
|
+
}
|
18
24
|
end
|
19
25
|
|
20
|
-
|
26
|
+
puts JSON.pretty_generate(json)
|
27
|
+
end
|
28
|
+
|
29
|
+
def peco
|
30
|
+
alert_id_by_name = {}
|
31
|
+
|
32
|
+
build_alert_by_name.select {|name, alrt|
|
33
|
+
@options[:status].nil? or @options[:status] == alrt[:status]
|
34
|
+
}.map {|name, alrt| alert_id_by_name[name] = alrt[:id] }
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
unless alert_id_by_name.empty?
|
37
|
+
result = PecoSelector.select_from(alert_id_by_name)
|
38
|
+
|
39
|
+
result.each do |alert_id|
|
40
|
+
url = alert_url(alert_id)
|
41
|
+
Lbrt::Utils.open(url)
|
42
|
+
end
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
@@ -36,6 +54,31 @@ class Lbrt::Alert
|
|
36
54
|
|
37
55
|
private
|
38
56
|
|
57
|
+
def build_alert_by_name
|
58
|
+
alert_by_name = {}
|
59
|
+
|
60
|
+
@client.alerts.get.each do |alrt|
|
61
|
+
alert_id = alrt.fetch('id')
|
62
|
+
name = alrt.fetch('name')
|
63
|
+
next unless Lbrt::Utils.matched?(name, @options[:target])
|
64
|
+
alert_by_name[name] = {id: alert_id}
|
65
|
+
end
|
66
|
+
|
67
|
+
concurrency = @options[:concurrency] || DEFAULT_CONCURRENCY
|
68
|
+
|
69
|
+
Parallel.each(alert_by_name, :in_threads => concurrency) do |name, alrt|
|
70
|
+
alert_id = alrt[:id]
|
71
|
+
status = @client.alerts(alert_id).status.get
|
72
|
+
alrt[:status] = status['status']
|
73
|
+
end
|
74
|
+
|
75
|
+
alert_by_name
|
76
|
+
end
|
77
|
+
|
78
|
+
def alert_url(alert_id)
|
79
|
+
"https://metrics.librato.com/alerts#/#{alert_id}"
|
80
|
+
end
|
81
|
+
|
39
82
|
def walk(file)
|
40
83
|
expected = load_file(file)
|
41
84
|
actual = Lbrt::Alert::Exporter.export(@client, @options)
|
data/lib/lbrt/cli/alert.rb
CHANGED
@@ -3,7 +3,16 @@ class Lbrt::CLI::Alert < Thor
|
|
3
3
|
|
4
4
|
class_option :target
|
5
5
|
|
6
|
+
desc 'list', 'Show alerts'
|
7
|
+
option :'status'
|
8
|
+
option :'concurrency', :type => :numeric, :default => 32
|
9
|
+
def list
|
10
|
+
client(Lbrt::Alert).list
|
11
|
+
end
|
12
|
+
|
6
13
|
desc 'peco', 'Show alert by peco'
|
14
|
+
option :'status'
|
15
|
+
option :'concurrency', :type => :numeric, :default => 32
|
7
16
|
def peco
|
8
17
|
client(Lbrt::Alert).peco
|
9
18
|
end
|
data/lib/lbrt/cli/metric.rb
CHANGED
data/lib/lbrt/cli/service.rb
CHANGED
data/lib/lbrt/cli/space.rb
CHANGED
@@ -2,7 +2,12 @@ class Lbrt::CLI::Space < Thor
|
|
2
2
|
include Lbrt::Utils::CLIHelper
|
3
3
|
|
4
4
|
class_option :target
|
5
|
-
class_option :'
|
5
|
+
class_option :'concurrency', :type => :numeric, :default => 32
|
6
|
+
|
7
|
+
desc 'list', 'Show spaces'
|
8
|
+
def list
|
9
|
+
client(Lbrt::Space).list
|
10
|
+
end
|
6
11
|
|
7
12
|
desc 'peco', 'Show space by peco'
|
8
13
|
def peco
|
data/lib/lbrt/metric.rb
CHANGED
@@ -6,18 +6,42 @@ class Lbrt::Metric
|
|
6
6
|
@options = options
|
7
7
|
end
|
8
8
|
|
9
|
+
def list
|
10
|
+
json = {}
|
11
|
+
metric_names = build_metric_names
|
12
|
+
|
13
|
+
metric_names.each do |name|
|
14
|
+
json[name] = {
|
15
|
+
url: metric_url(name),
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
puts JSON.pretty_generate(json)
|
20
|
+
end
|
21
|
+
|
9
22
|
def peco
|
23
|
+
metric_names = build_metric_names
|
24
|
+
result = PecoSelector.select_from(metric_names)
|
25
|
+
|
26
|
+
result.each do |name|
|
27
|
+
url = metric_url(name)
|
28
|
+
Lbrt::Utils.open(url)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build_metric_names
|
10
35
|
metric_names = @client.metrics.get.map {|mtrc|
|
11
36
|
mtrc.fetch('name')
|
12
37
|
}.select {|name|
|
13
38
|
Lbrt::Utils.matched?(name, @options[:target])
|
14
39
|
}
|
15
40
|
|
16
|
-
|
41
|
+
metric_names
|
42
|
+
end
|
17
43
|
|
18
|
-
|
19
|
-
|
20
|
-
Lbrt::Utils.open(url)
|
21
|
-
end
|
44
|
+
def metric_url(name)
|
45
|
+
"https://metrics.librato.com/s/metrics/#{name}"
|
22
46
|
end
|
23
47
|
end
|
data/lib/lbrt/service.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
class Lbrt::Service
|
2
2
|
include Lbrt::Logger::Helper
|
3
3
|
|
4
|
+
def list
|
5
|
+
json = {}
|
6
|
+
service_by_key = build_service_by_key
|
7
|
+
|
8
|
+
service_by_key.each do |service_key, srvc|
|
9
|
+
service_id = srvc.delete('id')
|
10
|
+
type, title = service_key
|
11
|
+
|
12
|
+
json[service_id] = {
|
13
|
+
type: type,
|
14
|
+
title: title,
|
15
|
+
}.merge(srvc)
|
16
|
+
end
|
17
|
+
|
18
|
+
puts JSON.pretty_generate(json)
|
19
|
+
end
|
20
|
+
|
4
21
|
def initialize(client, options = {})
|
5
22
|
@client = client
|
6
23
|
@options = options
|
@@ -18,6 +35,20 @@ class Lbrt::Service
|
|
18
35
|
|
19
36
|
private
|
20
37
|
|
38
|
+
def build_service_by_key
|
39
|
+
service_by_key = {}
|
40
|
+
|
41
|
+
@client.services.get.each do |srvc|
|
42
|
+
type = srvc.delete('type')
|
43
|
+
title = srvc.delete('title')
|
44
|
+
service_key = [type, title]
|
45
|
+
next unless service_key.any? {|i| Lbrt::Utils.matched?(i, @options[:target]) }
|
46
|
+
service_by_key[service_key] = srvc
|
47
|
+
end
|
48
|
+
|
49
|
+
service_by_key
|
50
|
+
end
|
51
|
+
|
21
52
|
def walk(file)
|
22
53
|
expected = load_file(file)
|
23
54
|
actual = Lbrt::Service::Exporter.export(@client, @options)
|
data/lib/lbrt/space/exporter.rb
CHANGED
@@ -21,7 +21,7 @@ class Lbrt::Space::Exporter
|
|
21
21
|
|
22
22
|
def normalize_spaces(spaces)
|
23
23
|
space_by_name_or_id = {}
|
24
|
-
concurrency = @options[:
|
24
|
+
concurrency = @options[:concurrency] || DEFAULT_CONCURRENCY
|
25
25
|
|
26
26
|
Parallel.each(spaces, :in_threads => concurrency) do |spc|
|
27
27
|
space_id = spc.fetch('id')
|
data/lib/lbrt/space.rb
CHANGED
@@ -7,20 +7,26 @@ class Lbrt::Space
|
|
7
7
|
@driver = Lbrt::Driver.new(@client, @options)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
def list
|
11
|
+
json = {}
|
12
|
+
space_by_name_or_id = build_space_by_name_or_id
|
13
|
+
|
14
|
+
space_by_name_or_id.each do |name_or_id, space_id|
|
15
|
+
json[space_id] = {
|
16
|
+
name: name_or_id,
|
17
|
+
url: space_url(space_id),
|
18
|
+
}
|
18
19
|
end
|
19
20
|
|
21
|
+
puts JSON.pretty_generate(json)
|
22
|
+
end
|
23
|
+
|
24
|
+
def peco
|
25
|
+
space_by_name_or_id = build_space_by_name_or_id
|
20
26
|
result = PecoSelector.select_from(space_by_name_or_id)
|
21
27
|
|
22
28
|
result.each do |space_id|
|
23
|
-
url =
|
29
|
+
url = space_url(space_id)
|
24
30
|
Lbrt::Utils.open(url)
|
25
31
|
end
|
26
32
|
end
|
@@ -36,6 +42,23 @@ class Lbrt::Space
|
|
36
42
|
|
37
43
|
private
|
38
44
|
|
45
|
+
def build_space_by_name_or_id
|
46
|
+
space_by_name_or_id = {}
|
47
|
+
|
48
|
+
@client.spaces.get.each do |spc|
|
49
|
+
space_id = spc.fetch('id')
|
50
|
+
name_or_id = spc.fetch('name') || space_id
|
51
|
+
next unless Lbrt::Utils.matched?(name_or_id, @options[:target])
|
52
|
+
space_by_name_or_id[name_or_id] = space_id
|
53
|
+
end
|
54
|
+
|
55
|
+
space_by_name_or_id
|
56
|
+
end
|
57
|
+
|
58
|
+
def space_url(space_id)
|
59
|
+
"https://metrics.librato.com/s/spaces/#{space_id}"
|
60
|
+
end
|
61
|
+
|
39
62
|
def walk(file)
|
40
63
|
expected = load_file(file)
|
41
64
|
actual = Lbrt::Space::Exporter.export(@client, @options)
|
data/lib/lbrt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbrt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.1.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.1.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parallel
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|