2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 def parse_aws_s3(info
): # pylint: disable=function-redefined
29 parsed
= _extract_aws_metrics_by_labels([
41 "TotalRequestLatency",
45 "SelectReturnedBytes",
50 # .--requests------------------------------------------------------------.
52 # | _ __ ___ __ _ _ _ ___ ___| |_ ___ |
53 # | | '__/ _ \/ _` | | | |/ _ \/ __| __/ __| |
54 # | | | | __/ (_| | |_| | __/\__ \ |_\__ \ |
55 # | |_| \___|\__, |\__,_|\___||___/\__|___/ |
57 # '----------------------------------------------------------------------'
61 def check_aws_s3_requests(item
, params
, metrics
):
63 all_requests_rate
= get_rate('aws_s3_http_errors_all_requests.%s' % item
, now
,
64 metrics
['AllRequests'])
65 yield 0, 'Total: %s/s' % all_requests_rate
67 for key
, perf_key
, title
in [
68 ("GetRequests", "get_requests", "Get"),
69 ("PutRequests", "put_requests", "Put"),
70 ("DeleteRequests", "delete_requests", "Delete"),
71 ("HeadRequests", "head_requests", "Head"),
72 ("PostRequests", "post_requests", "Post"),
73 ("SelectRequests", "select_requests", "Select"),
74 ("ListRequests", "list_requests", "List"),
76 requests
= metrics
.get(key
)
80 requests_rate
= get_rate('aws_s3_%s.%s' % (perf_key
, item
), now
, requests
)
81 yield 0, '%s: %s/s' % (title
, requests_rate
), [(perf_key
, requests_rate
)]
84 requests_perc
= 100.0 * requests_rate
/ all_requests_rate
85 except ZeroDivisionError:
91 params
.get('levels_%s_perc' % perf_key
),
92 human_readable_func
=get_percent_human_readable
,
93 infoname
="%s of total requests" % title
)
96 check_info
['aws_s3_requests'] = {
97 'parse_function': parse_aws_s3
,
98 'inventory_function': lambda p
:\
99 inventory_aws_generic(p
, ['AllRequests']),
100 'check_function': check_aws_s3_requests
,
101 'service_description': 'AWS/S3 Requests %s',
102 'includes': ['aws.include'],
103 'has_perfdata': True,
104 'group': 'aws_s3_requests',
108 # .--HTTP errors---------------------------------------------------------.
109 # | _ _ _____ _____ ____ |
110 # | | | | |_ _|_ _| _ \ ___ _ __ _ __ ___ _ __ ___ |
111 # | | |_| | | | | | | |_) | / _ \ '__| '__/ _ \| '__/ __| |
112 # | | _ | | | | | | __/ | __/ | | | | (_) | | \__ \ |
113 # | |_| |_| |_| |_| |_| \___|_| |_| \___/|_| |___/ |
115 # '----------------------------------------------------------------------'
118 @get_parsed_item_data
119 def check_aws_s3_http_errors(item
, params
, metrics
):
121 request_rate
= get_rate('aws_s3_http_errors_all_requests', now
, metrics
['AllRequests'])
123 for http_errors_nr
in ["4", "5"]:
124 http_errors
= metrics
.get("%sxxErrors" % http_errors_nr
)
125 if http_errors
is None:
128 http_errors_rate
= get_rate('aws_s3_http_%sxx_errors' % http_errors_nr
, now
, http_errors
)
129 yield (0, '%s00-Errors: %s/s' % (http_errors_nr
, http_errors_rate
),
130 [('http_%sxx_rate' % http_errors_nr
, http_errors_rate
)])
133 http_errors_perc
= 100.0 * http_errors_rate
/ request_rate
134 except ZeroDivisionError:
139 'http_%sxx_perc' % http_errors_nr
,
140 params
.get('levels_http_%sxx_perc' % http_errors_nr
),
141 human_readable_func
=get_percent_human_readable
,
142 infoname
="%s00-Errors of total requests" % http_errors_nr
)
145 check_info
['aws_s3_requests.http_errors'] = {
146 'inventory_function': lambda p
:\
147 inventory_aws_generic(p
, ['AllRequests', '4xxErrors', '5xxErrors']),
148 'check_function': check_aws_s3_http_errors
,
149 'service_description': 'AWS/S3 HTTP Errors %s',
150 'includes': ['aws.include'],
151 'has_perfdata': True,
152 'group': 'aws_s3_http_errors',
156 # .--latency-------------------------------------------------------------.
158 # | | | __ _| |_ ___ _ __ ___ _ _ |
159 # | | |/ _` | __/ _ \ '_ \ / __| | | | |
160 # | | | (_| | || __/ | | | (__| |_| | |
161 # | |_|\__,_|\__\___|_| |_|\___|\__, | |
163 # '----------------------------------------------------------------------'
166 @get_parsed_item_data
167 def check_aws_s3_latency(item
, params
, metrics
):
169 metrics
['TotalRequestLatency'] / 1000.0,
170 'aws_request_latency',
171 params
.get('levels_latency'),
172 human_readable_func
=get_age_human_readable
,
173 infoname
="Total request latency")
175 first_byte_latency
= metrics
.get('FirstByteLatency')
176 if first_byte_latency
is not None:
177 yield 0, 'First byte latency: %s' % get_age_human_readable(first_byte_latency
/ 1000.0)
180 check_info
['aws_s3_requests.latency'] = {
181 'inventory_function': lambda p
:\
182 inventory_aws_generic(p
, ['TotalRequestLatency']),
183 'check_function': check_aws_s3_latency
,
184 'service_description': 'AWS/S3 Latency %s',
185 'includes': ['aws.include'],
186 'has_perfdata': True,
187 'group': 'aws_s3_latency',
191 # .--traffic stats-------------------------------------------------------.
193 # | | |_ _ __ __ _ / _|/ _(_) ___ ___| |_ __ _| |_ ___ |
194 # | | __| '__/ _` | |_| |_| |/ __| / __| __/ _` | __/ __| |
195 # | | |_| | | (_| | _| _| | (__ \__ \ || (_| | |_\__ \ |
196 # | \__|_| \__,_|_| |_| |_|\___| |___/\__\__,_|\__|___/ |
198 # '----------------------------------------------------------------------'
201 @get_parsed_item_data
202 def check_aws_s3_traffic_stats(item
, params
, metrics
):
203 for key
, title
, perf_key
in [
204 ("BytesDownloaded", "Downloads", "aws_s3_downloads"),
205 ("BytesUploaded", "Uploads", "aws_s3_uploads"),
207 bytes_
= metrics
[key
]
208 yield 0, '%s: %s' % (title
, get_bytes_human_readable(bytes_
)), [(perf_key
, bytes_
)]
211 check_info
['aws_s3_requests.traffic_stats'] = {
212 'inventory_function': lambda p
:\
213 inventory_aws_generic(p
, ['BytesDownloaded', 'BytesUploaded']),
214 'check_function': check_aws_s3_traffic_stats
,
215 'service_description': 'AWS/S3 Traffic Stats %s',
216 'includes': ['aws.include'],
217 'has_perfdata': True,
221 # .--select objects------------------------------------------------------.
223 # | ___ ___| | ___ ___| |_ ___ | |__ (_) ___ ___| |_ ___ |
224 # | / __|/ _ \ |/ _ \/ __| __| / _ \| '_ \| |/ _ \/ __| __/ __| |
225 # | \__ \ __/ | __/ (__| |_ | (_) | |_) | | __/ (__| |_\__ \ |
226 # | |___/\___|_|\___|\___|\__| \___/|_.__// |\___|\___|\__|___/ |
228 # '----------------------------------------------------------------------'
231 @get_parsed_item_data
232 def check_aws_s3_select_object(item
, params
, metrics
):
233 # In the agent we use "Sum" which means: bytes per period (300s)
234 for key
, title
, perf_key
in [
235 ("SelectScannedBytes", "Scanned", "aws_s3_select_object_scanned"),
236 ("SelectReturnedBytes", "Returned", "aws_s3_select_object_returned"),
238 select_bytes
= metrics
[key
]
239 yield 0, '%s: %s' % (title
, get_bytes_human_readable(select_bytes
)), [(perf_key
,
243 check_info
['aws_s3_requests.select_object'] = {
244 'inventory_function': lambda p
:\
245 inventory_aws_generic(p
, ['SelectScannedBytes', 'SelectReturnedBytes']),
246 'check_function': check_aws_s3_select_object
,
247 'service_description': 'AWS/S3 SELECT Object %s',
248 'includes': ['aws.include'],
249 'has_perfdata': True,