sensu-plugins-cgroups 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1651ede861e1dd7e2ecf1003707e21cb0a80d991
4
- data.tar.gz: b462460e12937fa01f582fc41f838ddef4ca38ba
3
+ metadata.gz: 3977f9af71115c500dee0b3f0bdc39e709d9a436
4
+ data.tar.gz: 8fbaa70300354f52f516a7302b3582af2d362754
5
5
  SHA512:
6
- metadata.gz: ee51b2d6e269b9b5355236f4615926366b4ec77674b544edee33cb44bc5f2eed58e9f1e563e5be35a099931b73e82418647af490cf24aadeb35dbde5cb212385
7
- data.tar.gz: 8fdd7911513941ceba9fb1ff5537d874b40ff5002904446618bc359a3071b3ddd9a50c389bfcfc5977b3c0fed214cac13574a359ea1697b4ac5a06b8ea1552fe
6
+ metadata.gz: aeeb3613c62f59cd70beebd3525019ad609932e2089d88b9a8278b35c9a933ccab0426d7b02f2b3c588b2ef4307e4ab270de021b305db4f9653bc97397f78eb4
7
+ data.tar.gz: 36e68af14d019d76664ecc32b92344b641dbfefab2a26b3495284b8631fc9f581b352312e009f18cb9989fd45735b221a3007e5972c763d639ab9561f3c82c1b
@@ -5,10 +5,14 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.1.0] - 2017-08-01
9
+ ### Added
10
+ - New metrics script implemented in ruby (@bergerx)
11
+
8
12
  ## [1.0.0] - 2017-07-12
9
13
  ### Added
10
- - Support for Ruby 2.3.0
11
- - Support for Ruby 2.4.1
14
+ - Testing for Ruby 2.3.0
15
+ - Testing for Ruby 2.4.1
12
16
  ### Breaking Changes
13
17
  - Drop support for Ruby 1.9.3
14
18
 
@@ -27,7 +31,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
27
31
  ### Added
28
32
  - initial release
29
33
 
