Amazon Redshift ULM アプリケーションのログとメトリクスの収集
このページでは、Amazon Redshift ULM アプリケーションでログとメトリクスの収集をセットアップする方法について説明します。
ステップ 1.Source Category の計画
Amazon Redshift 用のログ Source とメトリクス Source を設定する前に、それぞれに割り当てる Source Category を決める必要があります。 次のように、階層的なアプローチを採用すると、検索の実行時にワイルドカードを利用できます。例:
- Amazon Redshift 監査ログ収集用の AWS S3 Source には、Source Category として
AWS/Redshift/Audit
を指定できます。 - Redshift CloudTrail イベント用の AWS CloudTrail Source には、Source Category として
AWS/CloudTrail
を指定できます。 - Redshift イベント用の AWS CloudWatch Source には、Source Category として
AWS/Metric/Redshift
を指定できます。
ステップ 2.Amazon Redshift 監査ログの有効化
このステップでは、Amazon Redshift の監査ログを有効にします。
- データベース監査ログを有効化します。背景情報については、「Database Audit Logging (データベース監査ログ)」を参照してください。監査ログを有効にする方法については、「Configuring Auditing Using the Console (コンソールを使用した監査の設定)」を参照してください。
- ユーザ アクティビティ ログを有効化します。ユーザ アクティビティ ログを使用する場合は、
enable_user_activity_logging
データベース パラメータも有効化する必要があります。監査ログ機能のみを有効化して関連するパラメータを有効化しないと、データベース監査ログには接続ログとユーザ ログのみが記録され、ユーザ アクティビティ ログは記録されません。enable_user_activity_logging
パラメータは、デフォルトでは無効 (false) で、これを true に設定することでユーザ アクティビティ ログを有効化できます。詳細については、「Amazon Redshift Parameter Groups (Amazon Redshift のパラメータ グループ)」を参照してください。必要なパラメータ値で新しいパラメータ グループを作成し、新しいパラメータ グループを使用するようにクラスタ設定を修正します。既存のパラメータ グループを使用する場合は、AWS CLI で修正できます。詳細については、「Amazon Redshift Parameter Groups (Amazon Redshift のパラメータ グループ)」を参照してください。
ステップ 3: Amazon Redshift の監査ログを収集するための AWS S3 Source の設定
- Hosted Collector を設定します。
- Hosted Collector に AWS S3 Source を追加します。
- Name (名前): 新しい Source に表示する名前を入力します。
- Description (説明): 説明 (省略可能) を入力します。
- S3 Region (S3 リージョン)。Redshift 監査ログ S3 バケットの Amazon リージョンを選択します。
- Bucket Name (バケット名)。Redshift 監査ログ S3 バケットの名前を正確に入力します。
- Path Expression (パス式)。収集する S3 オブジェクトに一致する文字列を入力します。この文字列では、ワイルドカードを 1 つ使用できます。(先頭にスラッシュを付けないでください。「Amazon のパス式」参照。)
- Source Category: AWS/Redshift/Audit
- Access Key and Secret Key (アクセス キーとシークレット キー)。Amazon のアクセス キーとシークレット キーを入力します。
- Scan Interval (スキャン間隔): デフォルトの 5 分を使用します。または、Sumo Logic が S3 バケットをスキャンして新しいデータがないか確認する間隔を入力します。
- Enable Timestamp Parsing (タイムスタンプ parse の有効化)。チェックボックスをオンにします。
- Time Zone (タイム ゾーン): [Ignore time zone from log file and instead use (ログ ファイルのタイムゾーンを無視して、次を使用します)] を選択して、[UTC] を選択します。
- Timestamp Format (タイムスタンプ形式)。[Automatically detect the format (自動的に形式を検出)] を選択します。
- Enable Multiline Processing (複数行の処理の有効化)。チェックボックスをオンにして [Infer Boundaries (境界の推測)] を選択します。
- [Save (保存)] をクリックします。
ステップ 4.Redshift CloudTrail イベント用の AWS CloudTrail Source の設定
- Hosted Collector を設定します。
- Hosted Collector に AWS CloudTrail Source を追加します。
- Name (名前): 新しい Source に表示する名前を入力します。
- Description (説明): 説明 (省略可能) を入力します。
- S3 Region (S3 リージョン)。CloudTrail Redshift S3 バケットの Amazon リージョンを選択します。
- Bucket Name (バケット名)。CloudTrail Redshift S3 バケットの名前を正確に入力します。
- Path Expression (パス式)。収集する S3 オブジェクトに一致する文字列を入力します。この文字列では、ワイルドカードを 1 つ使用できます。(先頭にスラッシュを付けないでください。「Amazon パス式」参照。) S3 バケット名はパスに含まれません。パス式を設定するときはバケット名を含めないでください。
- Source Category: Source Category を入力します。例: AWS/Cloudtrail
- Access Key and Secret Key (アクセス キーとシークレット キー)。Amazon のアクセス キーとシークレット キーを入力します。
- Scan Interval (スキャン間隔): デフォルトの 5 分を使用します。または、Sumo Logic が S3 バケットをスキャンして新しいデータがないか確認する間隔を入力します。
- Enable Timestamp Parsing (タイムスタンプ parse の有効化)。チェックボックスをオンにします。
- Time Zone (タイム ゾーン): [Ignore time zone from log file and instead use (ログ ファイルのタイムゾーンを無視して、次を使用します)] を選択して、[UTC] を選択します。
- Timestamp Format (タイムスタンプ形式)。[Automatically detect the format (自動的に形式を検出)] を選択します。
- Enable Multiline Processing (複数行の処理の有効化)。チェックボックスをオンにして [Infer Boundaries (境界を推測する)] を選択します。
- [Save (保存)] をクリックします。
ステップ 5: Redshift メトリクス用の AWS CloudWatch Source の設定
- Hosted Collector を設定します。
- AWS CloudTrail Source を設定します。
- Name (名前): 新しい Source に表示する名前を入力します。
- Description (説明): 説明 (省略可能) を入力します。
- Regions (リージョン)。Amazon Redshift の Amazon リージョンを選択します。
- Namespaces (名前空間)。[AWS/Redshift] を選択します。
- Source Category: Source Category を入力します。例: AWS/Metric/Redshift
- Access Key and Secret Key (アクセス キーとシークレット キー)。Amazon のアクセス キーと秘密鍵を入力します。
- Scan Interval (スキャン間隔): Sumo Logic が CloudWatch Source をスキャンして新しいデータがないか確認する間隔として、デフォルトの 5 分を使用するか、または別の間隔を入力します。
- [Save (保存)] をクリックします。
ログ メッセージのサンプル
Amazon Redshift 接続監査ログのサンプル
dir="ltr">authenticated |Mon, 21 May 2018 01:38:01:601|::ffff:127.0.0.1 |32828 |15523|dev |rdsdb |password |0| | |0| | | |dir="ltr">authentication failure |Mon, 21 May 2018 05:20:10:123|::ffff:10.11.12.16 |66790 |98031|vendor |himanshu |password |0|TLSv1.2 |ECDHE-RSA-AES256-SHA384 |0| | | |
Amazon Redshift ユーザ アクティビティ監査ログのサンプル
'2018-05-21T06:00:09Z UTC [ db=prod_sales user=duc pid=99753 userid=95 xid=6728324 ]' LOG: create table SumoProdbackUp.organization as (select * from SumoProd.simpleuser) '2018-05-21T06:00:09Z UTC [ db=vendor user=ankit pid=36616 userid=53 xid=2956702 ]' LOG: DELETE FROM SumoProd.employee WHERE id = 38; '2018-05-21T06:20:09Z UTC [ db=dev user=himanshu pid=64458 userid=35 xid=5143208 ]' LOG: drop user testuser3
Amazon CloudTrail Redshift ログのサンプル
dir="ltr">{"eventVersion":"1.04","userIdentity":{"type":"IAMUser","principalId":"AIDA1234567890WUABG5Q", "arn":"arn:aws:iam::951234567838:user/Nitin","accountId":"951234567838","accessKeyId":"ASIA12345678UPV5IWTQ", "userName":"Nitin","sessionContext":{"attributes":{"mfaAuthenticated":"true","creationDate":"2018-05-11T14:08:12Z"}}, "invokedBy":"signin.amazonaws.com"},"eventTime":"2018-05-11T17:37:06Z","eventSource":"redshift.amazonaws.com","eventName": "RebootCluster","awsRegion":"us-west-1","sourceIPAddress":"114.140.11.57","userAgent":"signin.amazonaws.com","requestParameters": {"clusterIdentifier":"sumologicdevbi"},"responseElements":{"nodeType":"dc2.large","preferredMaintenanceWindow":"mon:10:00-mon:10:30", "clusterStatus":"rebooting","clusterCreateTime":"Mar 13, 2018 4:49:17 AM","vpcId":"vpc-4333942c","enhancedVpcRouting":false, "endpoint":{"port":5439,"address":"sumologicdev-bi.cklqobrc1234.us-west-1.redshift.amazonaws.com"},"masterUsername": "sumologicdevbi","clusterSecurityGroups":[],"pendingModifiedValues":{},"dBName":"sumologicdevbi","availabilityZone": "us-west-1c","clusterVersion":"1.0","encrypted":false,"publiclyAccessible":true,"tags":[],"clusterParameterGroups": [{"clusterParameterStatusList":[{"parameterApplyStatus":"pending-reboot","parameterName":"spectrum_enable_enhanced_vpc_routing"}, {"parameterApplyStatus":"pending-reboot","parameterName":"enable_user_activity_logging"},{"parameterApplyStatus":"pending-reboot", "parameterName":"max_cursor_result_set_size"},{"parameterApplyStatus":"pending-reboot","parameterName":"query_group"}, {"parameterApplyStatus":"pending-reboot","parameterName":"datestyle"},{"parameterApplyStatus":"pending-reboot","parameterName": "extra_float_digits"},{"parameterApplyStatus":"pending-reboot","parameterName":"search_path"},{"parameterApplyStatus":"pending-reboot", "parameterName":"statement_timeout"},{"parameterApplyStatus":"pending-reboot","parameterName":"wlm_json_configuration"},{"parameterApplyStatus": "pending-reboot","parameterName":"require_ssl"},{"parameterApplyStatus":"pending-reboot","parameterName":"use_fips_ssl"}],"parameterGroupName": "auditclusterparamgroup","parameterApplyStatus":"pending-reboot"}],"allowVersionUpgrade":true,"automatedSnapshotRetentionPeriod":1, "numberOfNodes":1,"vpcSecurityGroups":[{"status":"active","vpcSecurityGroupId":"sg-1234d441"}],"iamRoles":[{"iamRoleArn": "arn:aws:iam::951234567838:role/RedshiftS3ReadOnly","applyStatus":"in-sync"}],"clusterIdentifier":"sumologicdevbi", "clusterSubnetGroupName":"redshift"},"requestID":"ec7759c5-5541-11e8-947b-614ed503d341","eventID":"4b0a0389-b04e-4553-8946-e71d0c3cfd46", "eventType":"AwsApiCall","recipientAccountId":"951234567838"}
クエリのサンプル
上位ユーザ
dir="ltr">_sourceCategory=*/AWS/Redshift/Audit LOG | parse regex "^\'(?<time>\d+\-\d+\-\d+T\d+:\d+:\d+Z \w+)\s+\[\s*(?<parameters>[^\]]+)\]\'\s+LOG:\s+(?<sqlstatement>[^;]*)" | parse field=parameters "db=* user=* pid=* userid=* xid=*" as dbName, username, pid, userid, xid nodrop | parse regex field = sqlstatement "^/\*(?:.|[\r\n])*?\*/\s+(?<command>\w+)\s*" nodrop | parse regex field = sqlstatement "^(?<command>\w+)\s*" nodrop | count as eventCount by username | top 10 username by eventCount, username asc