ã¿ãã§ã.
åå DuckDB 㧠CloudTrail ãã°ãåæãã¦ã¿ã¾ãã.ä»å㯠ALB ã®ã¢ã¯ã»ã¹ãã°ãåæãã¦ã¿ã¾ã.
sadayoshi-tada.hatenablog.com
sadayoshi-tada.hatenablog.com
ãã¡ãã®è¨äºãåç
§ããã¦ããã ãã¦ãã¼ãã«ãä½ã£ã¦ã¿ã¾ãã.
CREATE TABLE alb_log AS
SELECT *
FROM read_csv(
'[ãã°ãã¡ã¤ã«ãã¹]',
columns={
'type': 'VARCHAR',
'timestamp': 'TIMESTAMP',
'elb': 'VARCHAR',
'client_ip_port': 'VARCHAR',
'target_ip_port': 'VARCHAR',
'request_processing_time': 'DOUBLE',
'target_processing_time': 'DOUBLE',
'response_processing_time': 'DOUBLE',
'elb_status_code': 'INTEGER',
'target_status_code': 'VARCHAR',
'received_bytes': 'BIGINT',
'sent_bytes': 'BIGINT',
'request': 'VARCHAR',
'user_agent': 'VARCHAR',
'ssl_cipher': 'VARCHAR',
'ssl_protocol': 'VARCHAR',
'target_group_arn': 'VARCHAR',
'trace_id': 'VARCHAR',
'domain_name': 'VARCHAR',
'chosen_cert_arn': 'VARCHAR',
'matched_rule_priority': 'VARCHAR',
'request_creation_time': 'TIMESTAMP',
'actions_executed': 'VARCHAR',
'redirect_url': 'VARCHAR',
'error_reason': 'VARCHAR',
'target_port_list': 'VARCHAR',
'target_status_code_list': 'VARCHAR',
'classification': 'VARCHAR',
'classification_reason': 'VARCHAR',
'conn_trace_id': 'VARCHAR'
},
delim=' ',
quote='"',
escape='"',
header=False,
auto_detect=False
);
D show tables;
âââââââââââ
â name â
â varchar â
âââââââââââ¤
â alb_log â
âââââââââââ
åèè¨äº
swfz.hatenablog.com
ALB ã¢ã¯ã»ã¹ãã°ã®åæã¯ã¨ãªãå®è¡ãã
AWS ã®ããã¥ã¡ã³ããåèã«ã¯ã¨ãªãããã¤ãå®è¡ãã¦ã¿ã¾ã.
ã¯ã©ã¤ã¢ã³ã IP ã¢ãã¬ã¹å¥ã«ã°ã«ã¼ãåããã HTTP ãªã¯ã¨ã¹ãã®æ°ãéè¨
D SELECT COUNT(request) AS
count,
request,
SPLIT_PART(client_ip_port, ':', 1) as client_ip
FROM alb_log
GROUP BY request, client_ip
;
âââââââââ¬âââââââââââââââââââââââââââââââââââââââââââ¬ââââââââââââââââ
â count â request â client_ip â
â int64 â varchar â varchar â
âââââââââ¼âââââââââââââââââââââââââââââââââââââââââââ¼ââââââââââââââââ¤
â 2 â GET https://12.34.56.78:443/ HTTP/1.1 â 123.45.657.89 â
â 1 â GET https://12.34.56.78:443/xxx HTTP/1.1 â 45.657.89.110 â
âââââââââ´âââââââââââââââââââââââââââââââââââââââââââ´ââââââââââââââââ
ELB ã¹ãã¼ã¿ã¹ã³ã¼ãã®å¤ã200以å¤ã®ãªã¯ã¨ã¹ããæ½åº
SELECT
type,
timestamp,
client_ip_port,
elb_status_code,
target_status_code,
request,
error_reason
FROM
alb_log
WHERE
elb_status_code != 200;
âââââââââââ¬âââââââââââââââââââââââââââââ¬ââââââââââââââââââââââ¬ââââââââââââââââââ¬âââââââââââââââââââââ¬âââââââââââââââââââââââââââââââââââââââââââ¬âââââââââââââââ
â type â timestamp â client_ip_port â elb_status_code â target_status_code â request â error_reason â
â varchar â timestamp â varchar â int32 â varchar â varchar â varchar â
âââââââââââ¼âââââââââââââââââââââââââââââ¼ââââââââââââââââââââââ¼ââââââââââââââââââ¼âââââââââââââââââââââ¼âââââââââââââââââââââââââââââââââââââââââââ¼âââââââââââââââ¤
â https â 2024-12-22 00:35:22.50771 â 123.45.657.89:12345 â 403 â - â GET https://12.34.56.78:443/ HTTP/1.1 â - â
â https â 2024-12-22 00:35:33.942067 â 123.45.657.89:53456 â 403 â - â GET https://12.34.56.78:443/ HTTP/1.1 â - â
â https â 2024-12-22 00:36:08.717268 â 45.657.89.110:32134 â 403 â - â GET https://12.34.56.78:443/xxx HTTP/1.1 â - â
âââââââââââ´âââââââââââââââââââââââââââââ´ââââââââââââââââââââââ´ââââââââââââââââââ´âââââââââââââââââââââ´âââââââââââââââââââââââââââââââââââââââââââ´âââââââââââââââ
ã¾ã¨ã
DuckDB 㧠ALB ã®ã¢ã¯ã»ã¹ãã°ãåæããã®ã試ãã¦ã¿ã¾ãã.