recmon 1.0.2 → 1.0.3

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.
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
+ == Version 1.0.3
2
+ - Added DiskfreeSensor
3
+
1
4
  == Version 1.0.2
2
- - Fixed du syntax
5
+ - Fixed du syntax
3
6
 
4
7
  == Version 1.0.1
5
8
  - Added filesize monitor.
data/README CHANGED
@@ -41,6 +41,7 @@ and it will periodically write entries to the log file (default = +/var/log/recm
41
41
  There are several sensors:
42
42
 
43
43
  - *web*: ensure a website is responding
44
+ - *diskfree*: track disk free space
44
45
  - *diskspace*: track the diskspace used by a folder
45
46
  - *filesize*: monitor the size of a file
46
47
  - *ping*: check if a server is alive
@@ -70,6 +71,13 @@ To periodically check if a website is reachable, add a WebSensor, specifying the
70
71
  s.web("Google", "http://www.google.com/jsapi", 120)
71
72
  # log entry => "2012-09-13T16:09:02+10:00 site=Google status=up"
72
73
 
74
+ === diskfree: track disk free space
75
+ A DiskfreeSensor tracks how much disk space is available on a mounted disk partition:
76
+
77
+ s.diskfree(name, freq=1200)
78
+ s.diskfree("/var")
79
+ # log entry => "2012-09-13T16:09:02+10:00 mountpoint=/var usage=45%"
80
+
73
81
  === diskspace: track the diskspace used by a folder
74
82
  A DiskspaceSensor tracks how much disk space is being consumed by a set of files (log files or database files) in a folder:
75
83
 
data/lib/recmon.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'recmon/monitor'
2
2
  require 'recmon/sensor'
3
3
  require 'recmon/command-sensor'
4
+ require 'recmon/diskfree-sensor'
4
5
  require 'recmon/diskspace-sensor'
5
6
  require 'recmon/filesize-sensor'
6
7
  require 'recmon/ping-sensor'
@@ -12,6 +13,7 @@ require 'recmon/web-sensor'
12
13
  # - Recmon::Monitor
13
14
  # - Recmon::Sensor
14
15
  # - Recmon::CommandSensor
16
+ # - Recmon::DiskfreeSensor
15
17
  # - Recmon::DiskspaceSensor
16
18
  # - Recmon::FilesizeSensor
17
19
  # - Recmon::PingSensor
@@ -0,0 +1,30 @@
1
+ require 'recmon/sensor'
2
+
3
+ module Recmon
4
+
5
+ # Periodically check the diskspace usage for a folder
6
+ class DiskfreeSensor < Sensor
7
+
8
+ # create a DiskfreeSensor to check the usage of a disk partition.
9
+ # * +name+ is a name of the mounted partition (eg. "/var")
10
+ def initialize(name, freq=1200)
11
+ super(name.strip(), freq)
12
+ raise "Partition not found: #{@name}" unless File.directory?(@name)
13
+ end
14
+
15
+ # Called by Monitor. Executes df(1) to determine the disk %usage.
16
+ def sense()
17
+ begin
18
+ lines = `sudo /bin/df #{@name}`.split("\n")
19
+ line = lines[1]
20
+ usage = "unknown"
21
+ if line
22
+ parts = line.split(/\s+/)
23
+ usage = parts[4]
24
+ end
25
+ end
26
+ return("mountpoint=#{@name} usage=#{usage}%")
27
+ end
28
+
29
+ end
30
+ end
@@ -71,6 +71,11 @@ class Monitor
71
71
  @sensors << Recmon::CommandSensor.new(name, command, freq)
72
72
  end
73
73
 
74
+ # Adds a DiskfreeSensor
75
+ def diskspace(name, freq=1200)
76
+ @sensors << Recmon::DiskfreeSensor.new(name, freq)
77
+ end
78
+
74
79
  # Adds a DiskspaceSensor
75
80
  def diskspace(name, path, freq=1200)
76
81
  @sensors << Recmon::DiskspaceSensor.new(name, path, freq)
@@ -6,7 +6,8 @@ module Recmon
6
6
  # Periodically pings a host to check it is alive
7
7
  class PingSensor < Sensor
8
8
 
9
- # Create a new PingSensor to ping the given IP every 2 minutes
9
+ # Create a new PingSensor to ping the given IP every 2 minutes.
10
+ # +ip+ can be a hostname if it can be sucessfully resolved.
10
11
  def initialize(name, ip, freq=120)
11
12
  super(name, freq)
12
13
  @ip = IPAddr.new(ip)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recmon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Kernahan
@@ -31,6 +31,7 @@ files:
31
31
  - lib/recmon/monitor.rb
32
32
  - lib/recmon/sensor.rb
33
33
  - lib/recmon/command-sensor.rb
34
+ - lib/recmon/diskfree-sensor.rb
34
35
  - lib/recmon/diskspace-sensor.rb
35
36
  - lib/recmon/filesize-sensor.rb
36
37
  - lib/recmon/ping-sensor.rb