Skip to content

Commit

Permalink
Merge pull request #90 from default50/riemann-freeswitch
Browse files Browse the repository at this point in the history
Riemann freeswitch
  • Loading branch information
aphyr committed Nov 18, 2014
2 parents dde783e + 1b29d14 commit b3b333a
Showing 1 changed file with 65 additions and 18 deletions.
83 changes: 65 additions & 18 deletions bin/riemann-freeswitch
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,73 @@ require File.expand_path('../../lib/riemann/tools', __FILE__)
class Riemann::Tools::FreeSWITCH
include Riemann::Tools

opt :calls_warning, "Calls warning threshold", :default => 100
opt :calls_critical, "Calls critical threshold", :default => 300
opt :pid_file, "FreeSWITCH daemon pidfile", :type => String, :default => "/var/run/freeswitch/freeswitch.pid"

def initialize
@limits = {
:calls => {:critical => opts[:calls_critical], :warning => opts[:calls_warning]}
}
end

def dead_proc?(pid)
begin
Process.kill(0, pid)
false
rescue Errno::ESRCH
true
end
end

def alert(service, state, metric, description)
report(
:service => service.to_s,
:state => state.to_s,
:metric => metric.to_f,
:description => description
)
end

def tick
# Determine how many current calls I have according to FreeSWITCH
fs_calls = %x[fs_cli -x "show calls count"| grep -Po '^\\d+'].to_i

# Determine how many current channels I have according to FreeSWITCH
fs_channels = %x[fs_cli -x "show channels count"| grep -Po '^\\d+'].to_i

# Try to read pidfile. If it fails use Devil's dummy PID
begin
fs_pid = File.read(opts[:pid_file]).to_i
rescue
fs_pid = -666
end

# Submit calls to riemann
if fs_calls > @limits[:calls][:critical]
alert "FreeSWITCH current calls", :critical, fs_calls, "Number of calls are #{fs_calls}"
elsif fs_calls > @limits[:calls][:warning]
alert "FreeSWITCH current calls", :warning, fs_calls, "Number of calls are #{fs_calls}"
else
alert "FreeSWITCH current calls", :ok, fs_calls, "Number of calls are #{fs_calls}"
end

# Submit channels to riemann
if fs_channels > @limits[:calls][:critical]
alert "FreeSWITCH current channels", :critical, fs_channels, "Number of channels are #{fs_channels}"
elsif fs_channels > @limits[:calls][:warning]
alert "FreeSWITCH current channels", :warning, fs_channels, "Number of channels are #{fs_channels}"
else
alert "FreeSWITCH current channels", :ok, fs_channels, "Number of channels are #{fs_channels}"
end

# Submit status to riemann
if dead_proc?(fs_pid)
alert "FreeSWITCH status", :critical, -1, "FreeSWITCH service status: not running"
else
alert "FreeSWITCH status", :ok, nil, "FreeSWITCH service status: running"
end

#determine how many current calls I have according to FreeSWITCH
fs_calls = %x[fs_cli -x "show calls count"| grep -Po '^\\d+']

#determine how many current channels I have according to FreeSWITCH
fs_channels = %x[fs_cli -x "show channels count"| grep -Po '^\\d+']

#submit them to riemann
report(
:service => "FreeSWITCH current calls",
:metric => fs_calls.to_i,
:state => "info"
)

report(
:service => "FreeSWITCH current channels",
:metric => fs_channels.to_i,
:state => "info"
)
end
end

Expand Down

0 comments on commit b3b333a

Please sign in to comment.