LoginSignup
1
0

More than 3 years have passed since last update.

AuroraのActiveTransactionsをMetricsで取得する

Last updated at Posted at 2020-03-18

はじめに

DBの監視目的に CloudWatchMetricsを取得してみたが、 ActiveTransactions がそのままでは取得できなかったので取得できるようにしてみた。

ドキュメントを読む

Amazon Aurora メトリクス

メトリクス 説明 Applies to
ActiveTransactions Aurora データベースインスタンスで実行されている現在のトランザクションの 1 秒あたりの平均数。 Aurora では、このメトリクスはデフォルトで有効になっていません。この値の計測を開始するには、特定の DB インスタンス用の DB パラメータグループに innodb_monitor_enable='all' を設定します。

Amazon Aurora DB クラスターメトリクスのモニタリング
https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/AuroraUserGuide/Aurora.Monitoring.html

どうやらDBの設定を有効にしないといけないことが分かりました。

DB設定の有効化(間違い)

Auroraに接続し設定を有効にします。
MuSQL 5.6.17のinnodb_metricsを有効にしてみる を参考に、実際にDBに接続して設定してみます。

$ mysql -h hogehoge.ap-northeast-1.rds.amazonaws.com -P 3306 -u admin -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET GLOBAL innodb_monitor_enable = 'all';
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation

adminで実行しているのに権限がない…だと?

AWSコンソール上で有効化

どうやらAuroraはコンソール上でパラメータを設定しないといけないようです。(AWSCLIでもいける?)

パラメータグループの作成

RDS作成時のデフォルトのパラメータは変更できないと怒られたので新しくパラメータグループを作ります。
スクリーンショット 2020-03-18 9.49.09.png

公式に 『DBパラメータグループに』 と指定があるので、タイプは DB Parameter Group にします。
スクリーンショット 2020-03-18 10.03.33.png

作成したパラメータグループの編集ボタンを押すと、パラメータがたくさん表示されます。
検索項目に変更したいパラメータを入力すると絞り込めます。
スクリーンショット 2020-03-18 10.04.20.png

パラメータの編集で値を入れて保存を押します。
スクリーンショット 2020-03-18 10.04.52.png

RDSの設定変更

作ったパラメータグループをDBインスタンスのパラメータグループに変更します。

スクリーンショット 2020-03-18 10.13.30.png

ActiveTransactionsを取得してみる

無事、 ActiveTransactions を取得することができました。

$ aws cloudwatch get-metric-statistics --region ap-northeast-1 --period 300 \
>  --namespace "AWS/RDS" \
>  --dimensions "Name=DBClusterIdentifier,Value=hogehoge-db-cluster" \
>  --metric-name "ActiveTransactions" \
>  --statistics "Average" \
>  --start-time `date --iso-8601=seconds --date '5 minutes ago'` \
>  --end-time `date --iso-8601=seconds --date '0 minutes ago'` \
>  --endpoint-url "https://hogehoge.ap-northeast-1.amazonaws.com"
{
    "Datapoints": [
        {
            "Timestamp": "2020-03-18T01:41:00Z", 
            "Average": 0.28497748183989613, 
            "Unit": "Count/Second"
        }
    ], 
    "Label": "ActiveTransactions"
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0