Classic Load Balancer 로그 쿼리 - Amazon Athena

Classic Load Balancer 로그 쿼리

Classic Load Balancer 로그를 사용하여 Elastic Load Balancing 인스턴스 및 백엔드 애플리케이션과의 송수신 트래픽 패턴을 분석하고 이해합니다. 트래픽의 소스, 지연 시간 및 전송된 바이트 수를 확인할 수 있습니다.

Elastic Load Balancing 로그를 분석하기 전에 대상 Amazon S3 버킷에 저장하기 위한 로그를 구성합니다. 자세한 내용은 Classic Load Balancer 액세스 로그 사용을 참조하세요.

Elastic Load Balancing 로그에 대한 테이블을 생성하려면

  1. 다음 DDL 문을 복사하여 Athena 콘솔에 붙여 넣습니다. Elastic Load Balancing 로그 레코드의 구문을 확인합니다. 최신 버전 레코드의 열과 Regex 구문을 포함하도록 다음 쿼리를 업데이트해야 할 수 있습니다​.

    CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs ( timestamp string, elb_name string, request_ip string, request_port int, backend_ip string, backend_port int, request_processing_time double, backend_processing_time double, client_response_time double, elb_response_code string, backend_response_code string, received_bytes bigint, sent_bytes bigint, request_verb string, url string, protocol string, user_agent string, ssl_cipher string, ssl_protocol string ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES ( 'serialization.format' = '1', 'input.regex' = '([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\"[^\"]*\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$' ) LOCATION 's3://DOC-EXAMPLE-BUCKET/AWSLogs/AWS_account_ID/elasticloadbalancing/';
  2. Elastic Load Balancing 로그의 대상을 지정하여 LOCATION Amazon S3 버킷을 수정합니다.

  3. Athena 콘솔에서 쿼리를 실행합니다. 쿼리가 완료된 후 Athena는 elb_logs 테이블을 등록하여 쿼리를 위한 데이터를 준비합니다. 자세한 내용은 Elastic Load Balancing 예제 쿼리 단원을 참조하십시오.

Elastic Load Balancing 예제 쿼리

다음과 비슷한 방식으로 쿼리를 사용합니다. 4XX 또는 5XX 오류 응답 코드를 반환한 백엔드 애플리케이션 서버가 나열됩니다. LIMIT 연산자를 사용하여 한 번에 쿼리할 로그 수를 제한합니다.

SELECT timestamp, elb_name, backend_ip, backend_response_code FROM elb_logs WHERE backend_response_code LIKE '4%' OR backend_response_code LIKE '5%' LIMIT 100;

후속 쿼리를 사용하여 백엔드 IP 주소 및 Elastic Load Balancing 인스턴스 이름별로 그룹화된 모든 트랜잭션의 응답 시간을 요약합니다.

SELECT sum(backend_processing_time) AS total_ms, elb_name, backend_ip FROM elb_logs WHERE backend_ip <> '' GROUP BY backend_ip, elb_name LIMIT 100;

자세한 내용은 Athena를 이용한 S3 데이터 분석을 참조하세요.