Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Riemann freeswitch #90

Merged
merged 2 commits into from
Nov 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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