Skip to content

Commit a161335

Browse files
authored
Merge pull request #576 from cloudnull/nfs_check
[TURTLES-1547] Add check for NFS
2 parents a7724f5 + f375a62 commit a161335

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2018, Rackspace US, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
import shlex
19+
import subprocess
20+
21+
from maas_common import metric
22+
from maas_common import metric_bool
23+
from maas_common import print_output
24+
from maas_common import status_err
25+
from maas_common import status_ok
26+
27+
28+
def nfs_export_check():
29+
nfs_metrics = dict()
30+
31+
output = subprocess.check_output(
32+
shlex.split(
33+
"awk -F':' '/nfs/ {print $1}' /proc/mounts"
34+
)
35+
)
36+
nfs_mounts = output.splitlines()
37+
for mount in nfs_mounts:
38+
mount_metrics = nfs_metrics[mount] = {'exports': 0, 'online': False}
39+
try:
40+
exports = subprocess.check_output(
41+
shlex.split(
42+
"showmount --no-headers --exports {}".format(mount)
43+
)
44+
)
45+
except subprocess.CalledProcessError:
46+
mount_metrics['exports'] = 0
47+
else:
48+
mount_metrics['exports'] += len(exports.splitlines())
49+
50+
if mount_metrics['exports'] > 0:
51+
mount_metrics['online'] = True
52+
53+
return nfs_metrics
54+
55+
56+
if __name__ == '__main__':
57+
parser = argparse.ArgumentParser(description='Disk utilisation checks')
58+
parser.add_argument('--telegraf-output',
59+
action='store_true',
60+
default=False,
61+
help='Set the output format to telegraf')
62+
args = parser.parse_args()
63+
with print_output(print_telegraf=args.telegraf_output):
64+
nfs_system_check = nfs_export_check()
65+
66+
# If there are no returns for the nfs check or the status is ALL
67+
# online the check is marked as "OK".
68+
status = all([i['online'] for i in nfs_system_check.values()])
69+
if status:
70+
status_ok(m_name='nfs_check')
71+
else:
72+
status_err('The state of NFS connections is degraded',
73+
m_name='nfs_check')
74+
75+
# Generate a general purpose metric fot the operational state of NFS.
76+
metric_bool('nfs_all_online', status, m_name='nfs_check')
77+
78+
for key, value in nfs_system_check.items():
79+
# Generate a metric for the number of exports seen from a server.
80+
metric('nfs_{}_exports'.format(key),
81+
'uint32',
82+
value['exports'],
83+
'exports',
84+
m_name='nfs_check')
85+
86+
# Generate a metric for the given online or offline state.
87+
metric_bool('nfs_{}_online'.format(key),
88+
value['online'],
89+
m_name='nfs_check')

playbooks/maas-host-cdm.yml

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
group: "root"
4747
mode: "0644"
4848

49+
- name: Install nfs system checks
50+
template:
51+
src: "templates/rax-maas/nfs_check.yaml.j2"
52+
dest: "/etc/rackspace-monitoring-agent.conf.d/nfs_check--{{ inventory_hostname }}.yaml"
53+
owner: "root"
54+
group: "root"
55+
mode: "0644"
56+
4957
- name: Install memory Checks
5058
template:
5159
src: "templates/rax-maas/memory_check.yaml.j2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% from "templates/common/macros.jinja" import get_metadata with context %}
2+
{% set label = "nfs_check" %}
3+
{% set check_name = label+'--'+inventory_hostname %}
4+
type : agent.plugin
5+
label : "{{ check_name }}"
6+
period : "{{ maas_check_period_override[label] | default(maas_check_period) }}"
7+
timeout : "{{ maas_check_timeout_override[label] | default(maas_check_timeout) }}"
8+
disabled : "{{ (check_name | match(maas_excluded_checks_regex)) | ternary('true', 'false') }}"
9+
details :
10+
file : run_plugin_in_venv.sh
11+
args : ["{{ maas_plugin_dir }}/nfs_check.py"]
12+
timeout : {{ (maas_check_timeout_override[label] | default(maas_check_timeout) * 1000) }}
13+
{{ get_metadata(label).strip() }}
14+
{# Add extra metadata options with two leading white spaces #}
15+
alarms :
16+
nfs_all_online :
17+
label : nfs_all_online--{{ inventory_hostname }}
18+
notification_plan_id : "{{ maas_notification_plan_override[label] | default(maas_notification_plan) }}"
19+
disabled : {{ (('nfs_all_online--'+inventory_hostname) | match(maas_excluded_alarms_regex)) | ternary('true', 'false') }}
20+
criteria : |
21+
:set consecutiveCount={{ maas_alarm_local_consecutive_count }}
22+
if (metric["nfs_all_online"] != 1) {
23+
return new AlarmStatus(CRITICAL, "NFS status is degraded");
24+
}

0 commit comments

Comments
 (0)