Project

procmon

0.0
No commit activity in last 3 years
No release in over 3 years
Procmon allows you to check on processes and then perform arbitary actions based on the result of the checks. For example, you can send notification when mem usage is too high, or you can restart a process if it's dead, etc. It is not meant to run as a daemon. It is designed to be invoked manually or via cron.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.5.0
 Project Readme

Procmon

Procmon is a process monitor written in Ruby. Concepts and design are based on Bluepill and God, but with emphasis on simplicity and extensibility.

Procmon allows you to check on processes and then perform arbitary actions based on the result of the checks. For example, you can send notification when mem usage is too high, or you can restart a process if it's dead, etc. It is not meant to run as a daemon. It is designed to be invoked manually or via cron.

Installation

It's hosted on [rubygems.org][rubygems].

sudo gem install procmon

Usage

    require 'rubygems'
    require 'procmon'

    notifier = Proc.new do
      puts "I NEED TO SEND OUT AN EMAIL"
    end

    notifier2 = Proc.new do
      puts "I NEED TO SEND OUT AN SMS"
    end
 
    # action can be a Proc object. You can define whatever you want to do 
    Procmon.process("Mail") do |process|
      process.checks :mem_usage, :above => 100.megabytes, :actions => [notifier, notifier2]
    end
 
    # You can specify a code block as well
    Procmon.process("Mail") do |process|
      process.pid = 29124
      process.checks :mem_usage, :above => 100.megabytes do
        puts "I'm in your base"
      end
    end
 
    # Using built-in email notifier
    NOTIFICATION_TARGET='ddao@example.com'
    Procmon.process("Mail") do |process|
      process.checks :mem_usage, :above => 100.megabytes, :actions => [Procmon::Notifiers::Email]
    end
 
    # Check if a process is alive
    Procmon.process("libvirtd") do |process|
      process.checks :process_health, :status => "down" do
        puts "Oh no! My process is not running"
      end
    end

    # Checking for percent cpu usage
    Procmon.process("Mail") do |process|
      process.checks :cpu_usage, :above => 90 do
        puts "This process sure is busy!"
      end
    end

    # You can have multiple checks in one process block
    Procmon.process("Mail") do |process|
      process.checks :cpu_usage, :above => 90 do
        puts "This process sure is busy!"
      end
      process.checks :mem_usage, :above => 500.megabytes do
        puts "Nom nom nom. I'm eating up all of the memory."
      end
    end
 
    # Would be nice if we can do this as well
    # Procmon.process("Mail") do |process|
    #  process.checks :mem_usage, :above => 100.megabytes do |action|
    #    action.perform(notifier)
    #    action.perform(Procmon::Notifiers::Email, 'someone@example.com')
    #  end
    #  process.checks :mem_usage, :above => 100.megabytes, :actions => [notifier, notifier2]
    #  process.checks :mem_usage, :above => 100.megabytes, :actions => [Procmon::Notifiers::Email]
    #end