malsh 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3f9b890ede7e635dfaadf659beb03d32e373836
4
- data.tar.gz: 32aa5fa95ccd58e26e16b12d628ec7408416b67b
3
+ metadata.gz: f57d61ecea6999ff0d35382a91d7e75bfddb89fd
4
+ data.tar.gz: 54e68023c18a8986a7ed2ed622b2a269e846fd40
5
5
  SHA512:
6
- metadata.gz: 76a2f05c3b3164c017cb863999a2317041722a2911b480c35c6ee081ec702c7b892653e0138a456c5596ccad0700110013b7fe7cb5098a0ecbbf9ab875f8f83c
7
- data.tar.gz: ca0d99f7b4d13d13813f20d00aec17c9d69a0b92a40fb87bf4c2bd5f4bcfab9295a032ffed57f0ec66d6f6270113e889a59a8713fb1a9c3e530d1e41082cf3b1
6
+ metadata.gz: b180f61a9316c5743588af5266b7c9af0ef5a5ec62b67f209c8a25036da224833d182b67b4eac5dc3148dea82a5e44a3ff5d2a10c8b31a07dbd02a5d5811370b
7
+ data.tar.gz: 698feecf25f60f438b40da1d41dc5a4497d214330fc8a33230a6eff0a95b6ce6a6139df6931cf91fc9dfc1e55c498c2047c6d1bb763b3029880cd1611c99f540
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # Malsh
2
- *Mackerel Sheperd = malsh*
2
+ *Mackerel Shepherd = malsh(マルシェ)*
3
3
 
