PeterGrace / py_arris_exporter

A prometheus exporter for Arris SB6183 cablemodems
8 stars 5 forks source link

Customize for SB8200 #4

Open cypherstream opened 4 years ago

cypherstream commented 4 years ago

The URL for the SB8200 is http://192.168.100.1/cmconnectionstatus.html

I edited this in the handler.py and reinstalled it (pip3 install py_arris_exporter) and when I run it I get this about broken pipes. Can you help?

EBUG:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.100.1:80 DEBUG:urllib3.connectionpool:http://192.168.100.1:80 "GET /cmconnectionstatus.html HTTP/1.1" 200 None DEBUG:dogpile.cache.region:Cache value generated in 17.178 seconds for key(s): 'py_arris_exporter.handler:process|' DEBUG:dogpile.lock:Released creation lock 127.0.0.1 - - [28/Sep/2020 13:58:28] "GET / HTTP/1.1" 200 - ERROR:main:Exception when trying to write to socket: [Errno 32] Broken pipe 127.0.0.1 - - [28/Sep/2020 13:58:28] "GET / HTTP/1.1" 200 - DEBUG:dogpile.lock:value creation lock <dogpile.cache.region.CacheRegion._LockWrapper object at 0x7fb2b0b53130> acquired DEBUG:dogpile.lock:Calling creation function for previously expired value DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.100.1:80 DEBUG:urllib3.connectionpool:http://192.168.100.1:80 "GET /cmconnectionstatus.html HTTP/1.1" 200 None DEBUG:dogpile.cache.region:Cache value generated in 16.948 seconds for key(s): 'py_arris_exporter.handler:process|' DEBUG:dogpile.lock:Released creation lock 127.0.0.1 - - [28/Sep/2020 13:58:58] "GET / HTTP/1.1" 200 - ERROR:main:Exception when trying to write to socket: [Errno 32] Broken pipe 127.0.0.1 - - [28/Sep/2020 13:58:58] "GET / HTTP/1.1" 200 -

cypherstream commented 4 years ago

I was able to customize handler.py to get most of the SB8200 stats. Its not perfect. For some reason, it only returns 1 upstream channel. Also the SB8200 web page is slower to load so you do get broken pipes in between lookups when it tries to read the page too fast.

Here is the updated code, but again its not perfect.

import re
import logging
from requests import Session
from bs4 import BeautifulSoup
from dogpile.cache import make_region

region = make_region().configure('dogpile.cache.memory',expiration_time=5)

log = logging.getLogger('main')

ARRIS_URL = "http://192.168.100.1/cmconnectionstatus.html"

@region.cache_on_arguments()
def process():
    result_body = []
    s = Session()
    try:
        rs = s.get(ARRIS_URL)
        rs.raise_for_status()
    except Exception as e:
        log.error("exception: %s" % (e))
    html = re.sub(r'(\r|\n|\t)', '', rs.text)
    soup = BeautifulSoup(html, 'html.parser')
    tables = soup.find_all('table', attrs={"class": "simpleTable"})
    for table in tables:
        for tr in table.find_all('tr'):
            tds = tr.find_all('td')
            if (len(tds) == 7):
                if tds[0].get_text() == "Channel":
                    continue
                if tds[2].get_text() == "Locked":
                    locked = 1
                else:
                    locked = 0
                result_body.append("arris_upstream_locked{{index=\"{index}\",channel_id=\"{channel}\",type=\"{modulation}\",frequency=\"{freq}\"}} {locked}"
                        .format(
                            index=tds[0].get_text(),
                            channel=tds[1].get_text(),
                            modulation=tds[3].get_text(),
                            freq=tds[4].get_text().split(' ')[0],
                            locked=locked))
                result_body.append("arris_upstream_symbol_rate{{index=\"{index}\",channel_id=\"{channel}\",type=\"{modulation}\",frequency=\"{freq}\"}} {rate}"
                        .format(
                            index=tds[0].get_text(),
                            channel=tds[1].get_text(),
                            modulation=tds[3].get_text(),
                            freq=tds[4].get_text().split(' ')[0],
                            rate=tds[5].get_text().strip().split(' ')[0]))
                result_body.append("arris_upstream_power{{index=\"{index}\",channel_id=\"{channel}\",type=\"{modulation}\",frequency=\"{freq}\"}} {power}"
                        .format(
                            index=tds[0].get_text(),
                            channel=tds[1].get_text(),
                            modulation=tds[3].get_text(),
                            freq=tds[4].get_text().split(' ')[0],
                            power=tds[6].get_text().strip().split(' ')[0]))
            elif (len(tds) == 8):
                if tds[0].get_text() == "Channel ID":
                    continue
                if tds[1].get_text() == "Locked":
                    locked = 1
                else:
                    locked = 0
                result_body.append("arris_downstream_locked{{index=\"{index}\",modulation=\"{modulation}\",channel_id=\"{channel}\",frequency=\"{freq}\"}} {locked}"
                        .format(
                            index=tds[0].get_text(),
                            modulation=tds[2].get_text(),
                            channel=tds[0].get_text(),
                            freq=tds[3].get_text().split(' ')[0],
                            locked=locked))
                result_body.append("arris_downstream_packets_corrected{{index=\"{index}\",modulation=\"{modulation}\",channel_id=\"{channel}\",frequency=\"{freq}\"}} {corrected}"
                        .format(
                            index=tds[0].get_text(),
                            modulation=tds[2].get_text(),
                            channel=tds[0].get_text(),
                            freq=tds[3].get_text().split(' ')[0],
                            corrected=tds[6].get_text()))
                result_body.append("arris_downstream_packets_uncorrectable{{index=\"{index}\",modulation=\"{modulation}\",channel_id=\"{channel}\",frequency=\"{freq}\"}} {uncorrectable}"
                        .format(
                            index=tds[0].get_text(),
                            modulation=tds[2].get_text(),
                            channel=tds[0].get_text(),
                            freq=tds[3].get_text().split(' ')[0],
                            uncorrectable=tds[7].get_text()))
                result_body.append("arris_downstream_power{{index=\"{index}\",modulation=\"{modulation}\",channel_id=\"{channel}\",frequency=\"{freq}\"}} {power}"
                        .format(
                            index=tds[0].get_text(),
                            modulation=tds[2].get_text(),
                            channel=tds[0].get_text(),
                            freq=tds[3].get_text().split(' ')[0],
                            power=tds[4].get_text().strip().split(' ')[0]))
                result_body.append("arris_downstream_snr{{index=\"{index}\",modulation=\"{modulation}\",channel_id=\"{channel}\",frequency=\"{freq}\"}} {snr}"
                        .format(
                            index=tds[0].get_text(),
                            modulation=tds[2].get_text(),
                            channel=tds[0].get_text(),
                            freq=tds[3].get_text().split(' ')[0],
                            snr=tds[5].get_text().strip().split(' ')[0]))
            else:
                for tdstr in tds:
                    if re.search(r'Connectivity State',tdstr.get_text()):

                        if tds[1].get_text() == "OK":
                            state = 1
                        else:
                            state = 0
                        result_body.append("arris_connectivity_state{{}} {state}"
                            .format(state=state))
    return '\n'.join(str(x) for x in result_body)

sb8200down sb8200up