30
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/1.0.0...HEAD
34
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/1.1.0...HEAD
35
+ [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/1.0.0...1.1.0
31
36
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/0.0.3...1.0.0
32
37
  [0.0.3]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/0.0.2...0.0.3
33
38
  [0.0.2]: https://github.com/sensu-plugins/sensu-plugins-cgroups/compare/0.0.1...0.0.2
data/README.md CHANGED
@@ -10,9 +10,55 @@
10
10
 
11
11
  ## Files
12
12
  * bin/metrics-cgroup.sh
13
+ * bin/metrics-cgroup.rb
13
14
 
14
15
  ## Usage
15
16
 
17
+ Collect all cgroup metrics, tested only on CentOS.
18
+
19
+ ```
20
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/**"
21
+ ```
22
+
23
+ Collect only systemd service metrics
24
+
25
+ ```
26
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/system.slice/*"
27
+ ```
28
+
29
+ Collect only user.slice only
30
+
31
+ ```
32
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/user.slice"
33
+ ```
34
+
35
+ Collect only mesos task metrics
36
+
37
+ ```
38
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/mesos/*"
39
+ ```
40
+
41
+ Collect only docker container metrics (may not be meaningful if you already collect metrics from docker)
42
+
43
+ ```
44
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/docker/*"
45
+ ```
46
+
47
+ Collect only system.slice, user.slice, docker and mesos and nothing else
48
+
49
+ ```
50
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/{system.slice,user.slice,docker,mesos}{,/*}"
51
+ ```
52
+
53
+ Instead of collecting breakdown of each docker instance, or
54
+ mesos task, or systemd service metric; this could let to
55
+ collect/compare overall docker, mesos, systemd and user recources
56
+ in total.
57
+
58
+ ```
59
+ metrics-cgroup.rb -g "/sys/fs/cgroup/**/{system.slice,user.slice,docker,mesos}"
60
+ ```
61
+
16
62
  ## Installation
17
63
 
18
64
  [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # metrics-cgroup
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin collects cgroup metrics.
7
+ #
8
+ # OUTPUT:
9
+ # metrics data in graphite
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # # Collect all cgroup metrics, tested only on CentOS.
19
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/**"
20
+ #
21
+ # # Collect only systemd service metrics
22
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/system.slice/*"
23
+ #
24
+ # # Collect only user.slice only
25
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/user.slice"
26
+ #
27
+ # # Collect only mesos task metrics
28
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/mesos/*"
29
+ #
30
+ # # Collect only docker container metrics
31
+ # # (may not be meaningful if you already collect metrics from docker)
32
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/docker/*"
33
+ #
34
+ # # collect only system.slice, user.slice, docker and mesos and nothing else
35
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/{system.slice,user.slice,docker,mesos}{,/*}"
36
+ #
37
+ # # Instead of collecting breakdown of each docker instance, or
38
+ # # mesos task, or systemd service metric; this could let to
39
+ # # collect/compare overall docker, mesos, systemd and user recources
40
+ # # in total.
41
+ # metrics-cgroup.rb -g "/sys/fs/cgroup/**/{system.slice,user.slice,docker,mesos}"
42
+ #
43
+ # LICENCE:
44
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
45
+ # for details.
46
+ #
47
+ require 'sensu-plugin/metric/cli'
48
+ require 'socket'
49
+
50
+ class CgroupMetrics < Sensu::Plugin::Metric::CLI::Graphite
51
+ option :scheme,
52
+ description: 'Metric naming scheme, text to prepend to queue_name.metric',
53
+ short: '-s SCHEME',
54
+ long: '--scheme SCHEME',
55
+ default: "#{Socket.gethostname}.cgroup"
56
+ option :glob,
57
+ description: 'This should match a cgroup directories in a cgroup filesystem. '\
58
+ '(default: /sys/fs/cgroup/**/**)',
59
+ short: '-g GLOB',
60
+ long: '--glob GLOB',
61
+ default: '/sys/fs/cgroup/**/**'
62
+ option :files_whitelist,
63
+ description: 'Limit metric collection to this files, comma seperated '\
64
+ 'list of files in cgroup directories. (default is to '\
65
+ 'collect all files)',
66
+ short: '-f FILES_WHITELIST',
67
+ long: '--files-whitelist FILES_WHITELIST',
68
+ default: NIL
69
+ option :files_blacklist,
70
+ description: 'Don\'t collect these files, comma seperated list of file '\
71
+ 'names in cgroup directories. This list will override '\
72
+ 'whitelist if confict. "tasks" and "cgroup.procs" will '\
73
+ 'always appended to the list. (default: '\
74
+ '"cgroup.clone_children,notify_on_release")',
75
+ short: '-b FILES_BLACKLIST',
76
+ long: '--files-blacklist FILES_BLACKLIST',
77
+ default: 'cgroup.clone_children,notify_on_release'
78
+ option :smart_paths,
79
+ description: 'Instead of using full cgroup path in metrics this '\
80
+ 'enabling smarter metrics names',
81
+ short: '-p',
82
+ long: '--no-smart-paths',
83
+ boolean: true
84
+
85
+ def get_tag(cgroup_dir)
86
+ if config[:smart_paths]
87
+ "path.#{cgroup_dir.gsub(/[.\/]/, '_')}"
88
+ else
89
+ # use cgroup consumer specific tags
90
+ type, val = cgroup_dir.split(File::SEPARATOR)[-2..-1]
91
+ case type
92
+ when 'docker'
93
+ "docker_id.#{val}"
94
+ when 'mesos'
95
+ "mesos_container_id.#{val}"
96
+ when 'system.slice'
97
+ "systemd_unit.#{val.gsub(/[.\/]/, '_')}"
98
+ else
99
+ "path.#{cgroup_dir.gsub(/[.\/]/, '_')}"
100
+ end
101
+ end
102
+ end
103
+
104
+ def run
105
+ matching_dirs = Dir.glob(config[:glob])
106
+ if matching_dirs.empty?
107
+ critical "No matching directory for glob: #{config[:glob]}"
108
+ end
109
+
110
+ # Add 'tasks' and 'cgroup.procs' to blacklist
111
+ files_to_skip = config[:files_blacklist].split(',') + ['tasks', 'cgroup.procs']
112
+
113
+ matching_dirs.each do |cgroup_dir|
114
+ # Each matching object needs to be a cgroup directory, which always have a tasks file
115
+ next if !File.directory?(cgroup_dir) || !File.file?("#{cgroup_dir}/tasks")
116
+
117
+ Dir.glob("#{cgroup_dir}/*").each do |file|
118
+ next if !File.file?(file) || !File.readable?(file)
119
+
120
+ filename = File.basename(file)
121
+
122
+ files_whitelist = config[:files_whitelist]
123
+ unless files_whitelist.nil?
124
+ # skip if there is a whitelisted files list and it's not in the list
125
+ next unless files_whitelist.split(',').include?(filename)
126
+ end
127
+
128
+ # skip if the file is in blacklisted files list
129
+ next if files_to_skip.include?(filename)
130
+
131
+ # Skip files that can't be read
132
+ begin
133
+ lines = File.readlines(file)
134
+ rescue Errno::EIO
135
+ next
136
+ end
137
+
138
+ tag = get_tag(cgroup_dir)
139
+ metric_prefix = [config[:scheme], tag, filename.tr('.', '_')].join('.')
140
+
141
+ # block that parses most types of files under cgroup file system
142
+ if lines.size == 1
143
+ if /^(?<value>[\d-]+)$/=~ lines[0]
144
+ output(metric_prefix, value)
145
+ elsif /^(?<key>\w+) (?<value>[\d-]+)$/ =~ lines[0]
146
+ output([metric_prefix, key].join('.'), value)
147
+ elsif /^(?<values>([\d-]+ ?)+)$/ =~ lines[0]
148
+ values.split.each_with_index do |val, index|
149
+ output([metric_prefix, index].join('.'), val)
150
+ end
151
+ end
152
+ else
153
+ lines.each_with_index do |line, index|
154
+ if /^(?<value>[\d-]+)$/=~ line
155
+ output([metric_prefix, index].join('.'), value)
156
+ elsif /^(?<key>\w+) (?<value>[\d-]+)$/ =~ line
157
+ output([metric_prefix, key].join('.'), value)
158
+ elsif /^(?<dev>[\w:]+) (?<key>\w+) (?<value>[\d-]+)$/ =~ line
159
+ output([metric_prefix, dev.tr(':', '_'), key].join('.'), value)
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ ok
167
+ end
168
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsCgroups
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-cgroups
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -152,13 +152,15 @@ dependencies:
152
152
  version: '0.8'
153
153
  description: Sensu plugins for workign with cgroups
154
154
  email: "<sensu-users@googlegroups.com>"
155
- executables: []
155
+ executables:
156
+ - metrics-cgroup.rb
156
157
  extensions: []
157
158
  extra_rdoc_files: []
158
159
  files:
159
160
  - CHANGELOG.md
160
161
  - LICENSE
161
162
  - README.md
163
+ - bin/metrics-cgroup.rb
162
164
  - bin/metrics-cgroup.sh
163
165
  - lib/sensu-plugins-cgroups.rb
164
166
  - lib/sensu-plugins-cgroups/version.rb