Cleanup config.nodes_of
[check_mk.git] / checks / aws_ec2
blob668b06b0a834f01aee0d04ad54d7f4b3451cd44f
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 EC2DefaultItemName = "Summary"
30 def parse_aws_ec2(info):
31 metrics = _extract_aws_metrics_by_labels([
32 'CPUCreditUsage',
33 'CPUCreditBalance',
34 'CPUUtilization',
35 'DiskReadOps',
36 'DiskWriteOps',
37 'DiskReadBytes',
38 'DiskWriteBytes',
39 'NetworkIn',
40 'NetworkOut',
41 'StatusCheckFailed_Instance',
42 'StatusCheckFailed_System',
43 ], parse_aws(info))
44 # We get exactly one entry: {INST-ID: METRICS}
45 # INST-ID is the piggyback host name
46 try:
47 inst_metrics = metrics.values()[-1]
48 except IndexError:
49 inst_metrics = {}
50 return {EC2DefaultItemName: inst_metrics}
53 # .--status check--------------------------------------------------------.
54 # | _ _ _ _ |
55 # | ___| |_ __ _| |_ _ _ ___ ___| |__ ___ ___| | __ |
56 # | / __| __/ _` | __| | | / __| / __| '_ \ / _ \/ __| |/ / |
57 # | \__ \ || (_| | |_| |_| \__ \ | (__| | | | __/ (__| < |
58 # | |___/\__\__,_|\__|\__,_|___/ \___|_| |_|\___|\___|_|\_\ |
59 # | |
60 # +----------------------------------------------------------------------+
61 # | main check |
62 # '----------------------------------------------------------------------'
65 def check_aws_ec2_status_check(item, params, parsed):
66 # item is None, therefore we cannot use @get_parsed_item_data
67 metrics = parsed.get(EC2DefaultItemName)
68 if metrics is None:
69 return
71 for title, key in [
72 ('System', 'StatusCheckFailed_System'),
73 ('Instance', 'StatusCheckFailed_Instance'),
75 state, state_readable =\
76 _get_status_check_readable(metrics[key])
77 yield state, "%s: %s" % (title, state_readable)
80 def _get_status_check_readable(value):
81 if int(value) == 0:
82 return 0, "passed"
83 return 2, "failed"
86 check_info['aws_ec2'] = {
87 'parse_function': parse_aws_ec2,
88 'inventory_function': lambda p: inventory_aws_generic_single(p[
89 EC2DefaultItemName], ['StatusCheckFailed_System', 'StatusCheckFailed_Instance']),
90 'check_function': check_aws_ec2_status_check,
91 'service_description': 'AWS/EC2 Status Check',
92 'includes': ['aws.include'],
96 # .--CPU credits---------------------------------------------------------.
97 # | ____ ____ _ _ _ _ _ |
98 # | / ___| _ \| | | | ___ _ __ ___ __| (_) |_ ___ |
99 # | | | | |_) | | | | / __| '__/ _ \/ _` | | __/ __| |
100 # | | |___| __/| |_| | | (__| | | __/ (_| | | |_\__ \ |
101 # | \____|_| \___/ \___|_| \___|\__,_|_|\__|___/ |
102 # | |
103 # '----------------------------------------------------------------------'
106 def check_aws_ec2_cpu_credits(item, params, parsed):
107 # item is None, therefore we cannot use @get_parsed_item_data
108 metrics = parsed.get(EC2DefaultItemName)
109 if metrics is None:
110 return
112 yield 0, "Usage: %.2f" % metrics['CPUCreditUsage']
113 warn, crit = params["balance_levels_lower"]
114 yield check_levels(
115 metrics['CPUCreditBalance'],
116 "aws_cpu_credit_balance", (None, None, warn, crit),
117 human_readable_func=lambda x: "%.2f" % x,
118 infoname='Balance')
121 check_info['aws_ec2.cpu_credits'] = {
122 'inventory_function': lambda p: inventory_aws_generic_single(p[
123 EC2DefaultItemName], ['CPUCreditUsage', 'CPUCreditBalance']),
124 'check_function': check_aws_ec2_cpu_credits,
125 'service_description': 'AWS/EC2 CPU Credits',
126 'group': 'aws_ec2_cpu_credits',
127 'includes': ['aws.include'],
128 'default_levels_variable': 'aws_cpu_credits',
129 'has_perfdata': True,
133 # .--CPU utilization-----------------------------------------------------.
134 # | ____ ____ _ _ _ _ _ _ _ _ |
135 # | / ___| _ \| | | | _ _| |_(_) (_)______ _| |_(_) ___ _ __ |
136 # | | | | |_) | | | | | | | | __| | | |_ / _` | __| |/ _ \| '_ \ |
137 # | | |___| __/| |_| | | |_| | |_| | | |/ / (_| | |_| | (_) | | | | |
138 # | \____|_| \___/ \__,_|\__|_|_|_/___\__,_|\__|_|\___/|_| |_| |
139 # | |
140 # '----------------------------------------------------------------------'
142 factory_settings['aws_ec2_cpu_util_default_levels'] = {
143 "levels": (90.0, 95.0),
147 def check_aws_ec2_cpu_util(item, params, parsed):
148 # item is None, therefore we cannot use @get_parsed_item_data
149 metrics = parsed.get(EC2DefaultItemName)
150 if metrics is None:
151 return
152 return check_cpu_util(metrics['CPUUtilization'], params, time.time())
155 check_info['aws_ec2.cpu_util'] = {
156 'inventory_function': lambda p: inventory_aws_generic_single(p[EC2DefaultItemName],
157 ['CPUUtilization']),
158 'check_function': check_aws_ec2_cpu_util,
159 'service_description': 'AWS/EC2 CPU utilization',
160 'group': 'cpu_utilization',
161 'default_levels_variable': 'aws_ec2_cpu_util_default_levels',
162 'has_perfdata': True,
163 'includes': ['cpu_util.include', 'aws.include'],
167 # .--disk IO-------------------------------------------------------------.
168 # | _ _ _ ___ ___ |
169 # | __| (_)___| | __ |_ _/ _ \ |
170 # | / _` | / __| |/ / | | | | | |
171 # | | (_| | \__ \ < | | |_| | |
172 # | \__,_|_|___/_|\_\ |___\___/ |
173 # | |
174 # '----------------------------------------------------------------------'
177 @get_parsed_item_data
178 def check_aws_ec2_disk_io(item, params, metrics):
179 now = time.time()
180 disks = {
181 item: {
182 "read_ios": get_rate("aws_ebs_disk_io_read_ios.%s" % item, now, metrics['DiskReadOps']),
183 "write_ios": get_rate("aws_ebs_disk_io_write_ios.%s" % item, now,
184 metrics['DiskWriteOps']),
185 "read_throughput": get_rate("aws_ebs_disk_io_read_throughput.%s" % item, now,
186 metrics['DiskReadBytes']),
187 "write_throughput": get_rate("aws_ebs_disk_io_write_throughput.%s" % item, now,
188 metrics['DiskWriteBytes']),
191 return check_diskstat_dict(item, params, disks)
194 check_info['aws_ec2.disk_io'] = {
195 'inventory_function': lambda p:\
196 inventory_aws_generic(p, ['DiskReadOps', 'DiskWriteOps', 'DiskReadBytes', 'DiskWriteBytes']),
197 'check_function': check_aws_ec2_disk_io,
198 'service_description': 'AWS/EC2 Disk IO %s',
199 'includes': ['diskstat.include', 'aws.include'],
200 'group': 'diskstat',
201 'has_perfdata': True,
205 # .--network IO----------------------------------------------------------.
206 # | _ _ ___ ___ |
207 # | _ __ ___| |___ _____ _ __| | __ |_ _/ _ \ |
208 # | | '_ \ / _ \ __\ \ /\ / / _ \| '__| |/ / | | | | | |
209 # | | | | | __/ |_ \ V V / (_) | | | < | | |_| | |
210 # | |_| |_|\___|\__| \_/\_/ \___/|_| |_|\_\ |___\___/ |
211 # | |
212 # '----------------------------------------------------------------------'
215 @get_parsed_item_data
216 def check_aws_ec2_network_io(item, params, metrics):
217 interfaces = [[
218 "0",
219 item,
220 "1",
222 "1",
223 metrics['NetworkIn'],
229 metrics['NetworkOut'],
236 item,
239 return check_if_common_single(item, params, interfaces)
242 check_info['aws_ec2.network_io'] = {
243 'inventory_function': lambda p:\
244 inventory_aws_generic(p, ['NetworkIn', 'NetworkOut']),
245 'check_function': check_aws_ec2_network_io,
246 'service_description': 'AWS/EC2 Network IO %s',
247 'includes': ['aws.include', 'if.include'],
248 'default_levels_variable': "if_default_levels",
249 'group': 'if',
250 'has_perfdata': True,