output from port 9393 webserver arris_connectivity_state{} 1 arris_downstream_locked{index="15",modulation="QAM256",channel_id="15",frequency="675000000"} 1 arris_downstream_packets_corrected{index="15",modulation="QAM256",channel_id="15",frequency="675000000"} 0 arris_downstream_packets_uncorrectable{index="15",modulation="QAM256",channel_id="15",frequency="675000000"} 0 arris_downstream_power{index="15",modulation="QAM256",channel_id="15",frequency="675000000"} -4.0 arris_downstream_snr{index="15",modulation="QAM256",channel_id="15",frequency="675000000"} 41.0 arris_downstream_locked{index="1",modulation="QAM256",channel_id="1",frequency="591000000"} 1 arris_downstream_packets_corrected{index="1",modulation="QAM256",channel_id="1",frequency="591000000"} 0 arris_downstream_packets_uncorrectable{index="1",modulation="QAM256",channel_id="1",frequency="591000000"} 0 arris_downstream_power{index="1",modulation="QAM256",channel_id="1",frequency="591000000"} -4.0 arris_downstream_snr{index="1",modulation="QAM256",channel_id="1",frequency="591000000"} 41.0 arris_downstream_locked{index="2",modulation="QAM256",channel_id="2",frequency="597000000"} 1 arris_downstream_packets_corrected{index="2",modulation="QAM256",channel_id="2",frequency="597000000"} 0 arris_downstream_packets_uncorrectable{index="2",modulation="QAM256",channel_id="2",frequency="597000000"} 0 arris_downstream_power{index="2",modulation="QAM256",channel_id="2",frequency="597000000"} -3.9 arris_downstream_snr{index="2",modulation="QAM256",channel_id="2",frequency="597000000"} 41.2 arris_downstream_locked{index="3",modulation="QAM256",channel_id="3",frequency="603000000"} 1 arris_downstream_packets_corrected{index="3",modulation="QAM256",channel_id="3",frequency="603000000"} 0 arris_downstream_packets_uncorrectable{index="3",modulation="QAM256",channel_id="3",frequency="603000000"} 0 arris_downstream_power{index="3",modulation="QAM256",channel_id="3",frequency="603000000"} -4.3 arris_downstream_snr{index="3",modulation="QAM256",channel_id="3",frequency="603000000"} 41.1 arris_downstream_locked{index="4",modulation="QAM256",channel_id="4",frequency="609000000"} 1 arris_downstream_packets_corrected{index="4",modulation="QAM256",channel_id="4",frequency="609000000"} 0 arris_downstream_packets_uncorrectable{index="4",modulation="QAM256",channel_id="4",frequency="609000000"} 0 arris_downstream_power{index="4",modulation="QAM256",channel_id="4",frequency="609000000"} -4.7 arris_downstream_snr{index="4",modulation="QAM256",channel_id="4",frequency="609000000"} 40.9 arris_downstream_locked{index="5",modulation="QAM256",channel_id="5",frequency="615000000"} 1 arris_downstream_packets_corrected{index="5",modulation="QAM256",channel_id="5",frequency="615000000"} 0 arris_downstream_packets_uncorrectable{index="5",modulation="QAM256",channel_id="5",frequency="615000000"} 0 arris_downstream_power{index="5",modulation="QAM256",channel_id="5",frequency="615000000"} -4.7 arris_downstream_snr{index="5",modulation="QAM256",channel_id="5",frequency="615000000"} 41.0 arris_downstream_locked{index="6",modulation="QAM256",channel_id="6",frequency="621000000"} 1 arris_downstream_packets_corrected{index="6",modulation="QAM256",channel_id="6",frequency="621000000"} 0 arris_downstream_packets_uncorrectable{index="6",modulation="QAM256",channel_id="6",frequency="621000000"} 0 arris_downstream_power{index="6",modulation="QAM256",channel_id="6",frequency="621000000"} -4.7 arris_downstream_snr{index="6",modulation="QAM256",channel_id="6",frequency="621000000"} 41.1 arris_downstream_locked{index="7",modulation="QAM256",channel_id="7",frequency="627000000"} 1 arris_downstream_packets_corrected{index="7",modulation="QAM256",channel_id="7",frequency="627000000"} 0 arris_downstream_packets_uncorrectable{index="7",modulation="QAM256",channel_id="7",frequency="627000000"} 0 arris_downstream_power{index="7",modulation="QAM256",channel_id="7",frequency="627000000"} -5.1 arris_downstream_snr{index="7",modulation="QAM256",channel_id="7",frequency="627000000"} 41.0 arris_downstream_locked{index="8",modulation="QAM256",channel_id="8",frequency="633000000"} 1 arris_downstream_packets_corrected{index="8",modulation="QAM256",channel_id="8",frequency="633000000"} 0 arris_downstream_packets_uncorrectable{index="8",modulation="QAM256",channel_id="8",frequency="633000000"} 0 arris_downstream_power{index="8",modulation="QAM256",channel_id="8",frequency="633000000"} -5.4 arris_downstream_snr{index="8",modulation="QAM256",channel_id="8",frequency="633000000"} 40.9 arris_downstream_locked{index="9",modulation="QAM256",channel_id="9",frequency="639000000"} 1 arris_downstream_packets_corrected{index="9",modulation="QAM256",channel_id="9",frequency="639000000"} 0 arris_downstream_packets_uncorrectable{index="9",modulation="QAM256",channel_id="9",frequency="639000000"} 0 arris_downstream_power{index="9",modulation="QAM256",channel_id="9",frequency="639000000"} -5.0 arris_downstream_snr{index="9",modulation="QAM256",channel_id="9",frequency="639000000"} 41.0 arris_downstream_locked{index="10",modulation="QAM256",channel_id="10",frequency="645000000"} 1 arris_downstream_packets_corrected{index="10",modulation="QAM256",channel_id="10",frequency="645000000"} 0 arris_downstream_packets_uncorrectable{index="10",modulation="QAM256",channel_id="10",frequency="645000000"} 0 arris_downstream_power{index="10",modulation="QAM256",channel_id="10",frequency="645000000"} -4.4 arris_downstream_snr{index="10",modulation="QAM256",channel_id="10",frequency="645000000"} 41.3 arris_downstream_locked{index="11",modulation="QAM256",channel_id="11",frequency="651000000"} 1 arris_downstream_packets_corrected{index="11",modulation="QAM256",channel_id="11",frequency="651000000"} 0 arris_downstream_packets_uncorrectable{index="11",modulation="QAM256",channel_id="11",frequency="651000000"} 0 arris_downstream_power{index="11",modulation="QAM256",channel_id="11",frequency="651000000"} -4.2 arris_downstream_snr{index="11",modulation="QAM256",channel_id="11",frequency="651000000"} 41.4 arris_downstream_locked{index="12",modulation="QAM256",channel_id="12",frequency="657000000"} 1 arris_downstream_packets_corrected{index="12",modulation="QAM256",channel_id="12",frequency="657000000"} 0 arris_downstream_packets_uncorrectable{index="12",modulation="QAM256",channel_id="12",frequency="657000000"} 0 arris_downstream_power{index="12",modulation="QAM256",channel_id="12",frequency="657000000"} -4.3 arris_downstream_snr{index="12",modulation="QAM256",channel_id="12",frequency="657000000"} 41.2 arris_downstream_locked{index="13",modulation="QAM256",channel_id="13",frequency="663000000"} 1 arris_downstream_packets_corrected{index="13",modulation="QAM256",channel_id="13",frequency="663000000"} 0 arris_downstream_packets_uncorrectable{index="13",modulation="QAM256",channel_id="13",frequency="663000000"} 0 arris_downstream_power{index="13",modulation="QAM256",channel_id="13",frequency="663000000"} -4.0 arris_downstream_snr{index="13",modulation="QAM256",channel_id="13",frequency="663000000"} 41.2 arris_downstream_locked{index="14",modulation="QAM256",channel_id="14",frequency="669000000"} 1 arris_downstream_packets_corrected{index="14",modulation="QAM256",channel_id="14",frequency="669000000"} 0 arris_downstream_packets_uncorrectable{index="14",modulation="QAM256",channel_id="14",frequency="669000000"} 0 arris_downstream_power{index="14",modulation="QAM256",channel_id="14",frequency="669000000"} -3.8 arris_downstream_snr{index="14",modulation="QAM256",channel_id="14",frequency="669000000"} 41.4 arris_downstream_locked{index="16",modulation="QAM256",channel_id="16",frequency="681000000"} 1 arris_downstream_packets_corrected{index="16",modulation="QAM256",channel_id="16",frequency="681000000"} 0 arris_downstream_packets_uncorrectable{index="16",modulation="QAM256",channel_id="16",frequency="681000000"} 0 arris_downstream_power{index="16",modulation="QAM256",channel_id="16",frequency="681000000"} -4.0 arris_downstream_snr{index="16",modulation="QAM256",channel_id="16",frequency="681000000"} 41.3 arris_downstream_locked{index="17",modulation="QAM256",channel_id="17",frequency="543000000"} 1 arris_downstream_packets_corrected{index="17",modulation="QAM256",channel_id="17",frequency="543000000"} 0 arris_downstream_packets_uncorrectable{index="17",modulation="QAM256",channel_id="17",frequency="543000000"} 0 arris_downstream_power{index="17",modulation="QAM256",channel_id="17",frequency="543000000"} -4.7 arris_downstream_snr{index="17",modulation="QAM256",channel_id="17",frequency="543000000"} 41.1 arris_downstream_locked{index="18",modulation="QAM256",channel_id="18",frequency="549000000"} 1 arris_downstream_packets_corrected{index="18",modulation="QAM256",channel_id="18",frequency="549000000"} 0 arris_downstream_packets_uncorrectable{index="18",modulation="QAM256",channel_id="18",frequency="549000000"} 0 arris_downstream_power{index="18",modulation="QAM256",channel_id="18",frequency="549000000"} -4.4 arris_downstream_snr{index="18",modulation="QAM256",channel_id="18",frequency="549000000"} 41.1 arris_downstream_locked{index="19",modulation="QAM256",channel_id="19",frequency="555000000"} 1 arris_downstream_packets_corrected{index="19",modulation="QAM256",channel_id="19",frequency="555000000"} 0 arris_downstream_packets_uncorrectable{index="19",modulation="QAM256",channel_id="19",frequency="555000000"} 0 arris_downstream_power{index="19",modulation="QAM256",channel_id="19",frequency="555000000"} -4.4 arris_downstream_snr{index="19",modulation="QAM256",channel_id="19",frequency="555000000"} 41.1 arris_downstream_locked{index="20",modulation="QAM256",channel_id="20",frequency="561000000"} 1 arris_downstream_packets_corrected{index="20",modulation="QAM256",channel_id="20",frequency="561000000"} 0 arris_downstream_packets_uncorrectable{index="20",modulation="QAM256",channel_id="20",frequency="561000000"} 0 arris_downstream_power{index="20",modulation="QAM256",channel_id="20",frequency="561000000"} -4.1 arris_downstream_snr{index="20",modulation="QAM256",channel_id="20",frequency="561000000"} 41.3 arris_downstream_locked{index="21",modulation="QAM256",channel_id="21",frequency="567000000"} 1 arris_downstream_packets_corrected{index="21",modulation="QAM256",channel_id="21",frequency="567000000"} 0 arris_downstream_packets_uncorrectable{index="21",modulation="QAM256",channel_id="21",frequency="567000000"} 0 arris_downstream_power{index="21",modulation="QAM256",channel_id="21",frequency="567000000"} -4.2 arris_downstream_snr{index="21",modulation="QAM256",channel_id="21",frequency="567000000"} 41.2 arris_downstream_locked{index="22",modulation="QAM256",channel_id="22",frequency="573000000"} 1 arris_downstream_packets_corrected{index="22",modulation="QAM256",channel_id="22",frequency="573000000"} 0 arris_downstream_packets_uncorrectable{index="22",modulation="QAM256",channel_id="22",frequency="573000000"} 0 arris_downstream_power{index="22",modulation="QAM256",channel_id="22",frequency="573000000"} -3.8 arris_downstream_snr{index="22",modulation="QAM256",channel_id="22",frequency="573000000"} 41.5 arris_downstream_locked{index="23",modulation="QAM256",channel_id="23",frequency="579000000"} 1 arris_downstream_packets_corrected{index="23",modulation="QAM256",channel_id="23",frequency="579000000"} 0 arris_downstream_packets_uncorrectable{index="23",modulation="QAM256",channel_id="23",frequency="579000000"} 0 arris_downstream_power{index="23",modulation="QAM256",channel_id="23",frequency="579000000"} -3.9 arris_downstream_snr{index="23",modulation="QAM256",channel_id="23",frequency="579000000"} 41.2 arris_downstream_locked{index="24",modulation="QAM256",channel_id="24",frequency="585000000"} 1 arris_downstream_packets_corrected{index="24",modulation="QAM256",channel_id="24",frequency="585000000"} 0 arris_downstream_packets_uncorrectable{index="24",modulation="QAM256",channel_id="24",frequency="585000000"} 0 arris_downstream_power{index="24",modulation="QAM256",channel_id="24",frequency="585000000"} -3.8 arris_downstream_snr{index="24",modulation="QAM256",channel_id="24",frequency="585000000"} 41.4 arris_downstream_locked{index="25",modulation="Other",channel_id="25",frequency="840000000"} 1 arris_downstream_packets_corrected{index="25",modulation="Other",channel_id="25",frequency="840000000"} 138253493 arris_downstream_packets_uncorrectable{index="25",modulation="Other",channel_id="25",frequency="840000000"} 0 arris_downstream_power{index="25",modulation="Other",channel_id="25",frequency="840000000"} -7.0 arris_downstream_snr{index="25",modulation="Other",channel_id="25",frequency="840000000"} 38.2 arris_upstream_locked{index="4",channel_id="4",type="SC-QAM",frequency="38500000"} 1 arris_upstream_symbol_rate{index="4",channel_id="4",type="SC-QAM",frequency="38500000"} 6400000 arris_upstream_power{index="4",channel_id="4",type="SC-QAM",frequency="38500000"} 45.0

PeterGrace commented 3 years ago

Hey @cypherstream !

Funny story, I just upgraded my SB6184 to an SB8200 and said "oh, I need to dust the project off and fix it so it works with the SB8200".

Come to find you've done the work already!

If you're familiar with making a pull request (and want the dubious honor of being listed as a committer on the page) feel free to put a pull request in to update to SB8200; otherwise I'll update the repo in a few days with your updated code and credit.

cypherstream commented 3 years ago

Cool, yeah I tried to do pull request but its greyed out. I have to read more about it. I've never "officially" contributed to a project on github before outside of maybe a discussion.

I can tell you that my grafana instance is plotting all of the data polled from this, along with other aspects from my pfsense install and UniFi gear. Here's an example of my Cable Modem dashboard which is using the data from this project. You can correlate signal fluctuations with outside temperature as it affects signal attenuation.

cable-modem