{"id":1272,"date":"2021-04-30T16:29:38","date_gmt":"2021-04-30T16:29:38","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=1272"},"modified":"2023-05-12T02:47:47","modified_gmt":"2023-05-12T02:47:47","slug":"how-to-check-cpu-memory-disks-mounts-on-an-array-of-hosts","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/how-to-check-cpu-memory-disks-mounts-on-an-array-of-hosts\/","title":{"rendered":"HOW TO CHECK  CPU, MEMORY, &#038; DISKS THRESHHOLDS  on an ARRAY of HOSTS."},"content":{"rendered":"<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>So I was tinkering around as usual. I thought this will come in handy for other engineers<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>If you a large cluster of servers that can suddenly over night loose all its <span style=\"color: #c00000;\">MEM,CPU<\/span><span style=\"color: #c00000;\">,DISK <\/span>due to the nature of your businesses. Its difficult to monitor that from a GUI and on an array of hosts more often&nbsp; than not.<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>Cloud Scenario\u2026&#8230;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>Say you find a node that is dying because too many clients are using resources and you need migrate instances off to another node, only you don\u2019t know which nodes have the needed resources without having to go look at all the nodes individually. <\/strong><\/p>\n<p><strong>This tends be every engineers pain point. So I decide to come up with quick easy solution for emergency situations, where you don\u2019t have time to sifting through alert systems that only show you data on a per host basis, that tend to load very slowly.<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>This bash script will check the CPU, MEM, DISK MOUNTS (including NFS) and tell which ones are okay and which ones are<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>CPU &#8211; calculated by the = 100MaxThrottle \u2013 Cpu-idle = <span style=\"color: #ff0000;\">CPU-usage<\/span><\/strong><br \/>\n<strong><span style=\"color: #0070c0;\">note: it also creates a log \/opt\/cpu.log on each host<\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>MEM \u2013 calculate by Total Mem \/ Used Memory * 100 = <span style=\"color: #ff0000;\">Percentage of Used Memory<\/span><\/strong><br \/>\n<strong><span style=\"color: #0070c0;\">note: it also creates a log \/opt\/mem.log on each host<\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>Disk \u2013 Any mount that reaches the warn threshold\u2026 <span style=\"color: #ff0000;\">COMPLAIN<\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>Now, itemised the bash script so you can just comment out item you don\u2019t want to use at the bottom of the script if you wanted to say just check <span style=\"color: #c00000;\">CPU\/MEM<\/span><\/strong><\/p>\n<p><strong>#Written By Nick Tailor<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#!\/bin\/bash<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>now=`date -u -d&#8221;+8 hour&#8221; +&#8217;%Y-%m-%d %H:%M:%S&#8217;`<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#cpu use threshold<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>cpu_warn=&#8217;75&#8217;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#disk use threshold<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>disk_warn=&#8217;80&#8217;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#&#8212;cpu<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>item_cpu () {<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>cpu_idle=`top -b -n 1 | grep Cpu | awk &#8216;{print $8}&#8217;|cut -f 1 -d &#8220;.&#8221;`<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>cpu_use=`expr 100 &#8211; $cpu_idle`<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;now current cpu utilization rate of $cpu_use $(hostname) as on $(date)&#8221; &gt;&gt; \/opt\/cpu.log<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>if [ $cpu_use -gt $cpu_warn ]<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>then<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;cpu warning!!! $cpu_use Currently HIGH $(hostname)&#8221;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>else<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;cpu ok!!! $cpu_use% use Currently LOW $(hostname)&#8221;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>fi<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>}<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#&#8212;mem<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>item_mem () {<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#MB units<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>LOAD=&#8217;80.00&#8242;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>mem_free_read=`free -h | grep &#8220;Mem&#8221; | awk &#8216;{print $4+$6}&#8217;`<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>MEM_LOAD=`free -t | awk &#8216;FNR == 2 {printf(&#8220;%.2f%&#8221;), $3\/$2*100}&#8217;`<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;Now the current memory space remaining ${mem_free_read} GB $(hostname) as on $(date)&#8221; &gt;&gt; \/opt\/mem.log<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>if [[ $MEM_LOAD &gt; $LOAD ]]<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>then<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;$MEM_LOAD not good!! MEM USEAGE is HIGH &#8211; Free-MEM-${mem_free_read}GB $(hostname)&#8221;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>else<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;$MEM_LOAD ok!! MEM USAGE is beLOW 80% &#8211; Free-MEM-${mem_free_read}GB $(hostname)&#8221;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>fi<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>}<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#&#8212;disk<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>item_disk () {<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>df -H | grep -vE &#8216;^Filesystem|tmpfs|cdrom&#8217; | awk &#8216;{ print $5 &#8221; &#8221; $1 }&#8217; | while read output;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>do<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo $output<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>&nbsp;&nbsp;usep=$(echo $output | awk &#8216;{ print $1}&#8217; | cut -d&#8217;%&#8217; -f1 )<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>partition=$(echo $output | awk &#8216;{ print $2 }&#8217; )<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>if [ $usep -ge $disk_warn ]; then<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>echo &#8220;AHH SHIT!, MOVE SOME VOLUMES IDIOT&#8230;. \\&#8221;$partition ($usep%)\\&#8221; on $(hostname) as on $(date)&#8221;<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>fi<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>done<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>}<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>item_cpu<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>item_mem<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; color: #5a5a5a;\"><strong>#item_disk \u2013 <span style=\"color: #7030a0;\"><em>This is so you can comment out whole sections of the script<\/em><\/span><span style=\"color: #7030a0;\"><em> without having to do the whole section by individual lines.<\/em><\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\"><strong>Now the cool part.<\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\">Now if you have a centrally managed jump host that allows you to get out from your estate. Ideally you would want to setup ssh keys on the hosts and ensure you have sudo permissions on the those hosts.<\/p>\n<p>We want to loop this script through an array of hosts and have it run and then report back all the findings in once place. This is extremely handy if your in resource crunch.<\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\">This assumes you have <span style=\"color: #0070c0;\">SSH KEYS SETUP &amp; SUDO <\/span>for your user setup.<\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\">Create the script<\/p>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">1.<\/span>On your jump host as your \u201cuser\u201d not root<\/strong><\/div>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">a.<\/span><em>vi coolchecks.sh<\/em><\/strong><\/div>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">b.<\/span>Copy the above code and paste<\/strong><\/div>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">c.<\/span>Save the file<\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">2.<\/span>Next chmod the permission to executable<\/strong><\/div>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">d.<\/span><em>chmod +x coolcheck.sh<\/em><\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3;\">Next<\/p>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">3.<\/span><strong>Create a servers.txt file<\/strong><\/div>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">e.<\/span><em>vi servers.txt<\/em><\/strong><\/div>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">f.<\/span>List out servers in a column<\/strong><\/div>\n<p style=\"text-align: left; margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><strong><span style=\"color: #0070c0;\">Server1<\/span><span style=\"color: #0070c0;\"><br \/>\nServer2<\/span><span style=\"color: #0070c0;\"><br \/>\nServer3<\/span><span style=\"color: #0070c0;\"><br \/>\nServer4<\/span><\/strong><\/p>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 72pt;\"><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">g.<\/span>Save the file.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">4.<\/span>Now we want to loop that through the list of servers and then have it spit out the results and pipe the information to a file on the jumps host.<\/strong><\/div>\n<p style=\"text-align: left; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>Run your forloop with ssh keys and sudo already setup.<\/strong><\/p>\n<p style=\"text-align: left; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/p>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; margin-left: 54pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">1.<\/span>f<em>or HOST in $(cat servers.txt); do ssh $HOST &#8220;sudo bash -s&#8221; &lt; coolcheck.sh; done 2&gt;&amp;1 | tee -a cpumem.status.DEV<\/em><\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; text-indent: 36pt;\"><strong><span style=\"color: #7030a0;\">Logfile &#8211; <\/span><span style=\"color: #7030a0;\">cpumem.status.DEV<\/span> \u2013 <span style=\"color: #c00000;\">will be the log file that has all the info<\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>Output:<\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">cpu<\/span><span style=\"color: #0070c0;\"> ok!!! 3% use Currently dev1.nicktailor.com<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">17.07% ok!! MEM USAGE is <\/span><span style=\"color: #0070c0;\">beLOW<\/span><span style=\"color: #0070c0;\"> 80% &#8211; Free-MEM-312.7GB dev1.nicktailor.com<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #0070c0;\">5% \/dev\/mapper\/VolGroup00-root<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">3% \/dev\/sda2<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">5% \/dev\/sda1<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">1% \/dev\/mapper\/VolGroup00-var_log<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">72% 192.168.1.101:\/data_1<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">28% 192.168.1.102:\/data_2<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">80% 192.168.1.103:\/data_3<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #ff0000;\">AHH <\/span><span style=\"color: #ff0000;\">SHIT!,<\/span><span style=\"color: #ff0000;\"> MOVE SOME VOLUMES IDIOT&#8230;. &#8220;192.168.1.104:\/data4 (80%)&#8221; on dev1.nicktailor.com as on Fri Apr 30 11:55:16 EDT 2021<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>Okay so now I\u2019m gonna show you a dirty way to do it, because im just dirty. So say your in horrible place that doesn\u2019t use keys, because they&#8217;re waiting to be hacked by password. \ud83d\ude1b<\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>DIRTY WAY \u2013 So this assumes you have <span style=\"color: #00b050;\">sudo<\/span><span style=\"color: #00b050;\"> permissions on the hosts<\/span>.<\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>Note: I do not recommend doing this way if you are a newb. Doing it this way will basically log your password in the bash history and if you don\u2019t know how to clean up after yourself, well\u2026\u2026\u2026\u2026\u2026\u2026\u2026.<span style=\"color: #ff0000;\">you&#8217;re<\/span><span style=\"color: #ff0000;\">&nbsp;going to get <\/span><span style=\"color: #ff0000;\">owned.<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">I\u2019m only showing you this because<\/span><span style=\"color: #000000;\"> some<\/span> <span style=\"color: #00b0f0;\">cyber security <\/span> <span style=\"color: #7030a0;\">\u201cfolks\u201d <\/span><span style=\"color: #000000;\">believe that not using keys is easier to deal with in some <\/span><span style=\"color: #0070c0;\">parallel realities iv visited<\/span><span style=\"color: #000000;\">&#8230; You can do the exact same thing above<\/span><span style=\"color: #000000;\">,<\/span><span style=\"color: #000000;\"> without keys. But leave massive trail behind you. <\/span><span style=\"color: #000000;\"> Hence why you should use <\/span><span style=\"color: #00b050;\">secure keys with passwords<\/span><span style=\"color: #000000;\">.<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">Not Recommended for <\/span><span style=\"color: #0070c0;\">Newbies<\/span><span style=\"color: #0070c0;\">:<br \/>\n<\/span><span style=\"color: #ff0000;\">Forloop<\/span><span style=\"color: #ff0000;\">&nbsp;AND passing your <\/span><span style=\"color: #ff0000;\">ssh<\/span><span style=\"color: #ff0000;\"> password<\/span><span style=\"color: #ff0000;\"> inside it.<\/span><\/strong><\/p>\n<div class=\"ol\" style=\"margin: 0;\">\n<div class=\"li\" style=\"margin: 0;\">\n<div style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 54pt;\"><strong><span style=\"display: inline-block; position: relative; text-indent: -18pt;\">2.<\/span><em>for HOST in $(cat servers.txt); do sshpass -p&#8217;<span style=\"color: #ff0000;\">SHHPASSWORD<\/span><span style=\"color: #ff0000;\">!<\/span>&#8216; ssh -o &#8216;StrictHostKeyChecking no&#8217; -p 22 $HOST &#8220;sudo bash -s&#8221; &lt; coolcheck.sh; done 2&gt;&amp;1 | tee -a <span style=\"color: #7030a0;\">cpumem.status.DEV<\/span><\/em><\/strong><\/div>\n<p style=\"text-align: left; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; margin-left: 54pt;\"><strong><span style=\"display: inline-block; height: 1em;\"><span style=\"display: none;\">.<\/span><\/span><\/strong><\/p>\n<\/div>\n<\/div>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 8pt; padding-bottom: 0; line-height: 1.3; text-indent: 36pt;\"><strong><span style=\"color: #7030a0;\">Log file &#8211; <\/span><span style=\"color: #7030a0;\">cpumem.status.DEV<\/span> \u2013 <span style=\"color: #c00000;\">will be the log file that has all the info<\/span><\/strong><\/p>\n<p style=\"margin-top: 0pt; padding-top: 0; margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong>Output:<\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">cpu<\/span><span style=\"color: #0070c0;\"> ok!!! 3% use Currently dev1.nicktailor.com<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">17.07% ok!! MEM USAGE is <\/span><span style=\"color: #0070c0;\">beLOW<\/span><span style=\"color: #0070c0;\"> 80% &#8211; Free-MEM-312.7GB dev1.nicktailor.com<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #0070c0;\">5% \/dev\/mapper\/VolGroup00-root<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">3% \/dev\/sda2<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">5% \/dev\/sda1<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">1% \/dev\/mapper\/VolGroup00-var_log<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">72% 192.168.1.101:\/data_1<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">28% 192.168.1.102:\/data_2<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #0070c0;\">80% 192.168.1.103:\/data_3&nbsp;<\/span><\/strong><\/p>\n<p style=\"margin-bottom: 0; padding-bottom: 0; line-height: 1.3; margin-left: 36pt;\"><strong><span style=\"color: #ff0000;\">AHH <\/span><span style=\"color: #ff0000;\">SHIT!,<\/span><span style=\"color: #ff0000;\"> MOVE SOME VOLUMES IDIOT&#8230;. &#8220;192.168.1.104:\/data4 (80%)&#8221; on dev1.nicktailor.com as on Fri Apr 30 11:55:16 EDT 2021<br \/>\n<\/span><\/strong><span style=\"display: inline-block; height: 1em;\"><br \/>\n<span style=\"display: none;\">.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I was tinkering around as usual. I thought this will come in handy for other engineers If you a large cluster of servers that can suddenly over night loose all its MEM,CPU,DISK due to the nature of your businesses. Its difficult to monitor that from a GUI and on an array of hosts more often&nbsp; than not. Cloud Scenario\u2026&#8230;<a href=\"https:\/\/nicktailor.com\/tech-blog\/how-to-check-cpu-memory-disks-mounts-on-an-array-of-hosts\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,138,132],"tags":[],"class_list":["post-1272","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-monitoring"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=1272"}],"version-history":[{"count":7,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1272\/revisions"}],"predecessor-version":[{"id":1583,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1272\/revisions\/1583"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=1272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=1272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=1272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}