4
4
  [![Build Status](https://travis-ci.org/pyama86/malsh.svg)](https://travis-ci.org/pyama86/malsh)
5
5
 
6
6
  [![Code Climate](https://codeclimate.com/github/pyama86/sac/badges/gpa.svg)](https://codeclimate.com/github/pyama86/sac)
7
7
 
8
8
 
9
- ### mackerelの運用で便利な下記の機能を提供します。
9
+ ### Mackerelの運用で便利な機能を提供します。
10
10
 
11
- * 退役忘れホストの検知
12
- * developmentっぽいホストの検知
13
- * ロールに紐付いてないホストの検知
11
+ * 退役忘れホストの通知
12
+ * ロールに紐付いてないホストの通知
13
+ * 特定のホスト名やCPU、メモリ利用率での検索結果の通知
14
14
 
15
- ### 通知機能
16
- * Slackへの通知
15
+ ### 通知先
16
+ * Slack
17
17
 
18
18
  ## Installation
19
19
 
@@ -29,32 +29,31 @@ $ export MACKEREL_APIKEY=xxxxxxxxxxxxxxxxxxxxxxxxxx
29
29
  # 過去5分間メトリックの投稿がないホストを検知
30
30
  $ malsh retire --subject 退役忘れホスト
31
31
 
32
- # 指定された単語がホスト名に含まれるホストを検知
33
- $ malsh find --regex dev local$ --subject developmentホスト
34
-
35
32
  # ロールに所属していないホストを検知
36
33
  $ malsh maverick --subject 無所属ホスト
34
+
35
+ # 指定された単語がホスト名に含まれるホストを検知
36
+ $ malsh search --regex dev local$ --subject developmentホスト
37
+
38
+ # CPUとメモリの過去7日間の最高使用率が40%以下のホストをを検知
39
+ $ malsh search --cpu 40 --memory 40 --subject 過去7日間のCPU、メモリがの最高使用率が40%以下
37
40
  ```
38
41
 
39
42
  ## options
40
43
  * --slack-webhook or ENV["SLACK_WEBHOOK"]
41
-
42
- slackのwebhookurlを指定するとslackに通知することができます。
44
+ * slackのwebhookurlを指定するとslackに通知することができます。
43
45
  * --slack-channel or ENV["SLACK_CHANNEL"]
44
-
45
- slackの通知先チャネルを指定します。
46
+ * slackの通知先チャネルを指定します。
46
47
  * --slack-user or ENV["SLACK_USER"]
47
-
48
- slackの通知ユーザーを指定します。
48
+ * slackの通知ユーザーを指定します。
49
49
  * --api-key or ENV["MACKEREL_APIKEY"]
50
-
51
- mackerelのAPIキーを指定します。
50
+ * mackerelのAPIキーを指定します。
52
51
  * --subject
53
-
54
- 通知のタイトルを指定します
52
+ * 通知のタイトルを指定します
55
53
  * --invert-match
56
-
57
- 除外したいホスト名を正規表現で指定します。
54
+ * 除外したいホスト名を正規表現で指定します。
55
+ * --regex
56
+ * 特定したいホスト名を正規表現で指定します。
58
57
 
59
58
  ## Author
60
59
  pyama86
data/lib/malsh/cli.rb CHANGED
@@ -9,6 +9,7 @@ module Malsh
9
9
  class_option :api_key, :type => :string, :aliases => :k
10
10
  class_option :subject, :type => :string, :aliases => :s
11
11
  class_option :invert_match, :type => :array, :aliases => :v
12
+ class_option :regexp,:type => :array, :aliases => :e
12
13
 
13
14
  desc 'retire', 'check forget retire host'
14
15
  def retire
@@ -22,18 +23,6 @@ module Malsh
22
23
  Malsh.notify("退役未了ホスト一覧", host_names)
23
24
  end
24
25
 
25
- desc 'find', 'find by hostname'
26
- option :regexp, :required => true, :type => :array, :aliases => :e
27
- def find
28
- Malsh.init options
29
-
30
- host_names = Parallel.map(Malsh.hosts) do |h|
31
- h.name if options[:regexp].find{|r| h.name.match(/#{r}/)}
32
- end.flatten.compact
33
-
34
- Malsh.notify("不要ホスト候補一覧", host_names)
35
- end
36
-
37
26
  desc 'maverick', 'check no role'
38
27
  def maverick
39
28
  Malsh.init options
@@ -45,22 +34,19 @@ module Malsh
45
34
  Malsh.notify("ロール無所属ホスト一覧", host_names)
46
35
  end
47
36
 
48
- desc 'obese', 'check obese hosts'
37
+ desc 'search', 'search hosts'
49
38
  option :past_date , :type => :numeric, :aliases => :p
50
39
  option :cpu_threshold, :type => :numeric, :aliases => :c
51
40
  option :memory_threshold, :type => :numeric, :aliases => :m
52
- def obese
41
+ def search
53
42
  _host_names = {}
54
43
  Malsh.init options
55
- now = Time.now.to_i
56
- # 7 = 1week
57
- from = now - (options[:past_date] || 7) * 86400
58
44
 
59
45
  hosts = Malsh.hosts
60
46
  Object.const_get("Malsh::HostMetrics").constants.each do |c|
61
- hosts = Object.const_get("Malsh::HostMetrics::#{c}").check(hosts, from, now)
47
+ hosts = Object.const_get("Malsh::HostMetrics::#{c}").check(hosts)
62
48
  end
63
- Malsh.notify("余剰リソースホスト一覧", hosts.compact.map {|h| h["name"]})
49
+ Malsh.notify("ホスト一覧", hosts.compact.map {|h| h["name"]})
64
50
  end
65
51
 
66
52
  map %w[--version -v] => :__print_version
@@ -1,7 +1,11 @@
1
1
  module Malsh::HostMetrics
2
2
  class Base
3
3
  class << self
4
- def check(hosts, from, to)
4
+ def check(hosts)
5
+ to = Time.now.to_i
6
+ # 7 = 1week
7
+ from = to - (Malsh.options[:past_date] || 7) * 86400
8
+
5
9
  if Malsh.options[option_name]
6
10
  Parallel.map(hosts) do |h|
7
11
  value = get_max_usage(h, from, to) if h
data/lib/malsh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Malsh
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/malsh.rb CHANGED
@@ -31,7 +31,11 @@ module Malsh
31
31
  end
32
32
 
33
33
  def hosts
34
- @_hosts ||= Mackerel.hosts.reject {|h| Malsh.options[:invert_match] && Malsh.options[:invert_match].find {|v| h.name.match(/#{v}/)}}
34
+ @_hosts ||= Mackerel.hosts.reject do |h|
35
+ Malsh.options[:invert_match] && Malsh.options[:invert_match].find {|v| h.name.match(/#{v}/) }
36
+ end.reject do |h|
37
+ Malsh.options[:regexp] && Malsh.options[:regexp].all? {|r| !h.name.match(/#{r}/)}
38
+ end
35
39
  end
36
40
 
37
41
  def host_by_id(id)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamahsita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor