kurchatov 0.0.2 → 0.0.3a

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: 12d8e19a3299c7b327e47c8ba767f43b37b216f6
4
- data.tar.gz: 44dd8f2603f2198ee0ff37cd9d2d90f00d4c6ee8
3
+ metadata.gz: 924266d6a2e4a98b5ecf7e376073cdb998c51b43
4
+ data.tar.gz: 909b8479425281711493f555c18a4832bf6ee3d7
5
5
  SHA512:
6
- metadata.gz: 5efe7fb43d65e52b4b1f1e71f3ed9414e5a3b5ea7920eb27e3ad4164a97c3a083d9f865868afae3c2051148897e9bf1ef127f9b46b7af28abbb2109b7df3e452
7
- data.tar.gz: 9d8e90d51336a578e894a1ac6c49a187f0beaf434d786bff7b0ab28a553d0305bde729abdc1a436673fefcec0a10ebf95bfa6423ca93141ce624f12934302620
6
+ metadata.gz: 6f82070f5217b37fb8130d1e2feef4b0c42a3299c819deab885e99b7eb4faef57ef1a8de0920170ffdbeec16890e6e0669aa130e19cad7795e5dedc60a8c74d8
7
+ data.tar.gz: b0c0940c7c14ca3b972397cc11776c382643b0b8061b4a023abeca188470cf32ac521649e7fa6b7301cbb066d9aa7c20a38f89fd38eae3dc553205cd0577160a
data/examples/la.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  always_start true
2
2
  interval 60
3
3
 
4
+ default[:cpu] = ohai[:cpu][:real]
5
+
4
6
  collect :os => "linux" do
5
7
  event(
6
8
  :metric => File.read('/proc/loadavg').scan(/[\d\.]+/)[0].to_f,
7
9
  :desc => 'LA averaged over 1 minute',
8
- :service => 'la la_1'
10
+ :service => 'la la_1',
11
+ :warning => plugin.cpu,
12
+ :critical => plugin.cpu * 2
9
13
  )
10
14
  end
11
15
 
@@ -13,6 +17,8 @@ collect :os => "darwin" do
13
17
  event(
14
18
  :metric => shell('uptime | cut -d":" -f4- | sed s/,//g').to_f,
15
19
  :desc => 'LA averaged over 1 minute',
16
- :service => 'la la_1'
20
+ :service => 'la la_1',
21
+ :warning => plugin.cpu,
22
+ :critical => plugin.cpu * 2
17
23
  )
18
24
  end
data/examples/uptime.rb CHANGED
@@ -9,6 +9,6 @@ end
9
9
 
10
10
  collect :os => "darwin" do
11
11
  event(
12
- :metric => shell('uptime | cut -d":" -f4- | sed s/,//g').to_f
12
+ :metric => shell("sysctl -n kern.boottime | awk '{print $4}'").to_f
13
13
  )
14
14
  end
@@ -1,13 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require "ohai/system"
3
4
  require "mixlib/cli"
4
5
  require "kurchatov/version"
5
6
  require "kurchatov/config"
6
7
  require "kurchatov/log"
7
8
  require "kurchatov/mixin/init"
8
9
  require "kurchatov/plugin/config"
9
- require "kurchatov/monitor"
10
10
  require "kurchatov/responders/init"
11
+ require "kurchatov/monitor"
11
12
 
12
13
  module Kurchatov
13
14
  class Aplication
@@ -1,5 +1,3 @@
1
- require "mixlib/config"
2
-
3
1
  module Kurchatov
4
2
  class Config
5
3
  extend Mixlib::Config
data/lib/kurchatov/log.rb CHANGED
@@ -1,5 +1,3 @@
1
- require "mixlib/log"
2
-
3
1
  module Kurchatov
4
2
  class Log
5
3
  extend Mixlib::Log
@@ -1,5 +1,3 @@
1
- require "mixlib/shellout"
2
-
3
1
  module Kurchatov
4
2
  module Mixin
5
3
  module Command
@@ -1,5 +1,3 @@
1
- require "ohai"
2
-
3
1
  module Kurchatov
4
2
 
5
3
  module Ohai
@@ -1,5 +1,3 @@
1
- require "kurchatov/mixin/queue"
2
-
3
1
  module Kurchatov
4
2
  class Monitor
5
3
 
@@ -41,7 +41,7 @@ module Kurchatov
41
41
  #
42
42
  if val.is_a?(Hash) && val.has_key?('parent')
43
43
  parent = find_plugin(val['parent'], @all_plugins)
44
- Log.error("Unable to find parent '#{parent_name}' for '#{name}'") and next if parent.nil?
44
+ Log.error("Unable to find parent '#{parent}' for '#{name}'") and next if parent.nil?
45
45
  child = parent.dup
46
46
  child.name = name
47
47
  child.plugin = parent.plugin.dup
@@ -2,6 +2,8 @@ module Kurchatov
2
2
  module Plugins
3
3
  class DSL
4
4
 
5
+ include Kurchatov::Mixin::Ohai
6
+
5
7
  attr_reader :plugins
6
8
  PLUGIN_EXT = '.rb'
7
9
 
@@ -19,7 +21,7 @@ module Kurchatov
19
21
  end
20
22
 
21
23
  def interval(val)
22
- last.interval = val
24
+ last.interval = val.to_f
23
25
  end
24
26
 
25
27
  def name(val)
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "kurchatov/plugin"
4
4
  require "kurchatov/mashie"
5
- require "kurchatov/mixin/init"
6
5
 
7
6
  module Kurchatov
8
7
  module Plugins
@@ -22,7 +21,7 @@ module Kurchatov
22
21
  @plugin = Mashie.new
23
22
  @always_start = false
24
23
  @collect = nil
25
- @interval = 60
24
+ @interval = 60.0
26
25
  end
27
26
 
28
27
  def run
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require "kurchatov/riemann/client"
4
- require "kurchatov/mixin/queue"
5
4
 
6
5
  module Kurchatov
7
6
  module Responders
@@ -1,7 +1,5 @@
1
1
  require "timeout"
2
2
  require "socket"
3
- require "beefcake"
4
- require "kurchatov/riemann/event"
5
3
  require "kurchatov/riemann/message"
6
4
 
7
5
  module Kurchatov
@@ -1,3 +1,6 @@
1
+ require "beefcake"
2
+ require "Kurchatov/riemann/event"
3
+
1
4
  module Kurchatov
2
5
  module Riemann
3
6
  class Message
