Last active
May 11, 2016 08:55
-
-
Save mfoll/4efcaae3c7b0684ae0ca7b62a77038dc to your computer and use it in GitHub Desktop.
Summary of CPU usage for LSF cluster (graph and text file)
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
#! /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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Text output example: