add netif info

main
Paco Hope 2023-10-08 14:40:56 -04:00
parent 37797bfd7f
commit 7b1d74afad
1 changed files with 29 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import subprocess
import base64
import json
import jc # holy crap: takes well known utils and produces json!
import re # for stuff that jc doesn't know
from hetrixtools_freebsd import __version__
@ -58,10 +59,10 @@ class Update:
self.iops = ""
self.raid = ""
self.dh = ""
self.nics = ""
self.ipv4 = ""
self.ipv6 = ""
self.conn = ""
self.nics = "" # getNetInfo
self.ipv4 = "" # getNetInfo
self.ipv6 = "" # getNetInfo
self.conn = "" # getNetInfo
self.temp = ""
self.serv = ""
self.cust = ""
@ -85,6 +86,7 @@ class Update:
return result.stdout.decode(encoding="utf-8")
def getVMStatInfo(self):
""" Take 2 samples, about 2 seconds apart. Report the difference."""
# Linux:
# vmstat 3 2
# procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
@ -144,6 +146,29 @@ class Update:
self.rambuff = str(0)
self.ramcache = str(0)
def getNetInfo(self):
""" Take 2 samples, about 2 seconds apart. Report the difference."""
t0 = json.loads( self.callCommand(command=['netstat', '-f', 'inet', '-b',
'-i', '--libxo', 'json']) )
time.sleep(2.0)
t1 = json.loads( self.callCommand(command=['netstat', '-f', 'inet', '-b',
'-i', '--libxo', 'json']) )
t0list = {ifname['name']:(ifname['sent-bytes'], ifname['received-bytes'])
for ifname in t0 ['statistics']['interface']}
t1list = {ifname['name']:(ifname['sent-bytes'], ifname['received-bytes'])
for ifname in t1 ['statistics']['interface']}
result = []
for ifname in t0list:
result.append("{},{},{};".format(ifname, t1[ifname][0]-t0[ifname][0],
t1[ifname][1]-t0[ifname][1]))
self.nics = result
self.ipv4 = "" # getNetInfo
self.ipv6 = "" # getNetInfo
self.conn = "" # getNetInfo
def getSysCtlInfo(self):
""" Parses all the things that can be gotten from sysctl and sets all the
values in the data structure. Other values can come from other places.