@@ -1,3 +1,3 @@
1
1
  module Kurchatov
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3a"
3
3
  end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Nathan L Smith (<nlloyds@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "cpu"
20
+
21
+ cpu Mash.new
22
+ cpu[:real] = from("sysctl -n hw.physicalcpu").to_i
23
+ cpu[:total] = from("sysctl -n hw.logicalcpu").to_i
@@ -0,0 +1,60 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "cpu"
20
+
21
+ cpuinfo = Mash.new
22
+ real_cpu = Mash.new
23
+ cpu_number = 0
24
+ current_cpu = nil
25
+
26
+ File.open("/proc/cpuinfo").each do |line|
27
+ case line
28
+ when /processor\s+:\s(.+)/
29
+ cpuinfo[$1] = Mash.new
30
+ current_cpu = $1
31
+ cpu_number += 1
32
+ when /vendor_id\s+:\s(.+)/
33
+ cpuinfo[current_cpu]["vendor_id"] = $1
34
+ when /cpu family\s+:\s(.+)/
35
+ cpuinfo[current_cpu]["family"] = $1
36
+ when /model\s+:\s(.+)/
37
+ cpuinfo[current_cpu]["model"] = $1
38
+ when /stepping\s+:\s(.+)/
39
+ cpuinfo[current_cpu]["stepping"] = $1
40
+ when /physical id\s+:\s(.+)/
41
+ cpuinfo[current_cpu]["physical_id"] = $1
42
+ real_cpu[$1] = true
43
+ when /core id\s+:\s(.+)/
44
+ cpuinfo[current_cpu]["core_id"] = $1
45
+ when /cpu cores\s+:\s(.+)/
46
+ cpuinfo[current_cpu]["cores"] = $1
47
+ when /model name\s+:\s(.+)/
48
+ cpuinfo[current_cpu]["model_name"] = $1
49
+ when /cpu MHz\s+:\s(.+)/
50
+ cpuinfo[current_cpu]["mhz"] = $1
51
+ when /cache size\s+:\s(.+)/
52
+ cpuinfo[current_cpu]["cache_size"] = $1
53
+ when /flags\s+:\s(.+)/
54
+ cpuinfo[current_cpu]["flags"] = $1.split(' ')
55
+ end
56
+ end
57
+
58
+ cpu cpuinfo
59
+ cpu[:total] = cpu_number
60
+ cpu[:real] = real_cpu.keys.length
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2010 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'ruby-wmi'
20
+
21
+ provides "cpu"
22
+
23
+ cpuinfo = Mash.new
24
+ cpu_number = 0
25
+ index = 0
26
+
27
+ WMI::Win32_Processor.find(:all).each do |processor|
28
+ #
29
+ # On Windows Server 2003 R2 (i.e. 5.2.*), numberofcores property
30
+ # doesn't exist on the Win32_Processor class unless the user has
31
+ # patched their system with:
32
+ # http://support.microsoft.com/kb/932370
33
+ #
34
+ # We're returning nil for cpu["cores"] and cpu["count"]
35
+ # when we don't see numberofcores property
36
+ #
37
+
38
+ number_of_cores = nil
39
+ begin
40
+ number_of_cores = processor.numberofcores
41
+ cpu_number += number_of_cores
42
+ rescue NoMethodError => e
43
+ Ohai::Log.info("Can not find numberofcores property on Win32_Processor. Consider applying this patch: http://support.microsoft.com/kb/932370")
44
+ end
45
+
46
+ current_cpu = index.to_s
47
+ index += 1
48
+ cpuinfo[current_cpu] = Mash.new
49
+ cpuinfo[current_cpu]["vendor_id"] = processor.manufacturer
50
+ cpuinfo[current_cpu]["family"] = processor.family.to_s
51
+ cpuinfo[current_cpu]["model"] = processor.revision.to_s
52
+ cpuinfo[current_cpu]["stepping"] = processor.stepping
53
+ cpuinfo[current_cpu]["physical_id"] = processor.deviceid
54
+ #cpuinfo[current_cpu]["core_id"] = XXX
55
+ cpuinfo[current_cpu]["cores"] = number_of_cores
56
+ cpuinfo[current_cpu]["model_name"] = processor.description
57
+ cpuinfo[current_cpu]["mhz"] = processor.maxclockspeed.to_s
58
+ cpuinfo[current_cpu]["cache_size"] = "#{processor.l2cachesize} KB"
59
+ #cpuinfo[current_cpu]["flags"] = XXX
60
+ end
61
+
62
+ cpu cpuinfo
63
+ cpu[:total] = (cpu_number == 0) ? nil : cpu_number
64
+ cpu[:real] = index
data/tests/run.sh CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/bin/sh -e
2
2
 
3
3
 
4
- nc -l 5555 &
4
+ bundle exec ruby ./tests/server.rb &
5
5
 
6
6
  rm -rf ./tmp
7
7
  mkdir -p ./tmp
8
8
  cat > tmp/config.yml <<EOF
9
+ not_exists:
10
+ - not error please
9
11
  test2:
10
12
  url: './tests/run.sh'
11
13
  cmd: 'ls'
12
14
  parent: 'test'
13
- counter: 5
15
+ counter: 2
14
16
  test:
15
17
  - url: 'http://google.com'
16
18
  cmd: 'test -f ./tests/run.sh'
@@ -19,11 +21,11 @@ test:
19
21
  EOF
20
22
 
21
23
  cat > tmp/test1.rb <<EOF
22
- interval 10
24
+ interval 3
23
25
  name "test"
24
26
 
25
- default[:host] = 'http://notexists'
26
- default[:cmd] = 'ls -1 && ls /notexists'
27
+ default[:url] = 'http://notexists'
28
+ default[:cmd] = 'ls /notexists'
27
29
 
28
30
  collect do
29
31
  @counter ||= 0
@@ -31,6 +33,10 @@ collect do
31
33
  Log.info "get size from #{plugin.url}: #{rest_get(plugin.url).size}"
32
34
  @counter += 1
33
35
  exit 0 if plugin.counter && @counter > plugin.counter.to_i
36
+ event(:metric => 3, :critical => 2, :warning => 1)
37
+ event(:metric => 2, :critical => 2, :warning => 1)
38
+ event(:metric => 1, :critical => 2, :warning => 1)
39
+ event(:metric => 0, :critical => 2, :warning => 1)
34
40
  end
35
41
  EOF
36
42
 
@@ -51,5 +57,3 @@ grep 'file command ls return: Gemfile' ./tmp/loadplugins.log
51
57
  grep 'get size from http://google.com:' ./tmp/loadplugins.log
52
58
  grep 'get size from https://www.kernel.org' ./tmp/loadplugins.log
53
59
  grep 'get size from ./tests/run.sh' ./tmp/loadplugins.log
54
-
55
- pkill -9 nc || exit 0
data/tests/server.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "socket"
2
+ require "timeout"
3
+
4
+ server = TCPServer.new('127.0.0.1', 5555)
5
+ Timeout::timeout(20) {
6
+ loop {
7
+ client = server.accept
8
+ line = client.gets
9
+ puts line
10
+ }
11
+ } rescue exit 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kurchatov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3a
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev Dmitry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: beefcake
@@ -170,18 +170,22 @@ files:
170
170
  - lib/kurchatov/riemann/event.rb
171
171
  - lib/kurchatov/riemann/message.rb
172
172
  - lib/kurchatov/version.rb
173
+ - lib/ohai/plugins/darwin/cpu.rb
173
174
  - lib/ohai/plugins/darwin/hostname.rb
174
175
  - lib/ohai/plugins/darwin/platform.rb
175
176
  - lib/ohai/plugins/hostname.rb
177
+ - lib/ohai/plugins/linux/cpu.rb
176
178
  - lib/ohai/plugins/linux/hostname.rb
177
179
  - lib/ohai/plugins/linux/platform.rb
178
180
  - lib/ohai/plugins/linux/virtualization.rb
179
181
  - lib/ohai/plugins/os.rb
180
182
  - lib/ohai/plugins/platform.rb
181
183
  - lib/ohai/plugins/virtualization.rb
184
+ - lib/ohai/plugins/windows/cpu.rb
182
185
  - lib/ohai/plugins/windows/hostname.rb
183
186
  - lib/ohai/plugins/windows/platform.rb
184
187
  - tests/run.sh
188
+ - tests/server.rb
185
189
  homepage: https://github.com/vadv/kurchatov
186
190
  licenses:
187
191
  - MIT
@@ -197,9 +201,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
201
  version: '0'
198
202
  required_rubygems_version: !ruby/object:Gem::Requirement
199
203
  requirements:
200
- - - '>='
204
+ - - '>'
201
205
  - !ruby/object:Gem::Version
202
- version: '0'
206
+ version: 1.3.1
203
207
  requirements: []
204
208
  rubyforge_project:
205
209
  rubygems_version: 2.0.3