diff --git a/sandbox/monitor-aurora-with-grafana/1-create-bucket.sh b/sandbox/monitor-aurora-with-grafana/1-create-bucket.sh index 08e257c39..60e5b81ab 100755 --- a/sandbox/monitor-aurora-with-grafana/1-create-bucket.sh +++ b/sandbox/monitor-aurora-with-grafana/1-create-bucket.sh @@ -1,5 +1,7 @@ #!/bin/bash BUCKET_ID=$(dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n') BUCKET_NAME=aurora-monitoring-grafana-pi-$BUCKET_ID +AWS_PROFILE=dime-kkpfg-uat +AWS_REGION=ap-southeast-1 echo $BUCKET_NAME > bucket-name.txt -aws s3 mb s3://$BUCKET_NAME \ No newline at end of file +aws s3 mb s3://$BUCKET_NAME --region $AWS_REGION \ No newline at end of file diff --git a/sandbox/monitor-aurora-with-grafana/2-deploy.sh b/sandbox/monitor-aurora-with-grafana/2-deploy.sh index 3441546ae..e69c56064 100755 --- a/sandbox/monitor-aurora-with-grafana/2-deploy.sh +++ b/sandbox/monitor-aurora-with-grafana/2-deploy.sh @@ -2,7 +2,10 @@ set -eo pipefail ARTIFACT_BUCKET=$(cat bucket-name.txt) STACK_ID=$(dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n') +AWS_PROFILE=dime-kkpfg-uat +AWS_REGION=ap-southeast-1 echo aurora-monitoring-grafana-pi-$STACK_ID > stack-name.txt STACK=$(cat stack-name.txt) aws cloudformation package --template-file template.yml --s3-bucket $ARTIFACT_BUCKET --output-template-file out.yml -aws cloudformation deploy --template-file out.yml --stack-name $STACK --capabilities CAPABILITY_NAMED_IAM \ No newline at end of file +aws cloudformation deploy --template-file out.yml --stack-name $STACK --capabilities CAPABILITY_NAMED_IAM --region $AWS_REGION +echo "ok" \ No newline at end of file diff --git a/sandbox/monitor-aurora-with-grafana/bucket-name.txt b/sandbox/monitor-aurora-with-grafana/bucket-name.txt new file mode 100644 index 000000000..9561f94ec --- /dev/null +++ b/sandbox/monitor-aurora-with-grafana/bucket-name.txt @@ -0,0 +1 @@ +aurora-monitoring-grafana-pi-7a13ecf009e716e0 diff --git a/sandbox/monitor-aurora-with-grafana/function/local.py b/sandbox/monitor-aurora-with-grafana/function/local.py new file mode 100644 index 000000000..84fc8ca3f --- /dev/null +++ b/sandbox/monitor-aurora-with-grafana/function/local.py @@ -0,0 +1,167 @@ +""" +Purpose +Shows how to use lambda function to get Performance Insight metrics from Amazon Aurora and publish to CloudWatch +@mundabra +@sharajag +https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.UsingDashboard.AnalyzeDBLoad.AdditionalMetrics.PostgreSQL.html +""" + +from base64 import encode +import time +import boto3 +import os +import logging +import json +from botocore.exceptions import ClientError + +logger = logging.getLogger() +logger.setLevel(logging.INFO) + +pi_client = boto3.client('pi') +rds_client = boto3.client('rds') +cw_client = boto3.client('cloudwatch') +targetMetricNamespace = os.environ.get('TargetMetricNamespace') + +dbSliceGroup = { "db.sql_tokenized", "db.wait_event", "db.user", "db.host", "db", "db.sql"} #"db.application" "db.application" "db.session_type" + + +def lambda_handler(event, context): + # Get DB instances for which Performance Insights have been enabled + pi_instances = get_pi_instances() + logger.info('## PI Instances --> ') + pi_list = ' '.join(e for e in pi_instances) + logger.info('## PI Instances List--> %s', pi_list) + for instance in pi_instances: + logger.info('## pi start') + pi_response = get_db_resource_metrics(instance) + logger.info('## pi ready') + if pi_response: + logger.info('## pi send') + send_cloudwatch_data(pi_response) + + return { + 'statusCode': 200, + 'body': 'ok' + } + +# Get DB instances for which Performance Insights have been enabled +def get_pi_instances(): + dbInstancesResponse = rds_client.describe_db_instances() + + if dbInstancesResponse: + response = filter(lambda _: _.get('PerformanceInsightsEnabled', False), dbInstancesResponse['DBInstances']) + if response: + new_list = [] + for item in response: + logger.info("## instance : %s", item['DBInstanceIdentifier']) + logger.info("## instance DbiResourceId : %s", item['DbiResourceId']) + # if item['DBInstanceIdentifier'] == "dime-default-uat-db-cluster-1-20230224104457267000000003": + new_list.append(item['DbiResourceId']) + # logger.info("APPEND : %s", item['DBInstanceIdentifier']) + dbInstanceList = [str(item['DbiResourceId']) for item in response] + pi_list_internal = ' '.join(e for e in new_list) + # pi_list_internal = ' '.join(e for e in ["a", "b", "c"]) + logger.info('## PI Internal Instances List--> %s', pi_list_internal) + return new_list # dbInstanceList + return None + + +def get_db_resource_metrics(instance): + # Build metric query list + metric_queries = [] + for group in dbSliceGroup: + # The example specifies the metric of db.load.avg and a GroupBy of the top seven wait events + # https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.API.html#USER_PerfInsights.API.Examples.CounterMetrics + + logger.info('## metrics for group --> %s ', group) + metric_queries.append( + { + "Metric": "db.load.avg", + "GroupBy": + + { + "Group": group + } + } + ) + + if not metric_queries: + return None + + response = pi_client.get_resource_metrics( + ServiceType='RDS', + Identifier=instance, + StartTime= time.time() - 900, #15 mins + EndTime= time.time(), + PeriodInSeconds=60, + MetricQueries=metric_queries + ) + + logger.info(print(response['MetricList'])) + + return response + +def str_encode(string): + encoded_str = string.encode("ascii","ignore") + return remove_non_ascii(encoded_str.decode()) + +def remove_non_ascii(string): + non_ascii = ascii(string) + return non_ascii + +def send_cloudwatch_data(pi_response): + metric_data = [] + for metric_response in pi_response['MetricList']: #dataoints and key + metric_dict = metric_response['Key'] #db.load.avg + metric_name = metric_dict['Metric'] + + is_metric_dimensions = False + formatted_dims = [] + if metric_dict.get('Dimensions'): + metric_dimensions = metric_response['Key']['Dimensions'] # return a dictionary + + for key in metric_dimensions: + metric_name = key.split(".")[1] + formatted_dims.append(dict(Name=key, Value=str_encode(metric_dimensions[key]))) + """ if key == "db.sql_tokenized.statement": + formatted_dims.append(dict(Name=key, Value=str_encode(metric_dimensions[key]))) + else: + formatted_dims.append(dict(Name=key, Value=str_encode(metric_dimensions[key]))) """ + + is_metric_dimensions = True + else: + metric_name = metric_name.replace("avg","") + + + for datapoint in metric_response['DataPoints']: + # We don't always have values from an instance + value = datapoint.get('Value', None) + + if value: + if is_metric_dimensions: + metric_data.append({ + 'MetricName': metric_name, + 'Dimensions': formatted_dims, + 'Timestamp': datapoint['Timestamp'], + 'Value': round(datapoint['Value'], 2) + }) + else: + metric_data.append({ + 'MetricName': metric_name, + 'Timestamp': datapoint['Timestamp'], + 'Value': round(datapoint['Value'], 2) + }) + + if metric_data: + logger.info('## sending data to cloduwatch...') + try: + cw_client.put_metric_data( + Namespace= targetMetricNamespace, + MetricData= metric_data) + except ClientError as error: + raise ValueError('The parameters you provided are incorrect: {}'.format(error)) + else: + logger.info('## NO Metric Data ##') + + +# dict_keys(['AlignedStartTime', 'AlignedEndTime', 'Identifier', 'MetricList', 'ResponseMetadata']) \ No newline at end of file diff --git a/sandbox/monitor-aurora-with-grafana/grafana/dashboard-nonprod.json b/sandbox/monitor-aurora-with-grafana/grafana/dashboard-nonprod.json new file mode 100644 index 000000000..5c5455bca --- /dev/null +++ b/sandbox/monitor-aurora-with-grafana/grafana/dashboard-nonprod.json @@ -0,0 +1,1175 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "description": "Amazon RDS - Performance Insights Dashboard", + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 371, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "datasource": { + "type": "prometheus", + "uid": "P2EC685C22B40CC2E" + }, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 28, + "panels": [], + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "P2EC685C22B40CC2E" + }, + "refId": "A" + } + ], + "title": "Top Load Events", + "type": "row" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 1 + }, + "id": 22, + "options": { + "displayMode": "gradient", + "minVizHeight": 10, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "max" + ], + "fields": "", + "values": false + }, + "showUnfilled": true + }, + "pluginVersion": "9.2.4", + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "user", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Top Users", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "bargauge" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 8 + }, + "id": 32, + "options": { + "displayMode": "gradient", + "minVizHeight": 10, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showUnfilled": true + }, + "pluginVersion": "9.2.4", + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "host", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Average" + } + ], + "title": "Top Host", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "bargauge" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 30, + "options": { + "displayMode": "gradient", + "minVizHeight": 10, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showUnfilled": true + }, + "pluginVersion": "9.2.4", + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "name", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Top Database", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "bargauge" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 14 + }, + "id": 20, + "options": { + "displayMode": "gradient", + "minVizHeight": 10, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": {} + }, + "pluginVersion": "9.2.4", + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "sql_tokenized", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sql": { + "from": { + "property": { + "name": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "type": "string" + }, + "type": "property" + }, + "groupBy": { + "expressions": [ + { + "property": { + "name": "db.sql_tokenized.statement", + "type": "string" + }, + "type": "groupBy" + } + ], + "type": "and" + }, + "limit": 10, + "orderBy": { + "name": "AVG", + "type": "function" + }, + "orderByDirection": "DESC", + "select": { + "name": "AVG", + "parameters": [ + { + "name": "sql_tokenized", + "type": "functionParameter" + } + ], + "type": "function" + } + }, + "sqlExpression": "SELECT AVG(sql_tokenized) FROM \"/AuroraMonitoringGrafana/PerformanceInsightMetrics\" GROUP BY \"db.sql_tokenized.statement\" ORDER BY AVG() DESC LIMIT 10", + "statistic": "Average" + } + ], + "title": "Top SQL", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "bargauge" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 14 + }, + "id": 24, + "options": { + "displayMode": "gradient", + "minVizHeight": 10, + "minVizWidth": 0, + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "max" + ], + "fields": "", + "values": false + }, + "showUnfilled": true + }, + "pluginVersion": "9.2.4", + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "wait_event", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Top Wait event", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "(.*)", + "renamePattern": "$1" + } + } + ], + "type": "bargauge" + }, + { + "collapsed": false, + "datasource": { + "type": "prometheus", + "uid": "P2EC685C22B40CC2E" + }, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 22 + }, + "id": 18, + "panels": [], + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "P2EC685C22B40CC2E" + }, + "refId": "A" + } + ], + "title": "Database load", + "type": "row" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 0, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 23 + }, + "id": 16, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": { + "db.sql_tokenized.statement": "*" + }, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "sql_tokenized", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Database load - SQL", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "timeseries" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 23 + }, + "id": 14, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "user", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Database load - User", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "timeseries" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 31 + }, + "id": 10, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "name", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Database", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "timeseries" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 31 + }, + "id": 12, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": { + "db.wait_event.name": "*" + }, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "wait_event", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Average" + } + ], + "title": "Wait event", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "(.*)", + "renamePattern": "$1" + } + } + ], + "type": "timeseries" + }, + { + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "description": "Performance Insight metrics", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 24, + "x": 0, + "y": 39 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "alias": "", + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "dimensions": {}, + "expression": "", + "id": "", + "label": "", + "matchExact": false, + "metricEditorMode": 0, + "metricName": "host", + "metricQueryType": 0, + "namespace": "/AuroraMonitoringGrafana/PerformanceInsightMetrics", + "period": "", + "queryMode": "Metrics", + "refId": "A", + "region": "default", + "sqlExpression": "", + "statistic": "Maximum" + } + ], + "title": "Database Load - Host", + "transformations": [ + { + "id": "renameByRegex", + "options": { + "regex": "'.*' '(.*)", + "renamePattern": "$1" + } + } + ], + "type": "timeseries" + } + ], + "refresh": "", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": true, + "text": "CloudWatch UAT", + "value": "CloudWatch UAT" + }, + "hide": 0, + "includeAll": false, + "label": "Data source", + "multi": false, + "name": "datasource", + "options": [], + "query": "cloudwatch", + "queryValue": "", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + }, + { + "current": { + "selected": false, + "text": "default", + "value": "default" + }, + "datasource": { + "type": "cloudwatch", + "uid": "${datasource}" + }, + "definition": "regions()", + "hide": 0, + "includeAll": false, + "label": "Region", + "multi": false, + "name": "region", + "options": [], + "query": "regions()", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "utc", + "title": "Amazon RDS - Performance Insights Dashboard", + "uid": "5hD_38I4k", + "version": 3, + "weekStart": "" + } \ No newline at end of file diff --git a/sandbox/monitor-aurora-with-grafana/out.yml b/sandbox/monitor-aurora-with-grafana/out.yml index 58bc0412c..ffef2ebf5 100644 --- a/sandbox/monitor-aurora-with-grafana/out.yml +++ b/sandbox/monitor-aurora-with-grafana/out.yml @@ -1,12 +1,12 @@ AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 -Description: An AWS Lambda application that calls the Lambda API for Performance Insights +Description: An AWS Lambda application that calls the API for Performance Insights metrics in Amazon Aurora. Parameters: TargetMetricNamespace: Type: String Default: /AuroraMonitoringGrafana/PerformanceInsightMetrics - Description: Target Amazon CloudWatch namespace where you want to public custom + Description: Target Amazon CloudWatch namespace where you want to publish custom metrics Resources: function: @@ -14,8 +14,8 @@ Resources: Properties: Handler: lambda_function.lambda_handler Runtime: python3.8 - CodeUri: s3://aurora-monitoring-grafana-pi-494d34597b3a4e8c/280c1b143b842055b23932598b88bee4 - Description: Publish Custom Cloudwatch Metrics for Performance Insights + CodeUri: s3://aurora-monitoring-grafana-pi-7a13ecf009e716e0/8039a1b901a8e822fcf5da14b3840485 + Description: Publish Custom Performance Insights metrics to Cloudwatch Timeout: 900 Environment: Variables: @@ -31,7 +31,7 @@ Resources: Schedule: Type: ScheduleV2 Properties: - ScheduleExpression: rate(15 minutes) - Name: TestScheduleV2Function - Description: Test schedule event + ScheduleExpression: rate(10 minutes) + Name: RunPIExtractorLambda + Description: Trigger Lambda execution on a schedule State: ENABLED diff --git a/sandbox/monitor-aurora-with-grafana/stack-name.txt b/sandbox/monitor-aurora-with-grafana/stack-name.txt index 47d5abda2..5f62bf31d 100644 --- a/sandbox/monitor-aurora-with-grafana/stack-name.txt +++ b/sandbox/monitor-aurora-with-grafana/stack-name.txt @@ -1 +1 @@ -aurora-monitoring-grafana-pi-30ad371077cfa584 +aurora-monitoring-grafana-pi-4a2d173826dd666c