Created
September 28, 2012 17:56
-
-
Save justinkamerman/3801270 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env Rscript | |
# | |
# Usage: $0 <datafile> | |
# | |
# Expected data file format: t lt ts s lb rc rm tn dt by | |
# | |
myspan = 0.1 | |
myargs <- commandArgs(TRUE) | |
file <- myargs[1] | |
d <- read.table (file, header=TRUE) | |
## Order by timestamp so we can get meaningful iats | |
d <- d[order(d$ts),] | |
# Inter-arrival time | |
v = numeric (length(d$ts)) | |
v[1] = 1 | |
for (i in 2:length(d$ts)) { v[i] = d$ts[i] - d$ts[i-1] + 1 } | |
d$v <- v | |
# Main Plot | |
image = paste(file, ".png", sep="") | |
png (image, width=960, height=480) | |
tsmin = min (d$ts) | |
ymax=1000*60*(1/mean(d$v)+1/sd(d$v)) | |
palette <- rainbow (nlevels(d$lb)+1) | |
d.lo <- loess (d$v ~ d$ts, span=myspan) | |
# Total | |
plot ((d$ts-tsmin)/1000, 1000*60/predict(d.lo, d$ts), type="l", ylab="req/min", xlab="seconds", main="Request Rate", col=palette[1], ylim=c(0,ymax)) | |
legend("topright", c("total", levels(d$lb)), col=palette, lty=1, cex=0.75) | |
# Labels | |
pindex = 2; | |
palette <- rainbow (nlevels(d$lb)) | |
for (label in levels(d$lb)) | |
{ | |
print (label) | |
a <- subset(d, lb==label) | |
v = numeric (length(a$ts)) | |
v[1] = 1 | |
for (i in 2:length(a$ts)) { v[i] = a$ts[i] - a$ts[i-1] + 1 } | |
a$v <- v | |
a.lo <- loess (a$v ~ a$ts, span=myspan) | |
lines ((a$ts-tsmin)/1000, 1000*60/predict(a.lo, a$ts), col=palette[pindex]) | |
rm(a) | |
rm(v) | |
pindex = pindex+1 | |
} | |
grid() | |
dev.off() | |
print (paste("Request rate plot written to file", image)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment