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

Add users monitoring to riemann-health #226

Merged
merged 1 commit into from
Aug 17, 2022
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
25 changes: 25 additions & 0 deletions lib/riemann/tools/health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Health
opt :memory_critical, 'Memory critical threshold (fraction of RAM)', default: 0.95
opt :uptime_warning, 'Uptime warning threshold', default: 86_400
opt :uptime_critical, 'Uptime critical threshold', default: 3600
opt :users_warning, 'Users warning threshold', default: 1
opt :users_critical, 'Users critical threshold', default: 1
opt :swap_warning, 'Swap warning threshold', default: 0.4
opt :swap_critical, 'Swap critical threshold', default: 0.5
opt :checks, 'A list of checks to run.', type: :strings, default: %w[cpu load memory disk swap]
Expand All @@ -34,6 +36,7 @@ def initialize
load: { critical: opts[:load_critical], warning: opts[:load_warning] },
memory: { critical: opts[:memory_critical], warning: opts[:memory_warning] },
uptime: { critical: opts[:uptime_critical], warning: opts[:uptime_warning] },
users: { critical: opts[:users_critical], warning: opts[:users_warning] },
swap: { critical: opts[:swap_critical], warning: opts[:swap_warning] },
}
case (@ostype = `uname -s`.chomp.downcase)
Expand Down Expand Up @@ -80,6 +83,7 @@ def initialize
@swap = method :linux_swap
@supports_exclude_type = `df --help 2>&1 | grep -e "--exclude-type"` != ''
end
@users = method :users

opts[:checks].each do |check|
case check
Expand All @@ -93,6 +97,8 @@ def initialize
@memory_enabled = true
when 'uptime'
@uptime_enabled = true
when 'users'
@users_enabled = true
when 'swap'
@swap_enabled = true
end
Expand Down Expand Up @@ -120,6 +126,18 @@ def report_pct(service, fraction, report)
end
end

def report_int(service, value, report)
return unless value

if value >= @limits[service][:critical]
alert service, :critical, value, "#{value} #{report}"
elsif value >= @limits[service][:warning]
alert service, :warning, value, "#{value} #{report}"
else
alert service, :ok, value, "#{value} #{report}"
end
end

def report_uptime(uptime)
description = uptime_to_human(uptime)

Expand Down Expand Up @@ -391,6 +409,12 @@ def linux_uptime
report_uptime(value)
end

def users
value = uptime[:users]

report_int(:users, value, "user#{'s' if value != 1}")
end

def bsd_swap
_device, blocks, used, _avail, _capacity = `swapinfo`.lines.last.split(/\s+/)

Expand Down Expand Up @@ -442,6 +466,7 @@ def tick
@disk.call if @disk_enabled
@load.call if @load_enabled
@uptime.call if @uptime_enabled
@users.call if @users_enabled
@swap.call if @swap_enabled
end

Expand Down