Add omit option to ifstats
This commit is contained in:
parent
70df69fb3b
commit
79d2f18330
|
@ -1 +1 @@
|
||||||
__version__ = "0.1.3"
|
__version__ = "0.1.4"
|
||||||
|
|
|
@ -9,7 +9,10 @@ rx_bytes, rx_packets, rx_errs, rx_drop, rx_fifo, rx_frame, rx_compressed, rx_mul
|
||||||
previous = defaultdict(lambda: [-1 for i in range(17)])
|
previous = defaultdict(lambda: [-1 for i in range(17)])
|
||||||
|
|
||||||
|
|
||||||
def ifstats():
|
def ifstats(omit=[]):
|
||||||
|
"""
|
||||||
|
:param omit: list of strings that, if prefix a discovered interface, to not skip
|
||||||
|
"""
|
||||||
with open("/proc/net/dev", "r") as f:
|
with open("/proc/net/dev", "r") as f:
|
||||||
_, _ = f.readline(), f.readline()
|
_, _ = f.readline(), f.readline()
|
||||||
|
|
||||||
|
@ -36,6 +39,8 @@ def ifstats():
|
||||||
|
|
||||||
previous[ifname] = fields + [time()]
|
previous[ifname] = fields + [time()]
|
||||||
|
|
||||||
|
if any([ifname.startswith(i) for i in omit or []]):
|
||||||
|
continue
|
||||||
yield record
|
yield record
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +49,9 @@ mapping = {
|
||||||
"properties": {
|
"properties": {
|
||||||
"iface": {
|
"iface": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
},
|
||||||
|
"iface_raw": {
|
||||||
|
"type": "string",
|
||||||
"index": "not_analyzed"
|
"index": "not_analyzed"
|
||||||
},
|
},
|
||||||
"rx_bytes": {
|
"rx_bytes": {
|
||||||
|
@ -77,9 +85,9 @@ mapping = {
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from time import sleep
|
from time import sleep
|
||||||
for item in ifstats():
|
for item in ifstats(omit=["vm"]):
|
||||||
print(item)
|
print(item)
|
||||||
print("-")
|
print("-")
|
||||||
sleep(2)
|
sleep(2)
|
||||||
for item in ifstats():
|
for item in ifstats(omit=["vm"]):
|
||||||
print(item)
|
print(item)
|
||||||
|
|
Loading…
Reference in New Issue