Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
fix(scrape): Fix regular express to match ifconfig output.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjw committed Sep 13, 2020
1 parent 114cfcc commit fd5e367
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 127 deletions.
2 changes: 1 addition & 1 deletion bin/zyxelprometheus
Expand Up @@ -38,7 +38,7 @@ def main():
if xdsl is not None:
print(xdsl)
if ifconfig is not None:
print(ifconfig)
print(repr(ifconfig))
else:
print(prometheus(xdsl, ifconfig))

Expand Down
226 changes: 113 additions & 113 deletions example_ifconfig.txt
@@ -1,113 +1,113 @@
bcmsw Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972804 errors:0 dropped:0 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2863805176 (2.6 GiB) TX bytes:1404861494 (1.3 GiB)
Base address:0x8200

br0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:7968422 errors:0 dropped:19510 overruns:0 frame:0
TX packets:11495200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2713281739 (2.5 GiB) TX bytes:1342943018 (1.2 GiB)

eth0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972821 errors:0 dropped:6 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2863807348 (2.6 GiB) TX bytes:1404861494 (1.3 GiB)


eth0.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972642 errors:0 dropped:3229 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2713867223 (2.5 GiB) TX bytes:1342942952 (1.2 GiB)

eth1 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


eth1.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)

eth2 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


eth2.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)

eth3 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth3.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:104 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7332 (7.1 KiB) TX bytes:7332 (7.1 KiB)

ppp2.3 Link encap:Point-to-Point Protocol
inet addr:82.69.87.219 P-t-P:51.148.72.21 Mask:255.255.255.255
inet6 addr: 2a02:8011:d000:243::1/64 Scope:Global
inet6 addr: fe80::1/10 Scope:Link
UP POINTOPOINT RUNNING NOARP ALLMULTI MULTICAST MTU:1492 Metric:1
RX packets:11401901 errors:0 dropped:0 overruns:0 frame:0
TX packets:7334759 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1152021749 (1.0 GiB) TX bytes:2564999965 (2.3 GiB)

ptm0 Link encap:Ethernet HWaddr E4:18:6B:06:87:72
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11518182 errors:0 dropped:1 overruns:0 frame:0
TX packets:7350460 errors:0 dropped:3693 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1456958071 (1.3 GiB) TX bytes:2762154613 (2.5 GiB)

