mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-05 01:53:44 +01:00
Merge branch 'master' of github.com:opinkerfi/nagios-plugins
This commit is contained in:
commit
c1005cb911
59
check_cpu.py/nagios-okplugin-check_cpu.spec
Normal file
59
check_cpu.py/nagios-okplugin-check_cpu.spec
Normal file
@ -0,0 +1,59 @@
|
||||
%define debug_package %{nil}
|
||||
|
||||
Summary: A Nagios plugin to check CPU on Linux servers
|
||||
Name: nagios-okplugin-check_cpu
|
||||
Version: 1.1
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2+
|
||||
Group: Applications/System
|
||||
URL: https://github.com/opinkerfi/nagios-plugins/
|
||||
Source0: https://github.com/opinkerfi/nagios-plugins/archive/%{name}-%{version}-%{release}.tar.gz
|
||||
Requires: nagios-okplugin-common
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
Packager: Tomas Edwardsson <tommi@tommi.org>
|
||||
BuildArch: noarch
|
||||
|
||||
%description
|
||||
Check cpu states on line machines
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
install -D -p -m 0755 okplugin_check_cpu %{buildroot}%{_libdir}/nagios/plugins/okplugin_check_cpu
|
||||
install -D -p -m 0755 nrpe.d/okplugin_check_cpu.cfg %{buildroot}/etc/nrpe.d/okplugin_check_cpu.cfg
|
||||
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%post
|
||||
/sbin/service nrpe reload
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%{_libdir}/nagios/plugins/*
|
||||
%{_sysconfdir}/nrpe.d/*
|
||||
|
||||
|
||||
|
||||
%changelog
|
||||
* Mon Jan 20 2014 Tomas Edwardsson <tommi@tommi.org> 1.1-1
|
||||
- new package built with tito
|
||||
|
||||
* Thu Aug 23 2012 Pall Sigurdsson <palli@opensource.is> 1.0-1
|
||||
- Version number bumped
|
||||
- Updates buildarch to noarch (tommi@tommi.org)
|
||||
|
||||
* Mon Mar 12 2012 Pall Sigurdsson <palli@opensource.is> 0.3-1
|
||||
- new package built with tito
|
||||
|
||||
* Thu Nov 25 2010 Pall Sigurdsson <palli@opensource.is> 0.1-2
|
||||
- Nrpe config now ships with plugin by default
|
||||
* Mon Mar 1 2010 Tomas Edwardsson <tommi@ok.is> 0.1-1
|
||||
- Initial packaging
|
||||
|
1
check_cpu.py/nrpe.d/okplugin_check_cpu.cfg
Normal file
1
check_cpu.py/nrpe.d/okplugin_check_cpu.cfg
Normal file
@ -0,0 +1 @@
|
||||
command[okplugin_check_cpu]=/usr/lib/nagios/plugins/okplugin_check_cpu
|
132
check_cpu.py/okplugin_check_cpu
Normal file
132
check_cpu.py/okplugin_check_cpu
Normal file
@ -0,0 +1,132 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright 2014, Tomas Edwardsson
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
Gathers information on cpu usage on a linux machine
|
||||
|
||||
It returns performance data for both the last 5 seconds and from last run.
|
||||
"""
|
||||
|
||||
from pynag.Plugins import PluginHelper, ok, unknown
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
"""The main logic of the program"""
|
||||
|
||||
# See man proc and search for /proc/stat
|
||||
stat_fields = ['cpu', 'user', 'nice', 'system', 'idle', 'iowait', 'irq',
|
||||
'softirq', 'steal', 'guest', 'guest_nice']
|
||||
|
||||
pyplug = PluginHelper()
|
||||
|
||||
# Get the statistics from last run
|
||||
old_stat = get_saved_stat()
|
||||
|
||||
# Get current state
|
||||
stat = get_stat()
|
||||
|
||||
# Resample
|
||||
time.sleep(5)
|
||||
stat2 = get_stat()
|
||||
|
||||
try:
|
||||
save_stat(stat)
|
||||
except IOError, err:
|
||||
pyplug.exit(unknown, "Unable to save cpu statistics: %s" % err)
|
||||
|
||||
|
||||
# Calculate averages for the last few seconds
|
||||
current_averages = diff_stats(stat2, stat)
|
||||
for pos in range(len(current_averages)):
|
||||
pyplug.add_metric(label=stat_fields[pos+1],
|
||||
value=current_averages[pos],
|
||||
uom="%")
|
||||
|
||||
# Calculate averages from last run
|
||||
if old_stat:
|
||||
last_run_avg = diff_stats(old_stat, stat)
|
||||
for pos in range(len(current_averages)):
|
||||
pyplug.add_metric(label=stat_fields[pos+1]+"_avg",
|
||||
value=last_run_avg[pos],
|
||||
uom="%")
|
||||
|
||||
pyplug.add_status(ok)
|
||||
pyplug.add_summary("CPU load %.2f%%" % (100.0 - current_averages[3]))
|
||||
pyplug.exit()
|
||||
|
||||
def diff_stats(older, newer):
|
||||
"""Calculates the percentage between two stat arrays"""
|
||||
if older:
|
||||
diff = []
|
||||
for pos in range(len(newer)):
|
||||
diff.append(newer[pos] - older[pos])
|
||||
averages = calc_avg(diff)
|
||||
else:
|
||||
averages = calc_avg(newer)
|
||||
|
||||
return averages
|
||||
|
||||
|
||||
def remove_stale_state():
|
||||
"""Removes the last state file if we have rebooted"""
|
||||
|
||||
try:
|
||||
state_mtime = os.stat("/var/lib/nagios-okplugin/check_cpu").st_mtime
|
||||
boot_time = os.stat("/proc/1").st_mtime
|
||||
if state_mtime < boot_time:
|
||||
print "unlinking"
|
||||
os.unlink("/var/lib/nagios-okplugin/check_cpu")
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
return state_mtime
|
||||
|
||||
def calc_avg(stat):
|
||||
"""Calculates the average of each int in array"""
|
||||
stat_sum = sum(stat)
|
||||
avg = []
|
||||
for pos in range(len(stat)):
|
||||
avg.append(float(stat[pos]) / stat_sum * 100)
|
||||
return avg
|
||||
|
||||
def get_stat():
|
||||
"""Fetches the first line from /proc/stat and returns the numbers"""
|
||||
stat_fh = open("/proc/stat")
|
||||
return [int(pos) for pos in stat_fh.readline().split()[1:]]
|
||||
|
||||
def get_saved_stat():
|
||||
"""Fetches information about the last run to be able to do averages"""
|
||||
|
||||
remove_stale_state()
|
||||
try:
|
||||
stat_fh = open("/var/lib/nagios-okplugin/check_cpu")
|
||||
except IOError:
|
||||
return None
|
||||
return [int(pos) for pos in stat_fh.readline().split()[1:]]
|
||||
|
||||
def save_stat(stat):
|
||||
"""Save statistics to compare to in next run"""
|
||||
stat_fh = open("/var/lib/nagios-okplugin/check_cpu", "w")
|
||||
|
||||
stat_fh.write("cpu " + " ".join([str(pos) for pos in stat]) + "\n")
|
||||
stat_fh.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim: sts=4 expandtab
|
@ -2,7 +2,7 @@
|
||||
|
||||
Summary: A Nagios plugin to check uptime of a remote host via NRPE
|
||||
Name: nagios-okplugin-check_uptime
|
||||
Version: 1.0.1
|
||||
Version: 1.0.2
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2+
|
||||
Group: Applications/System
|
||||
@ -41,6 +41,9 @@ rm -rf %{buildroot}
|
||||
/etc/nrpe.d/check_uptime.cfg
|
||||
|
||||
%changelog
|
||||
* Mon Dec 30 2013 Tomas Edwardsson <tommi@tommi.org> 1.0.2-1
|
||||
- Updated tag for build with newer tito
|
||||
|
||||
* Mon Mar 12 2012 Pall Sigurdsson <palli@opensource.is> 1.0.1-1
|
||||
- new package built with tito
|
||||
|
||||
|
46
nagios-okplugin-common/nagios-okplugin-common.spec
Normal file
46
nagios-okplugin-common/nagios-okplugin-common.spec
Normal file
@ -0,0 +1,46 @@
|
||||
%define debug_package %{nil}
|
||||
|
||||
Summary: A common package for the okplugin suite
|
||||
Name: nagios-okplugin-common
|
||||
Version: 1.2
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2+
|
||||
Group: Applications/System
|
||||
URL: https://github.com/opinkerfi/nagios-plugins/
|
||||
Source0: https://github.com/opinkerfi/nagios-plugins/archive/%{name}-%{version}-%{release}.tar.gz
|
||||
Requires: nrpe
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
Packager: Tomas Edwardsson <tommi@ok.is>
|
||||
BuildArch: noarch
|
||||
|
||||
%description
|
||||
Common utilities for okplugins
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
mkdir -m 0770 -p %{buildroot}%{_sharedstatedir}/nagios-okplugin
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%post
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%dir %attr(0770, nrpe, nrpe) %{_sharedstatedir}/nagios-okplugin
|
||||
|
||||
%changelog
|
||||
* Mon Jan 20 2014 Tomas Edwardsson <tommi@tommi.org> 1.2-1
|
||||
-
|
||||
|
||||
* Mon Jan 20 2014 Tomas Edwardsson <tommi@tommi.org> 1.1-1
|
||||
- new package built with tito
|
||||
|
||||
* Mon Jan 20 2014 Tomas Edwardsson <tommi@tommi.org> 1.0-1
|
||||
- Initial build
|
1
rel-eng/packages/nagios-okplugin-check_cpu
Normal file
1
rel-eng/packages/nagios-okplugin-check_cpu
Normal file
@ -0,0 +1 @@
|
||||
1.1-1 check_cpu.py/
|
@ -1 +1 @@
|
||||
1.0.1-1 check_uptime/
|
||||
1.0.2-1 check_uptime/
|
||||
|
1
rel-eng/packages/nagios-okplugin-common
Normal file
1
rel-eng/packages/nagios-okplugin-common
Normal file
@ -0,0 +1 @@
|
||||
1.2-1 nagios-okplugin-common/
|
@ -1,3 +1,33 @@
|
||||
# Fedora FC20
|
||||
[test-fc20-x86_64]
|
||||
releaser = tito.release.YumRepoReleaser
|
||||
builder = tito.builder.MockBuilder
|
||||
builder.mock = fedora-20-x86_64
|
||||
builder.test = 1
|
||||
rsync = tito@opensource.is:/var/www/sites/opensource.ok.is/repo/testing/fedora20/x86_64/
|
||||
|
||||
|
||||
[production-fc20-x86_64]
|
||||
releaser = tito.release.YumRepoReleaser
|
||||
builder = tito.builder.MockBuilder
|
||||
builder.mock = fedora-20-x86_64
|
||||
rsync = tito@opensource.is:/var/www/sites/opensource.ok.is/repo/fedora20/x86_64/
|
||||
|
||||
# Fedora FC19
|
||||
[test-fc19-x86_64]
|
||||
releaser = tito.release.YumRepoReleaser
|
||||
builder = tito.builder.MockBuilder
|
||||
builder.mock = fedora-19-x86_64
|
||||
builder.test = 1
|
||||
rsync = tito@opensource.is:/var/www/sites/opensource.ok.is/repo/testing/fedora19/x86_64/
|
||||
|
||||
|
||||
[production-fc19-x86_64]
|
||||
releaser = tito.release.YumRepoReleaser
|
||||
builder = tito.builder.MockBuilder
|
||||
builder.mock = fedora-19-x86_64
|
||||
rsync = tito@opensource.is:/var/www/sites/opensource.ok.is/repo/fedora19/x86_64/
|
||||
|
||||
# Fedora FC18
|
||||
[test-fc18-x86_64]
|
||||
releaser = tito.release.YumRepoReleaser
|
||||
|
Loading…
Reference in New Issue
Block a user