KaiRo bug 416 - Use ss instead of netstat for connect stats
authorRobert Kaiser <kairo@kairo.at>
Sun, 16 Apr 2017 23:12:56 +0000 (01:12 +0200)
committerRobert Kaiser <kairo@kairo.at>
Sun, 16 Apr 2017 23:12:56 +0000 (01:12 +0200)
examples/rrd/rrd-config/hostname.inc.php

index 3cf8948e76b1905bd76430778da90779e2b53a5c..59f7a773ab6f8278108afd75020faf9b94328170 100644 (file)
@@ -420,14 +420,14 @@ $rrd_info['connect']['fields'][] = array('name' => 'rest_other', 'type' => 'GAUG
 $rrd_info['connect']['fields'][] = array('name' => 'udp', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
 $rrd_info['connect']['update'] =
  'function {
 $rrd_info['connect']['fields'][] = array('name' => 'udp', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
 $rrd_info['connect']['update'] =
  'function {
-    $sdata = explode("\n", `LANG=C /bin/netstat -n -a`);
+    $sdata = explode("\n", `LANG=C /usr/sbin/ss -tuan`);
     $udata = array("listen"=>0,"run_http"=>0,"run_other"=>0,"rest_http"=>0,"rest_other"=>0,"udp"=>0);
     foreach ($sdata as $sline) {
       if (substr($sline, 0, 3) == "tcp") {
     $udata = array("listen"=>0,"run_http"=>0,"run_other"=>0,"rest_http"=>0,"rest_other"=>0,"udp"=>0);
     foreach ($sdata as $sline) {
       if (substr($sline, 0, 3) == "tcp") {
-        if (preg_match("/LISTEN\s*$/", $sline)) { $udata["listen"]++; }
-        elseif (preg_match("/:(80|443)\s+[\d\.:*]+\s+ESTABLISHED\s*/", $sline)) { $udata["run_http"]++; }
-        elseif (preg_match("/^tcp\s+\d+\s+\d+\s+[\d\.]+:(80|443)/", $sline)) { $udata["rest_http"]++; }
-        elseif (preg_match("/ESTABLISHED\s*$/", $sline)) { $udata["run_other"]++; }
+        if (preg_match("/^tcp\s+LISTEN\s+/", $sline)) { $udata["listen"]++; }
+        elseif (preg_match("/^tcp\s+ESTAB\s+\d+\s+\d+\s+[\da-f\.:]+:(80|443)\s*/", $sline)) { $udata["run_http"]++; }
+        elseif (preg_match("/^tcp\s+[^\s]+\s+\d+\s+\d+\s+[\da-f\.:]+:(80|443)\s*/", $sline)) { $udata["rest_http"]++; }
+        elseif (preg_match("/^tcp\s+ESTAB\s+/", $sline)) { $udata["run_other"]++; }
         else { $udata["rest_other"]++; }
       }
       elseif (substr($sline, 0, 3) == "udp") { $udata["udp"]++; }
         else { $udata["rest_other"]++; }
       }
       elseif (substr($sline, 0, 3) == "udp") { $udata["udp"]++; }