mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-27 03:14:45 +00:00
Code style (Black) and linting (PyFlakes) changes
This commit is contained in:
parent
99dfc5d16e
commit
f537b44b9b
1 changed files with 54 additions and 31 deletions
|
@ -97,6 +97,7 @@ examples [4] provided by Arturo Borrero Gonzalez.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from nftables import Nftables
|
from nftables import Nftables
|
||||||
from nftables import json
|
from nftables import json
|
||||||
|
@ -137,6 +138,7 @@ def nft_cmd(nftlib, cmd):
|
||||||
|
|
||||||
return ruleset
|
return ruleset
|
||||||
|
|
||||||
|
|
||||||
def getCounters():
|
def getCounters():
|
||||||
|
|
||||||
nft = Nftables()
|
nft = Nftables()
|
||||||
|
@ -161,7 +163,6 @@ class MuninNftCountersPlugin(MuninPlugin):
|
||||||
plugin_name = "nft_counters"
|
plugin_name = "nft_counters"
|
||||||
isMultigraph = True
|
isMultigraph = True
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, argv=(), env=None, debug=False):
|
def __init__(self, argv=(), env=None, debug=False):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -194,34 +195,46 @@ class MuninNftCountersPlugin(MuninPlugin):
|
||||||
if self._argv[1] == "autoconf":
|
if self._argv[1] == "autoconf":
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("# No counters in nftables. Try adding some first.",
|
print(
|
||||||
"# See 'munin-doc %s' for more information." % self.plugin_name,
|
"# No counters in nftables. Try adding some first.",
|
||||||
sep="\n")
|
"# See 'munin-doc %s' for more information." % self.plugin_name,
|
||||||
|
sep="\n",
|
||||||
|
)
|
||||||
raise
|
raise
|
||||||
except Exception as err:
|
except Exception:
|
||||||
if self._argv[1] == "autoconf":
|
if self._argv[1] == "autoconf":
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("# Plugin needs to be run as root since nftables can only be",
|
print(
|
||||||
"# run as root.",
|
"# Plugin needs to be run as root since nftables can only be",
|
||||||
"#",
|
"# run as root.",
|
||||||
"# Use the following setting in the configuration file",
|
"#",
|
||||||
"# to enable root privileges:",
|
"# Use the following setting in the configuration file",
|
||||||
"#",
|
"# to enable root privileges:",
|
||||||
"# [%s]" % self.plugin_name,
|
"#",
|
||||||
"# user root",
|
"# [%s]" % self.plugin_name,
|
||||||
sep="\n")
|
"# user root",
|
||||||
|
sep="\n",
|
||||||
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
count_only = self.envGet("count_only")
|
count_only = self.envGet("count_only")
|
||||||
|
|
||||||
# Create the graphs
|
# Create the graphs
|
||||||
if not (count_only == "bytes"):
|
if not (count_only == "bytes"):
|
||||||
graph_packets = MuninGraph("nftables counters (packets)", graph_category,
|
graph_packets = MuninGraph(
|
||||||
vlabel="packets / second", args="--base 1000")
|
"nftables counters (packets)",
|
||||||
|
graph_category,
|
||||||
|
vlabel="packets / second",
|
||||||
|
args="--base 1000",
|
||||||
|
)
|
||||||
if not (count_only == "packets"):
|
if not (count_only == "packets"):
|
||||||
graph_bytes = MuninGraph("nftables counters (bytes)", graph_category,
|
graph_bytes = MuninGraph(
|
||||||
vlabel="bytes / second", args="--base 1024")
|
"nftables counters (bytes)",
|
||||||
|
graph_category,
|
||||||
|
vlabel="bytes / second",
|
||||||
|
args="--base 1024",
|
||||||
|
)
|
||||||
|
|
||||||
# Define filter to allow for tuning of counters graphed
|
# Define filter to allow for tuning of counters graphed
|
||||||
self.envRegisterFilter("counters")
|
self.envRegisterFilter("counters")
|
||||||
|
@ -232,23 +245,32 @@ class MuninNftCountersPlugin(MuninPlugin):
|
||||||
# Until it does, use counter name as info
|
# Until it does, use counter name as info
|
||||||
try:
|
try:
|
||||||
field_info = counter["comment"]
|
field_info = counter["comment"]
|
||||||
except:
|
except Exception:
|
||||||
field_info = counter["name"]
|
field_info = counter["name"]
|
||||||
|
|
||||||
if self.envCheckFilter("counters", counter["name"]):
|
if self.envCheckFilter("counters", counter["name"]):
|
||||||
if not (count_only == "bytes"):
|
if not (count_only == "bytes"):
|
||||||
graph_packets.addField(counter["name"], counter["name"], min=0,
|
graph_packets.addField(
|
||||||
type="DERIVE", info=field_info)
|
counter["name"],
|
||||||
|
counter["name"],
|
||||||
|
min=0,
|
||||||
|
type="DERIVE",
|
||||||
|
info=field_info,
|
||||||
|
)
|
||||||
if not (count_only == "packets"):
|
if not (count_only == "packets"):
|
||||||
graph_bytes.addField(counter["name"], counter["name"], min=0,
|
graph_bytes.addField(
|
||||||
type="DERIVE", info=field_info)
|
counter["name"],
|
||||||
|
counter["name"],
|
||||||
|
min=0,
|
||||||
|
type="DERIVE",
|
||||||
|
info=field_info,
|
||||||
|
)
|
||||||
|
|
||||||
if not (count_only == "bytes"):
|
if not (count_only == "bytes"):
|
||||||
self.appendGraph("nft_counters_packets", graph_packets)
|
self.appendGraph("nft_counters_packets", graph_packets)
|
||||||
if not (count_only == "packets"):
|
if not (count_only == "packets"):
|
||||||
self.appendGraph("nft_counters_bytes", graph_bytes)
|
self.appendGraph("nft_counters_bytes", graph_bytes)
|
||||||
|
|
||||||
|
|
||||||
def retrieveVals(self):
|
def retrieveVals(self):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -264,12 +286,13 @@ class MuninNftCountersPlugin(MuninPlugin):
|
||||||
for counter in self.counters:
|
for counter in self.counters:
|
||||||
if self.envCheckFilter("counters", counter["name"]):
|
if self.envCheckFilter("counters", counter["name"]):
|
||||||
if self.hasGraph("nft_counters_packets"):
|
if self.hasGraph("nft_counters_packets"):
|
||||||
self.setGraphVal("nft_counters_packets", counter["name"],
|
self.setGraphVal(
|
||||||
counter["packets"])
|
"nft_counters_packets", counter["name"], counter["packets"]
|
||||||
|
)
|
||||||
if self.hasGraph("nft_counters_bytes"):
|
if self.hasGraph("nft_counters_bytes"):
|
||||||
self.setGraphVal("nft_counters_bytes", counter["name"],
|
self.setGraphVal(
|
||||||
counter["bytes"])
|
"nft_counters_bytes", counter["name"], counter["bytes"]
|
||||||
|
)
|
||||||
|
|
||||||
def autoconf(self):
|
def autoconf(self):
|
||||||
"""
|
"""
|
||||||
|
@ -283,9 +306,9 @@ class MuninNftCountersPlugin(MuninPlugin):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
counters = getCounters()
|
getCounters()
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue