Github Mirror / telegraf-plugins: 5a87bede




Capture the rest if the stats on the homepage

Capture the rest if the stats on the homepage

Example LP

i2pd,url=http://localhost:7070,version=2.41.0,network_status=Firewalled,network_status_v6=disabled uptime=69626i,tunnel_creation_success_rate=66,in_bytes=83589.12i,in_avg_bps=9830.4,out_bytes=74403.84i,out_avg_bps=9011.2,transit_bytes=0.0i,transit_avg_bps=0.0,routers=1285i,floodfills=798i,leasesets=0i,clienttunnels=25i,transittunnels=0i

Commit 5a87bede.

Authored 2022-03-13T12:20:09.000+00:00 by B Tasker in project Github Mirror / telegraf-plugins

+91 lines -5 lines

Commit Signature

Changes

diff --git a/i2pd-statistics/i2pd-statistics.py b/i2pd-statistics/i2pd-statistics.py
--- a/i2pd-statistics/i2pd-statistics.py
+++ b/i2pd-statistics/i2pd-statistics.py
# @@ -31,17 +31,34 @@ def process_uptime(inp):
# seconds = (int(res["hours"][0]) * 3600) + (int(res["minutes"][0]) * 60) + int(res["seconds"][0])
# return seconds
#
# -
# +def process_netstatus(inp):
# + ''' Extract the reported network status
# +
# + Valid values are defined here https://github.com/PurpleI2P/i2pd/blob/openssl/daemon/HTTPServer.cpp#L223
# + '''
# + return inp.split("</b>")[1].lstrip()
# +
# def process_percentage(inp):
# ''' Extract a percentage value
# '''
#
# - perc = getMatches(inp, "([0-9]+)%")
# + perc = getMatches(inp, "([0-9,\.]+)%")
# if len(perc) == 0:
# return 0
# else:
# return perc[0]
# -
# +
# +
# +def extract_number(inp):
# + ''' Extract an integer
# + '''
# + i = getMatches(inp, "([0-9]+)")
# + if len(i) == 0:
# + i = ["0"]
# +
# + return int(i[0])
# +
# +
# def extract_throughput(inp):
# ''' The unit changes based on volume, but the minimum unit used is KiB
#
# @@ -77,6 +94,41 @@ def extract_throughput(inp):
# return vol, through
#
#
# +def extract_version(inp):
# + ''' Extract the version string
# + '''
# + ver = getMatches(inp, "([0-9,\.]+)")
# + if len(ver) == 0:
# + ver = ['unknown']
# +
# + return ver[0]
# +
# +def split_counter_row(inp):
# + ''' The counter row is a single line with multiple counters on it
# + '''
# +
# + routers = 0
# + floodfills = 0
# + leasesets = 0
# + clienttunnels = 0
# + transittunnels = 0
# +
# + lines = inp.split('<b>')
# + for line in lines:
# + if line.startswith("Routers:"):
# + routers = extract_number(line)
# + elif line.startswith("Floodfills:"):
# + floodfills = extract_number(line)
# + elif line.startswith("LeaseSets:"):
# + leasesets = extract_number(line)
# + elif line.startswith("Client Tunnels:"):
# + clienttunnels = extract_number(line)
# + elif line.startswith("Transit Tunnels:"):
# + transittunnels = extract_number(line)
# +
# + return routers, floodfills, leasesets, clienttunnels, transittunnels
# +
# +
# homepage = getPage("/", HOST)
# #print(homepage)
#
# @@ -84,9 +136,15 @@ homepage = getPage("/", HOST)
# bold_fields = getMatches(homepage, "<b>(.+)<br>")
# #print(bold_fields)
#
# +network_status_v6 = "disabled"
# +
# for line in bold_fields:
# if line.startswith("Uptime:"):
# uptime = process_uptime(line)
# + if line.startswith("Network status:"):
# + network_status = process_netstatus(line)
# + if line.startswith("Network status v6:"):
# + network_status_v6 = process_netstatus(line)
# elif line.startswith("Tunnel creation success rate:"):
# creation_success = process_percentage(line)
# elif line.startswith("Received:"):
# @@ -95,7 +153,19 @@ for line in bold_fields:
# out_vol, out_through = extract_throughput(line)
# elif line.startswith("Transit:"):
# transit_vol, transit_through = extract_throughput(line)
# + elif line.startswith("Version:"):
# + version = extract_version(line)
# + elif line.startswith("Routers:"):
# + routers, floodfills, leasesets, x, y = split_counter_row(line)
# + elif line.startswith("Client Tunnels:"):
# + x, y, z, clienttunnels, transittunnels = split_counter_row(line)
# +
# +
#
# +
# +
# +
# +
#
#
# fields = "uptime={uptime}i,tunnel_creation_success_rate={success_rate},in_bytes={in_bytes}i,in_avg_bps={in_bps}".format(
# @@ -115,9 +185,25 @@ fields = "{fields},out_bytes={out_bytes}i,out_avg_bps={out_bps},transit_bytes={t
# transit_bps = transit_through
# )
#
# -lp = "{measurement},url={url} {fields}".format(
# +fields = "{fields},routers={routers}i,floodfills={floodfills}i,leasesets={leasesets}i,clienttunnels={clienttunnels}i,transittunnels={transittunnels}i".format(
# + fields = fields,
# + routers = routers,
# + floodfills = floodfills,
# + leasesets = leasesets,
# + clienttunnels = clienttunnels,
# + transittunnels = transittunnels
# + )
# +
# +tags = "url={url},version={version},network_status={network_status},network_status_v6={network_status_v6}".format(
# + url = HOST,
# + version = version,
# + network_status = network_status,
# + network_status_v6 = network_status_v6
# + )
# +
# +lp = "{measurement},{tags} {fields}".format(
# measurement = MEASUREMENT,
# - url = HOST,
# + tags = tags,
# fields = fields
# )
#
#