Skip to content

Instantly share code, notes, and snippets.

@justinkamerman
Created September 21, 2012 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinkamerman/3762375 to your computer and use it in GitHub Desktop.
Save justinkamerman/3762375 to your computer and use it in GitHub Desktop.
Generate hit statistics bar chart from Apache httpd access logs
#!/usr/bin/env Rscript
#
# Usage: $0 <apache_access_log>
#
# Generate hit statistics bar chart from Apache httpd access logs
#
d <- read.table ("access.dat")
colnames(d) <- c("ip", "path", "agent")
# Hits by IP address
# Aggregate to get counts
a <- (aggregate (d$ip, list(d$ip), length))
colnames (a) <- c('ip', 'count')
# Order by count
a <- a[with(a, order(a$count, decreasing=TRUE)),]
# Draw bar plot
png("hitsbyip.png", height=480, width=960)
# Widen bottom margin for labels
par(mar = c(10,4,4,4))
barplot(a$count[1:40], names.arg=a$ip[1:40], las=2, cex.lab=0.5, main="Hits by IP", col=c("green"))
dev.off()
# Hits by User-Agent
# Aggregate to get counts
b <- (aggregate (d$agent, list(d$agent), length))
colnames (b) <- c('agent', 'count')
# Order by count
b <- b[with(b, order(b$count, decreasing=TRUE)),]
# Draw bar plot
png("hitsbyagent.png", height=480, width=960)
# Widen bottom margin for labels
par(mar = c(10,4,4,4))
barplot(b$count[1:40], names.arg=b$agent[1:40], las=2, cex.lab=0.5, main="Hits by Agent", col=c("green"))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment