Skip to content

Instantly share code, notes, and snippets.

@eiryu
Created November 9, 2015 10:32
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 eiryu/cbc0901d9db5f97de999 to your computer and use it in GitHub Desktop.
Save eiryu/cbc0901d9db5f97de999 to your computer and use it in GitHub Desktop.
TOPのCPU・メモリ使用率集計
// e.g.
// Cpu(s): 1.1%us, 0.6%sy, 0.0%ni, 97.5%id, 0.6%wa, 0.1%hi, 0.1%si, 0.0%st
new File('/path/02_cpu.txt').eachLine {
m = (it =~ /Cpu\(s\):\ +([0-9.]+)%us,\ +([0-9.]+)%sy.+/)
// if(m.matches()) {
println "${m[0][1]}\t${m[0][2]}"
// }
}
// e.g.
// Mem: 1026352k total, 389288k used, 637064k free, 146228k buffers
new File('/path/02_mem.txt').eachLine {
m = (it =~ /Mem:\ +([0-9]+)k\ total,\ +([0-9.]+)k\ used,.+/)
// if(m.matches()) {
println "${m[0][2]}"
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment