Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding more parameters to services #6

Open
wants to merge 2 commits into from

2 participants

@hron84

Monit's xml contains more parameters than we already support, it would
be nice if we can support more info about system and services.

New parameters:

  • System:
    • os: Operating system
    • osversion: Operating system version
    • arch: Machine architecture
    • cputotal: Total nr. of CPUs
    • memtotal: Total size of memory (in KB)
    • swaptotal: Total size of swap area (in KB, nil if not supported)
  • Filesystem:
    • inode_percent, inode_usage, inode_total: Same values as block, but for inodes
  • Process:
    • total_memory: Memory usage of process and all children proces
    • total_cpu: CPU usage of process and all children process
    • response_time: monit supports checking a service within a process checking, and adds response time if it's available (or nil if not)

I added tests for these values too, and fixed formatting of source where
it is needed. All tests are passing

hron84 added some commits
@hron84 hron84 Adding more parameters to services
Monit's xml contains more parameters than we already support, it would
be nice if we can support more info about system and services.

New parameters:

 * System:
   * os: Operating system
   * osversion: Operating system version
   * arch: Machine architecture
   * cputotal: Total nr. of CPUs
   * memtotal: Total size of memory (in KB)
   * swaptotal: Total size of swap area (in KB, nil if not supported)
 * Filesystem:
   * inode_percent, inode_usage, inode_total: Same values as block, but
     for inodes
 * Process:
   * total_memory: Memory usage of process and all children proces
   * total_cpu: CPU usage of process and all children process
   * response_time: monit supports checking a service within a process
     checking, and adds response time if it's available (or nil if not)

I added tests for these values too, and fixed formatting of source where
it is needed. All tests are passing
7358836
@hron84 hron84 Fixing typo 1c451ac
@hron84

For pass tests on Travis, see #5 too.

@karmi
Owner

Are you sure all the parameters are available on current/most used Monit versions? I know there are some incompatibilities/inconsistencies...

@hron84

@karmi I checked it against Debian Lenny / Monit 4.10.1.

Filesystem: inode percent values are missing
Process: big total values are missing
System: all //platform related values are missing.

However I thinking on two thing:

  • Latest Monit version is 5.5. Are we sure to support a quite old systems? Monit does not have too much dependency, so it can be compiled on a very-very old architecture too - I ported Monit 5.4 to Debian Lenny without any problem -, so I do not think there is a real problem. TildeSlash provides an up-to-date package for bunch of architectures too.
  • If we want really support these old versions, we can make some guessing logic, e.g. where the percent value is missing, we can provide a method what calculates these values based on a free/used value.

My point is offer all new things - if somebody has an older monit, he could get nil - but nil is not an exception. I think clients can handle nils same way as we handle them in the sinatra application (displaying N/A).

I think current distributions does not provide monit older than 5.2 - and these things are supported quite long time ago. However, if anyone wants newer monit - he can recompile monit from source or grab TildeSlash binaries.

But you know what do you want... this is just my 2 cents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2013
  1. @hron84

    Adding more parameters to services

    hron84 authored
    Monit's xml contains more parameters than we already support, it would
    be nice if we can support more info about system and services.
    
    New parameters:
    
     * System:
       * os: Operating system
       * osversion: Operating system version
       * arch: Machine architecture
       * cputotal: Total nr. of CPUs
       * memtotal: Total size of memory (in KB)
       * swaptotal: Total size of swap area (in KB, nil if not supported)
     * Filesystem:
       * inode_percent, inode_usage, inode_total: Same values as block, but
         for inodes
     * Process:
       * total_memory: Memory usage of process and all children proces
       * total_cpu: CPU usage of process and all children process
       * response_time: monit supports checking a service within a process
         checking, and adds response time if it's available (or nil if not)
    
    I added tests for these values too, and fixed formatting of source where
    it is needed. All tests are passing
  2. @hron84

    Fixing typo

    hron84 authored
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 19 deletions.
  1. +25 −13 lib/monittr.rb
  2. +13 −6 test/monittr_test.rb
View
38 lib/monittr.rb
@@ -91,6 +91,12 @@ class System < Base
def initialize(xml)
@xml = xml
super( { :name => value('name' ),
+ :os => value('//platform/name' ),
+ :osversion => value('//platform/release' ),
+ :arch => value('//platform/machine' ),
+ :memtotal => value('//platform/memory', :to_i),
+ :swaptotal => value('//platform/swap', :to_i),
+ :cputotal => value('//platform/cpu', :to_i),
:status => value('status', :to_i),
:monitored => value('monitor', :to_i),
:load => value('system/load/avg01', :to_f),
@@ -111,12 +117,15 @@ def initialize(xml)
class Filesystem < Base
def initialize(xml)
@xml = xml
- super( { :name => value('name' ),
- :status => value('status', :to_i),
- :monitored => value('monitor', :to_i),
- :percent => value('block/percent', :to_f),
- :usage => value('block/usage' ),
- :total => value('block/total' )
+ super( { :name => value('name' ),
+ :status => value('status', :to_i),
+ :monitored => value('monitor', :to_i),
+ :percent => value('block/percent', :to_f),
+ :usage => value('block/usage' ),
+ :total => value('block/total' ),
+ :inode_percent => value('inode/percent', :to_f),
+ :inode_usage => value('inode/usage' ),
+ :inode_total => value('inode/total' )
} )
rescue Exception => e
puts "ERROR: #{e.class} -- #{e.message}, In: #{e.backtrace.first}"
@@ -135,13 +144,16 @@ def initialize(xml)
class Process < Base
def initialize(xml)
@xml = xml
- super( { :name => value('name' ),
- :status => value('status', :to_i),
- :monitored => value('monitor', :to_i),
- :pid => value('pid', :to_i),
- :uptime => value('uptime', :to_i),
- :memory => value('memory/percent', :to_f),
- :cpu => value('cpu/percent', :to_i)
+ super( { :name => value('name' ),
+ :status => value('status', :to_i),
+ :monitored => value('monitor', :to_i),
+ :pid => value('pid', :to_i),
+ :uptime => value('uptime', :to_i),
+ :memory => value('memory/percent', :to_f),
+ :cpu => value('cpu/percent', :to_i),
+ :total_memory => value('memory/percenttotal', :to_f),
+ :total_cpu => value('cpu/percenttotal', :to_i),
+ :response_time => value('port/responsetime', :to_i)
} )
rescue Exception => e
puts "ERROR: #{e.class} -- #{e.message}, In: #{e.backtrace.first}"
View
19 test/monittr_test.rb
@@ -73,13 +73,19 @@ class MonittrTest < Test::Unit::TestCase
end
should "return system info" do
- assert_not_nil @server.system
- assert_equal 0, @server.system.status
- assert_equal 1, @server.system.monitored
+ assert_not_nil @server.system
+ assert_equal 0, @server.system.status
+ assert_equal 1, @server.system.monitored
assert_equal 'application.com', @server.system.name
- assert_equal 5.28, @server.system.load
- assert_equal 0, @server.system.status
- assert_equal 937661, @server.system.uptime
+ assert_equal 5.28, @server.system.load
+ assert_equal 0, @server.system.status
+ assert_equal 937661, @server.system.uptime
+ assert_equal 'FreeBSD', @server.system.os
+ assert_equal '8.1-RELEASE', @server.system.osversion
+ assert_equal 'amd64', @server.system.arch
+ assert_equal 4, @server.system.cputotal
+ assert_equal 8373908, @server.system.memtotal
+ assert_equal nil, @server.system.swaptotal
end
should "return filesystems info" do
@@ -91,6 +97,7 @@ class MonittrTest < Test::Unit::TestCase
assert_equal 0, filesystem.status
assert_equal 1, filesystem.monitored
assert_equal 22.8, filesystem.percent
+ assert_equal 0.8, filesystem.inode_percent
end
should "return processes info" do
Something went wrong with that request. Please try again.