Created
May 4, 2018 20:02
-
-
Save kamermans/5bfe1fb8040c273c65704e7b41ae6963 to your computer and use it in GitHub Desktop.
AWS ELB Log Parsing Regex in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Cat your ELB logs into this script | |
$elb_regex = '#^(?<date>.+?) (?<elb>.+?) (?<client_ip>[\d\.]+):(?<client_port>\d+) (?<backend_ip>[\d\.]+):(?<backend_port>\d+) (?<request_processing_time>[\d\.]+) (?<backend_processing_time>[\d\.]+) (?<response_processing_time>[\d\.]+) (?<elb_status_code>\d+) (?<backend_status_code>\d+) (?<received_bytes>\d+) (?<sent_bytes>\d+) "(?<method>[A-Z]+) (?<https>https?)://(?<http_host>.+?):(?<port>\d+)(?<uri>/.*?) (?<protocol>HTTP/[\d\.]+)" "(?<http_user_agent>.+?)" (?<ssl_cipher>.+?) (?<ssl_protocol>.+?)$#'; | |
while ($line = fgets(STDIN)) { | |
if (!preg_match($elb_regex, $line, $data)) { | |
continue; | |
} | |
/* Vars available in $data | |
* date, elb, client_ip, client_port, backend_ip, backend_port, | |
* request_processing_time, backend_processing_time, response_processing_time, | |
* elb_status_code, backend_status_code, received_bytes, sent_bytes, | |
* method, https, http_host, port, uri, protocol, http_user_agent, | |
* ssl_cipher, ssl_protocol | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment