Skip to content

Commit e9d18b3

Browse files
authored
Linting code (#32)
Linting code according to reported issues from `make lint`.
1 parent b04b73a commit e9d18b3

File tree

6 files changed

+31
-27
lines changed

6 files changed

+31
-27
lines changed

p3exporter/cache/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
"""Module that defines all needed classes and functions for caching facility."""
12
from functools import lru_cache, wraps
23
from datetime import datetime, timedelta
34

5+
46
# found on https://bit.ly/39vlEXs
57
# thanks https://realpython.com/team/svaldarrama/ for your awsome article about caching in python
68
# has been adapted by us to meet our requirements

p3exporter/collector/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CollectorBase(object):
2929
"""
3030

3131
def __init__(self, config: CollectorConfig):
32-
"""Instantiates an CollectorBase object"""
32+
"""Instantiate a CollectorBase object."""
3333
self.collector_name = self.collector_name_from_class
3434
self.opts = config.collector_opts.pop(self.collector_name, {})
3535

@@ -58,7 +58,7 @@ class Collector(object):
5858
"""
5959

6060
def __init__(self, config: CollectorConfig):
61-
"""Instantiates an CollectorBase object"""
61+
"""Instantiate an CollectorBase object."""
6262
for c in config.collectors:
6363
try:
6464
collector_module = import_module("p3exporter.collector.{}".format(c), package=None)

p3exporter/collector/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Module that defines all needed classes and functions for example collector."""
12
import random
23
import time
34

@@ -30,5 +31,5 @@ def collect(self):
3031
@timed_lru_cache(10)
3132
def _run_process():
3233
"""Sample function to ran a command for metrics."""
33-
time.sleep(random.random()) # nosec
34+
time.sleep(random.random()) # nosec
3435
return "sucess"

p3exporter/collector/loadavg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
"""Module that defines all needed classes and functions for loadavg collector."""
12
import os
23

34
from p3exporter.collector import CollectorBase, CollectorConfig
45
from prometheus_client.core import GaugeMetricFamily
56

7+
68
class LoadavgCollector(CollectorBase):
9+
"""Load avg collector class."""
710

811
def __init__(self, config: CollectorConfig):
912
"""Instanciate a CpuCollector object."""
10-
1113
super(LoadavgCollector, self).__init__(config)
1214

1315
def collect(self):

p3exporter/collector/netdev.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
"""Module that defines all needed classes and functions for netdev collector."""
12
import netifaces
23

34
from p3exporter.collector import CollectorBase, CollectorConfig
45
from prometheus_client.core import CounterMetricFamily, InfoMetricFamily
56

67

78
class NetdevCollector(CollectorBase):
9+
"""Netdev collector class."""
810

911
def __init__(self, config: CollectorConfig):
1012
"""Instanciate a NetdevCollector object."""
11-
1213
super(NetdevCollector, self).__init__(config)
1314

1415
self.whitelist = self.opts.pop("whitelist", [])
@@ -21,7 +22,6 @@ def collect(self):
2122
2223
Returns several info, couter and gauge metrics for interfaces.
2324
"""
24-
2525
self.ifaces = netifaces.interfaces()
2626
self.iface_stats = _get_iface_stats()
2727

@@ -69,7 +69,6 @@ def _get_iface_stats():
6969
:return: Returns a dict of dicts. One dict for each interface and one key value pair for each interface statistic in the inner dict.
7070
:rtype: dict
7171
"""
72-
7372
ifaces = {}
7473
f = open("/proc/net/dev")
7574
data = f.read()
@@ -79,26 +78,26 @@ def _get_iface_stats():
7978
if len(i.strip()) > 0:
8079
x = i.split()
8180
k = {
82-
x[0][:len( x[0])-1]: {
83-
"tx" : {
84-
"bytes" : int(x[1]),
85-
"packets" : int(x[2]),
86-
"errs" : int(x[3]),
87-
"drop" : int(x[4]),
88-
"fifo" : int(x[5]),
89-
"frame" : int(x[6]),
90-
"compressed" : int(x[7]),
91-
"multicast" : int(x[8])
81+
x[0][:len(x[0]) - 1]: {
82+
"tx": {
83+
"bytes": int(x[1]),
84+
"packets": int(x[2]),
85+
"errs": int(x[3]),
86+
"drop": int(x[4]),
87+
"fifo": int(x[5]),
88+
"frame": int(x[6]),
89+
"compressed": int(x[7]),
90+
"multicast": int(x[8])
9291
},
93-
"rx" : {
94-
"bytes" : int(x[9]),
95-
"packets" : int(x[10]),
96-
"errs" : int(x[11]),
97-
"drop" : int(x[12]),
98-
"fifo" : int(x[13]),
99-
"frame" : int(x[14]),
100-
"compressed" : int(x[15]),
101-
"multicast" : int(x[16])
92+
"rx": {
93+
"bytes": int(x[9]),
94+
"packets": int(x[10]),
95+
"errs": int(x[11]),
96+
"drop": int(x[12]),
97+
"fifo": int(x[13]),
98+
"frame": int(x[14]),
99+
"compressed": int(x[15]),
100+
"multicast": int(x[16])
102101
}
103102
}
104103
}

p3exporter/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_app(config: CollectorConfig):
2020
app = Flask(__name__, instance_relative_config=True)
2121

2222
@app.route("/")
23-
def index(): # pylint: disable=W0612
23+
def index(): # pylint: disable=W0612
2424
return render_template("index.html", title=config.exporter_name)
2525

2626
dispatched_app = DispatcherMiddleware(app, {

0 commit comments

Comments
 (0)