...
You can simply check the number of HTTP threads on terminal:
Code Block |
---|
|
ss | grep http | wc -l |
Below code (httpd_count.sh) prints the total number of HTTP threads, so you can check its status constantly.
Code Block |
---|
language | bash |
---|
title | httpd_count.sh |
---|
|
#!/bin/bash
for i in {1..99999}
do
ss | grep http | wc -l
sleep 1
done |
...
Code Block |
---|
language | php |
---|
title | httpd_count.php |
---|
|
#!/usr/bin/php
<?php
// HTTP thread monitoring - Chun Kang (ck@ckii.com) at 2021-11-02
foreach($argv as $v)
{
$v = strtolower($v);
}
$loop_limit=100099999;
$hostname = gethostname();
for($i=0; $i<$loop_limit; $i++)
{
if ($i) sleep(1);
$resp = shell_exec( "ss | grep http | wc -l");
$process_count = intval($resp);
$cpu_usage = trim( shell_exec( "grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage \"%\"}'") );
if ($process_count<100) $bar_str = "\033[32m";
else if ($process_count<200) $bar_str = "\033[33m";
else if ($process_count<500) $bar_str = "\033[35m";
else
{
$bar_str = "\033[31m";
}
$bar_str = "";
if ($process_count)
{
$bar_count = round( $process_count/2030, 0);
while( $bar_count>0 )
{
$bar_str .= "#";
$bar_count--;
};
if ($process_count) $bar_str .= "#";
$bar_str .= "\033[0m ";
}
echo "[{$hostname}] {$bar_str {}" . number_format($process_count) . " (CPU {$cpu_usage})\n";
}
|