Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Excerpt

You may want to check the traffics in your server prom time to time, and checking CPU and number of threads are actually essential.



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.

Code Block
languagebash
titlehttpd_count.sh
#!/bin/bash
for i in {1..99999}
do
        ss | grep http | wc -l
        sleep 1
done


Below code (httpd_count.php) prints the total number of HTTP threads with # bar, so you can check its status more visually.

Code Block
languagephp
titlehttpd_count.php
#!/usr/bin/php
<?php

foreach($argv as $v)
{
        $v = strtolower($v);
}

$loop_limit=1000;

for($i=0; $i<$loop_limit; $i++)
{
        if ($i) sleep(1);

        $resp = shell_exec( "ss | grep http | wc -l");
        $process_count = intval($resp);

        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 = "";
        $bar_count = round( $process_count/20, 0);
        while( $bar_count>0 )
        {
                $bar_str .= "#";
                $bar_count--;
        };
		if ($process_count) $bar_str .= "#";
        $bar_str .= "\033[0m";

        echo "$bar_str {$process_count}\n";
}