确定在远程机器上的空闲线程数 [英] Determine number of idle threads on remote machines

查看:142
本文介绍了确定在远程机器上的空闲线程数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在研究一个脚本,将告诉我们有多少线程都可以在我们组8台电脑。我知道,我可以使用

 执行cat / proc内/ cpuinfo | grep的处理器|厕所-l

获得线程的总数,但我们也想知道可用线程的数目。通过可用线程我的意思是多少目前没有使用。我们有多人访问这些计算机和运行需要在一个时间1-12线程,将是很好的工作有一个快速的查询,而不是手动访问每台计算机

访问计算机应该能够被这个剧本做,我只需要找到一个合适的功能FindAvaiableThreads使用()

  SSH用户@主机<<'ENDSSH
#commands到远程主机上运行
FindAvaiableThreads()
ENDSSHSSH用户@主机2<< ENDSSH
#commands到远程主机上运行
FindAvaiableThreads()
ENDSSH...SSH用户@ hostN<< ENDSSH
#commands到远程主机上运行
FindAvaiableThreads()
ENDSSH

最终结果

我们正在运行checker.scr它发送一个脚本来远程计算机n,则脚本通过查看CPU使用率和从CPU的总量中减去估计可用的CPU的数量,并根据需要对超线程被校正。

我也想指出,这个实现是基于使用公共/私人SSH密钥的推迟密码输入,但是sshpass可以用于你的密码传递给它;不过,我不能在这些计算机上安装这些程序。

checker.scr

  NAME =用户名SSH $名@ remote1的'庆典-s'< threadquery.scr
SSH $名@ Remote2上'庆典-s'< threadquery.scr
SSH $名@ remote3'庆典-s'< threadquery.scr
SSH $名@ remote4'庆典-s'< threadquery.scr
SSH $名@ remote5'庆典-s'< threadquery.scr
SSH $名@ remote6'庆典-s'< threadquery_hyper.scr
SSH $名@ remote7'庆典-s'< threadquery_hyper.scr
SSH $名@ remote8'庆典-s'< threadquery_hyper.scr

threadquery.scr

  NUMCPUS =`grep的^ PROC的/ proc内/ cpuinfo | WC -l`;
FIRST =`猫的/ proc / STAT | awk的'/ ^ CPU / {打印$ 5}'`;
睡眠1;
秒=`猫的/ proc / STAT | awk的'/ ^ CPU / {打印$ 5}'`;
二手=`回声2 k $ 100第二个$ FIRST - $ NUMCPUS / - P | dc`;
AVA = $(回声$ $ NUMCPUS- * NUMCPUS $ USED / 100| BC -l);
HOSTVAL = $(主机名)
回声上$ HOSTVAL估计avaliable处理器;
回声$ AVA | awk的-F \\。 '{如果(($ 2/10 ^长度($ 2))> = 0.5)的printf(%d个\\ n,$ 1 + 1);其他的printf(%d个\\ n,$ 1)}';

threadquery_hyper.scr

  NUMCPUS =`grep的^ PROC的/ proc内/ cpuinfo | WC -l`;
FIRST =`猫的/ proc / STAT | awk的'/ ^ CPU / {打印$ 5}'`;
睡眠1;
秒=`猫的/ proc / STAT | awk的'/ ^ CPU / {打印$ 5}'`;
二手=`回声2 k $ 100第二个$ FIRST - $ NUMCPUS / - P | dc`;
AVA = $(回声$ $ NUMCPUS- * NUMCPUS $ USED / 100| BC -l);
HOSTVAL = $(主机名)
THREADCORRECT = $(回声$ AVA / 2| BC -l);
回声上$ HOSTVAL估计avaliable处理器;
回声$ THREADCORRECT | awk的-F \\。 '{如果(($ 2/10 ^长度($ 2))> = 0.5)的printf(%d个\\ n,$ 1 + 1);其他的printf(%d个\\ n,$ 1)}';


解决方案

从我的理解你正在寻找可以从'顶'

检索信息

HTTP:// WWW。 cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html

信息是从任务'顶'

部分取

 #!/斌/庆典getthreads =`顶部-n 1 | awk的'/运行/ {打印$ 2,$ 4,$ 6}'`
totalthreads =`回声$ getthreads| AWK'{打印$ 1}'`
runningthreads =`回声$ getthreads| AWK'{打印$ 2}'`
availablethreads =`回声$ getthreads| AWK'{打印$ 3}'`回声总主题:$ totalthreads
回声主题是使用:$ runningthreads
回声主题可供选择:$ availablethreads

下面是提取所需的数据,并输出它的脚本。你可以调整你的需要。
希望这有助于

We are working on a script that will tell us how many threads are available on our groups 8 computers. I know that I can use

cat /proc/cpuinfo | grep processor | wc -l

to get the total number of threads, but we would like to know the number of available threads. By available threads I mean how many are currently not in use. We have multiple people accessing these computers and running jobs that require 1-12 threads at a time and would be nice to have a quick query instead of accessing each computer manually

Accessing the computers should be able to be done with this script, I just need to find an appropriate function to use as FindAvaiableThreads()

ssh user@host <<'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH

ssh user@host2 << 'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH

...

ssh user@hostN << 'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH

End Result

We are running checker.scr which sends a script to remote computer n, the script estimates the amount of available cpus by looking at the cpu usage and subtracting from the total amount of cpus and is corrected for hyper-threading as needed.

I'd also like to note that this implementation is based on use of public/private ssh keys to defer password inputs, however sshpass can be used to pass your password to it; however, I am not allowed to 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 my understanding the information you are looking for can be retrieved from 'TOP'

http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html

the information is taken from the '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 is use: $runningthreads"
echo "Threads available: $availablethreads"

here is a script that extracts the data you need and outputs it. You can adjust as you need. Hope this helps

这篇关于确定在远程机器上的空闲线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