Module: check_mk
Branch: master
Commit: e55ad44f1a0c0fa9985af881ba28c2e3311db297
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e55ad44f1a0c0f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jan 14 12:56:08 2019 +0100
aws_costs_and_usage: Also display time period
Change-Id: Ie40156c75a9f88bce4f61cd24c802894c40de1ab
---
agents/special/agent_aws | 4 +++-
checkman/aws_costs_and_usage | 3 ++-
checkman/aws_costs_and_usage.per_service | 2 +-
checks/aws_costs_and_usage | 30 ++++++++++++++++++++----------
4 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index aac51c2..80b38bc 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -219,7 +219,7 @@ class CostsAndUsage(AWSSection):
now = time.time()
return self._client.get_cost_and_usage(
TimePeriod={
- 'Start': time.strftime(fmt, time.gmtime(now - self.period)),
+ 'Start': time.strftime(fmt, time.gmtime(now - self.interval)),
'End': time.strftime(fmt, time.gmtime(now)),
},
Granularity='DAILY',
@@ -840,6 +840,8 @@ class Glacier(AWSSection):
# | |
# '----------------------------------------------------------------------'
+# AWS eigener Monitoring service
+
class CloudTrail(AWSSection):
@property
diff --git a/checkman/aws_costs_and_usage b/checkman/aws_costs_and_usage
index b901ebb..d65d6b6 100644
--- a/checkman/aws_costs_and_usage
+++ b/checkman/aws_costs_and_usage
@@ -4,7 +4,8 @@ catalog: cloud/aws
license: GPL
distribution: check_mk
description:
- This check gives an overview over the unblended costs of AWS accounts.
+ This check gives an overview over the unblended costs of AWS accounts and
+ shows the costs of the last day.
To make this check work you have to configure the related special agent
{{Amazon Web Services (AWS)}}.
Upper levels are configurable; no default levels are set.
diff --git a/checkman/aws_costs_and_usage.per_service
b/checkman/aws_costs_and_usage.per_service
index ea46861..450125a 100644
--- a/checkman/aws_costs_and_usage.per_service
+++ b/checkman/aws_costs_and_usage.per_service
@@ -5,7 +5,7 @@ license: GPL
distribution: check_mk
description:
This check gives an overview over the unblended costs of each service
- configured in AWS accounts.
+ configured in AWS accounts and shows the costs of the last day.
To make this check work you have to configure the related special agent
{{Amazon Web Services (AWS)}}.
Upper levels are configurable; no default levels are set.
diff --git a/checks/aws_costs_and_usage b/checks/aws_costs_and_usage
index eb872c2..f59af24 100644
--- a/checks/aws_costs_and_usage
+++ b/checks/aws_costs_and_usage
@@ -32,7 +32,9 @@ AWSCostAndUageMetrics = [
def parse_aws_costs_and_usage(info):
parsed = {}
for row in parse_aws(info):
+ timeperiod = row['TimePeriod']['Start']
for group in row.get('Groups', []):
+ service_name = " ".join(group['Keys'])
for metric_name, metrics in group['Metrics'].iteritems():
try:
costs = float(metrics['Amount'])
@@ -40,7 +42,7 @@ def parse_aws_costs_and_usage(info):
except (KeyError, ValueError):
continue
else:
- parsed.setdefault(" ".join(group['Keys']), {})\
+ parsed.setdefault((timeperiod, service_name), {})\
.setdefault(metric_name, (costs, unit))
return parsed
@@ -64,17 +66,17 @@ def inventory_aws_costs_and_usage_summary(parsed):
def check_aws_costs_and_usage_summary(item, params, parsed):
amounts_by_metrics = collections.defaultdict(float)
- for metrics in parsed.itervalues():
+ for (timeperiod, _service_name), metrics in parsed.iteritems():
for title, metric_name, key, in AWSCostAndUageMetrics:
costs, unit = metrics[metric_name]
- amounts_by_metrics[(title, unit, key)] += costs
+ amounts_by_metrics[(timeperiod, title, unit, key)] += costs
- for (title, unit, key), costs in amounts_by_metrics.iteritems():
+ for (timeperiod, title, unit, key), costs in amounts_by_metrics.iteritems():
yield check_levels(
costs,
"aws_costs_%s" % key,
params.get('levels_%s' % key, (None, None)),
- infoname="Total %s %s" % (title, unit))
+ infoname="(%s) Total %s %s" % (timeperiod, title, unit))
check_info['aws_costs_and_usage'] = {
@@ -99,19 +101,27 @@ check_info['aws_costs_and_usage'] = {
def inventory_aws_costs_and_usage_per_service(parsed):
- for service_name in parsed.iterkeys():
+ for (_timeperiod, service_name) in parsed.iterkeys():
yield service_name, {}
-@get_parsed_item_data
-def check_aws_costs_and_usage_per_service(item, params, metrics):
+def check_aws_costs_and_usage_per_service(item, params, parsed):
+ data = None
+ timeperiod = None
+ for (timeperiod, service_name), metrics in parsed.iteritems():
+ if item == service_name:
+ data = metrics
+ break
+ if not data:
+ return
+
for title, metric_name, key in AWSCostAndUageMetrics:
- costs, unit = metrics[metric_name]
+ costs, unit = data[metric_name]
yield check_levels(
costs,
"aws_costs_%s" % key,
params.get('levels_%s' % key, (None, None)),
- infoname="%s %s" % (title, unit))
+ infoname="(%s) %s %s" % (timeperiod, title, unit))
check_info['aws_costs_and_usage.per_service'] = {