ptm0.3 Link encap:Ethernet HWaddr E4:18:6B:06:87:74
inet6 addr: fe80::e618:6bff:fe06:8774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11421286 errors:0 dropped:0 overruns:0 frame:0
TX packets:7354153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1244051286 (1.1 GiB) TX bytes:2756363550 (2.5 GiB)
bcmsw Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972804 errors:0 dropped:0 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2863805176 (2.6 GiB) TX bytes:1404861494 (1.3 GiB)
Base address:0x8200
br0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:7968422 errors:0 dropped:19510 overruns:0 frame:0
TX packets:11495200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2713281739 (2.5 GiB) TX bytes:1342943018 (1.2 GiB)
eth0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972821 errors:0 dropped:6 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2863807348 (2.6 GiB) TX bytes:1404861494 (1.3 GiB)
eth0.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7972642 errors:0 dropped:3229 overruns:0 frame:0
TX packets:11495195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2713867223 (2.5 GiB) TX bytes:1342942952 (1.2 GiB)
eth1 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth1.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)
eth2 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth2.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)
eth3 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth3.0 Link encap:Ethernet HWaddr E4:18:6B:06:87:70
inet6 addr: fe80::e618:6bff:fe06:8770/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:340619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:115241186 (109.9 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:104 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7332 (7.1 KiB) TX bytes:7332 (7.1 KiB)
ppp2.3 Link encap:Point-to-Point Protocol
inet addr:82.69.87.219 P-t-P:51.148.72.21 Mask:255.255.255.255
inet6 addr: 2a02:8011:d000:243::1/64 Scope:Global
inet6 addr: fe80::1/10 Scope:Link
UP POINTOPOINT RUNNING NOARP ALLMULTI MULTICAST MTU:1492 Metric:1
RX packets:11401901 errors:0 dropped:0 overruns:0 frame:0
TX packets:7334759 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1152021749 (1.0 GiB) TX bytes:2564999965 (2.3 GiB)
ptm0 Link encap:Ethernet HWaddr E4:18:6B:06:87:72
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11518182 errors:0 dropped:1 overruns:0 frame:0
TX packets:7350460 errors:0 dropped:3693 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1456958071 (1.3 GiB) TX bytes:2762154613 (2.5 GiB)
ptm0.3 Link encap:Ethernet HWaddr E4:18:6B:06:87:74
inet6 addr: fe80::e618:6bff:fe06:8774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11421286 errors:0 dropped:0 overruns:0 frame:0
TX packets:7354153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1244051286 (1.1 GiB) TX bytes:2756363550 (2.5 GiB)
1 change: 0 additions & 1 deletion example_xdsl.txt
Expand Up @@ -7,4 +7,3 @@ Last initialization procedure status: 0
Max: Upstream rate = 7833 Kbps, Downstream rate = 47522 Kbps
Bearer: 0, Upstream rate = 7833 Kbps, Downstream rate = 39999 Kbps
Bearer: 1, Upstream rate = 0 Kbps, Downstream rate = 0 Kbps

3 changes: 3 additions & 0 deletions tests/mock_sshclient.py
Expand Up @@ -87,3 +87,6 @@ def read(self, count):
class MockChannel:
def __init__(self):
self.eof_received = False

def close(self):
pass
4 changes: 2 additions & 2 deletions tests/test_prometheus.py
Expand Up @@ -20,8 +20,8 @@

from zyxelprometheus import prometheus

XDSL = open("example_xdsl.txt").read()
IFCONFIG = open("example_ifconfig.txt").read()
XDSL = open("example_xdsl.txt", "rb").read().decode("utf8")
IFCONFIG = open("example_ifconfig.txt", "rb").read().decode("utf8")


class TestPrometheus(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scrape.py
Expand Up @@ -21,8 +21,8 @@

from .mock_sshclient import MockSSHClient, MockSSHSession

IFCONFIG = open("example_ifconfig.txt").read()
XDSL = open("example_xdsl.txt").read()
IFCONFIG = open("example_ifconfig.txt", "rb").read().decode("utf8")
XDSL = open("example_xdsl.txt", "rb").read().decode("utf8")


class TestScrape(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Expand Up @@ -23,8 +23,8 @@

from .mock_sshclient import MockSSHClient, MockSSHSession

XDSL = open("example_xdsl.txt").read()
IFCONFIG = open("example_ifconfig.txt").read()
XDSL = open("example_xdsl.txt", "rb").read().decode("utf8")
IFCONFIG = open("example_ifconfig.txt", "rb").read().decode("utf8")


class MockHandler(Handler):
Expand Down
12 changes: 6 additions & 6 deletions zyxelprometheus/prometheus.py
Expand Up @@ -73,12 +73,12 @@ def prometheus(xdsl, ifconfig):
f"""zyxel_max_line_rate{{stream="down"}} {line_rate_down}""")

if ifconfig is not None:
for iface in iface_re.finditer(ifconfig):
iface_name = iface.group(1)
iface_stats = iface.group(2)
for (metric, help, metric_re) in iface_stats_map:
output.append(f"# HELP {metric} {help}")
output.append(f"# TYPE {metric} counter")
for (metric, help, metric_re) in iface_stats_map:
output.append(f"# HELP {metric} {help}")
output.append(f"# TYPE {metric} counter")
for iface in iface_re.finditer(ifconfig.replace("\r\n", "\n")):
iface_name = iface.group(1)
iface_stats = iface.group(2)
for groups in metric_re.finditer(iface_stats):
metric_stream = groups.group(1).lower()
metric_value = int(groups.group(2))
Expand Down

0 comments on commit fd5e367

Please sign in to comment.