we working on script tell how many threads available on our groups 8 computers. know can use
cat /proc/cpuinfo | grep processor | wc -l to total number of threads, know number of available threads. available threads mean how many not in use. have multiple people accessing these computers , running jobs require 1-12 threads @ time , nice have quick query instead of accessing each computer manually
accessing computers should able done script, need find appropriate function use findavaiablethreads()
ssh user@host <<'endssh' #commands run on remote host findavaiablethreads() endssh ssh user@host2 << 'endssh' #commands run on remote host findavaiablethreads() endssh ... ssh user@hostn << 'endssh' #commands run on remote host findavaiablethreads() endssh end result
we running checker.scr sends script remote computer n, script estimates amount of available cpus looking @ cpu usage , subtracting total amount of cpus , corrected hyper-threading needed.
i'd note implementation based on use of public/private ssh keys defer password inputs, sshpass can used pass password it; however, not allowed install such programs on these computers.
checker.scr
name = username ssh $name@remote1 'bash -s' < threadquery.scr ssh $name@remote2 'bash -s' < threadquery.scr ssh $name@remote3 'bash -s' < threadquery.scr ssh $name@remote4 'bash -s' < threadquery.scr ssh $name@remote5 'bash -s' < threadquery.scr ssh $name@remote6 'bash -s' < threadquery_hyper.scr ssh $name@remote7 'bash -s' < threadquery_hyper.scr ssh $name@remote8 'bash -s' < threadquery_hyper.scr threadquery.scr
numcpus=`grep ^proc /proc/cpuinfo | wc -l`; first=`cat /proc/stat | awk '/^cpu / {print $5}'`; sleep 1; second=`cat /proc/stat | awk '/^cpu / {print $5}'`; used=`echo 2 k 100 $second $first - $numcpus / - p | dc`; ava=$(echo "$numcpus-$numcpus*$used/100" | bc -l); hostval=$(hostname) echo "estimated avaliable processors on $hostval"; echo $ava | awk -f\. '{if(($2/10^length($2)) >= .5) printf("%d\n",$1+1);else printf("%d\n",$1)}'; threadquery_hyper.scr
numcpus=`grep ^proc /proc/cpuinfo | wc -l`; first=`cat /proc/stat | awk '/^cpu / {print $5}'`; sleep 1; second=`cat /proc/stat | awk '/^cpu / {print $5}'`; used=`echo 2 k 100 $second $first - $numcpus / - p | dc`; ava=$(echo "$numcpus-$numcpus*$used/100" | bc -l); hostval=$(hostname) threadcorrect=$(echo "$ava/2" | bc -l); echo "estimated avaliable processors on $hostval"; echo $threadcorrect | awk -f\. '{if(($2/10^length($2)) >= .5) printf("%d\n",$1+1);else printf("%d\n",$1)}';
from understanding information looking can retrieved 'top'
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
the information taken 'tasks' section of 'top'
#!/bin/bash getthreads=`top -n 1 | awk '/running/ {print $2, $4, $6}'` totalthreads=`echo "$getthreads" | awk ' {print $1 } '` runningthreads=`echo "$getthreads" | awk ' {print $2 } '` availablethreads=`echo "$getthreads" | awk ' {print $3 } '` echo "total threads: $totalthreads" echo "threads use: $runningthreads" echo "threads available: $availablethreads" here script extracts data need , outputs it. can adjust need. hope helps
Comments
Post a Comment