Last active
April 6, 2016 21:35
-
-
Save yannick/6caf5a5184beea0c24f35d9d4a4c7783 to your computer and use it in GitHub Desktop.
This file contains 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
import std.csv; | |
import std.stdio; | |
import std.datetime; | |
import std.conv; | |
/* | |
reads logfiles from nginx that are generated with: | |
log_format metrics '$msec\t$connection\t$status\t$request_time\t$remote_addr\t$remote_port\t$body_bytes_sent\t$request_uri\t$tcpinfo_rtt\t$tcpinfo_rttvar\t$tcpinfo_snd_cwnd\t$tcpinfo_rcv_space'; | |
*/ | |
//could this be done better? | |
struct SysUnixTime | |
{ | |
this(string s) | |
{ | |
t = SysTime(621_355_968_000_000_000L + convert!("msecs", | |
"hnsecs")(cast(long)(s.to!double * 1000))); | |
} | |
SysTime t; | |
alias t this; | |
} | |
struct NginxLogLine | |
{ | |
SysUnixTime time; | |
ulong connection; | |
ushort status; | |
float request_time; | |
string remote_addr; | |
ushort remote_port; | |
uint body_bytes_sent; | |
string request_uri; | |
uint tcpinfo_rtt; | |
uint tcpinfo_rttvar; | |
uint tcpinfo_snd_cwnd; | |
uint tcpinfo_rcv_space; | |
} | |
void main() | |
{ | |
import std.algorithm; | |
auto records = stdin.byLine.joiner("\n").csvReader!NginxLogLine('\t'); | |
foreach (l; records) | |
{ | |
writeln(record.status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment