Skip to content

Instantly share code, notes, and snippets.

@mfoll
Last active May 11, 2016 08:55
Show Gist options
  • Save mfoll/4efcaae3c7b0684ae0ca7b62a77038dc to your computer and use it in GitHub Desktop.
Save mfoll/4efcaae3c7b0684ae0ca7b62a77038dc to your computer and use it in GitHub Desktop.
Summary of CPU usage for LSF cluster (graph and text file)
#! /usr/bin/env Rscript
# With no argument provided, produce a graph since the begining of the year
# Argument can be "2016/03/01,2016/12/31" or "2016/03/01,"
if (!is.na(commandArgs(TRUE)[1])) {
time_string=commandArgs(TRUE)[1]
} else {
time_string=paste(format(Sys.time(), "%Y"),"/01/01,",sep="")
}
# add the final date to today if not provided to put in the graph title and file name
if (length(strsplit(time_string,",")[[1]])==1) {
time_string=paste(time_string,format(Sys.time(), "%Y/%m/%d"),sep="")
}
# get list of users
users=list.dirs("/home",recursive=F,full.names=F)
res=numeric()
for (cur_user in users) {
cur_res=as.numeric(readLines(pipe(paste("bacct -D ",time_string," -u ",cur_user," | grep \"Total CPU time consumed\" | awk '{print $5}' 2> /dev/null",sep=""))))
if (length(cur_res>0)) res[cur_user]=cur_res/3600
}
pdf(paste("cluster_usage_",gsub("/","-",time_string),".pdf",sep=""),width = 5+length(res)*0.3,height = 6)
par(mar=c(4.1+3,5.1+1.5,4.1,2.1),mgp = c(4, 0.5, 0))
barplot(sort(res,decreasing=T),main=gsub(","," - ",time_string),ylab="Total CPU time consumed (hours)",las=2)
dev.off()
write.table(res,paste("cluster_usage_",gsub("/","-",time_string),".txt",sep=""),quote=F,col.names=F)
@mfoll
Copy link
Author

mfoll commented May 11, 2016

Text output example:

ardinm 35770.1674444444
bouaounl 2860.43205555556
delhommet 19412.2644444444
ferreiroa 29.2038333333333
follm 1462.78852777778
gaborieauv 1085.5065
khlifi 5031.83922222222
leblayn 21534.7837222222
lesseurc 36.3131388888889
lsaadm 137164.667166667
perrierf 309.682638888889
robitaillea 12547.4320833333
vinayanuwattikunc 354.324333333333

@mfoll
Copy link
Author

mfoll commented May 11, 2016

Graphical output example:

cluster_usage_2016-01-01 2016-05-11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment