Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac88040

Browse files
author
Bernardo Sulzbach
committed
Fixed graphite.py formatting.
This file had varying indentation levels. There was also an unused local.
1 parent 91a928b commit ac88040

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

prometheus_client/bridge/graphite.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# We also remove periods, so labels can be distinguished.
1414
_INVALID_GRAPHITE_CHARS = re.compile(r"[^a-zA-Z0-9_-]")
1515

16+
1617
def _sanitize(s):
17-
return _INVALID_GRAPHITE_CHARS.sub('_', s)
18-
18+
return _INVALID_GRAPHITE_CHARS.sub('_', s)
1919

20-
class _RegularPush(threading.Thread):
2120

21+
class _RegularPush(threading.Thread):
2222
def __init__(self, pusher, interval):
2323
super(_RegularPush, self).__init__()
2424
self._pusher = pusher
@@ -30,15 +30,15 @@ def run(self):
3030
while True:
3131
now = time.time()
3232
if now >= wait_until:
33-
# May need to skip some pushes.
34-
while wait_until < now:
35-
wait_until += self._interval
36-
break
33+
# May need to skip some pushes.
34+
while wait_until < now:
35+
wait_until += self._interval
36+
break
3737
# time.sleep can return early.
3838
time.sleep(wait_until - now)
3939
try:
4040
self._pusher.push()
41-
except IOError as e:
41+
except IOError:
4242
logging.exception("Push failed")
4343

4444

@@ -50,27 +50,25 @@ def __init__(self, address, registry=core.REGISTRY, timeout_seconds=30, _time=ti
5050
self._time = _time
5151

5252
def push(self):
53-
now = int(self._time.time())
54-
output = []
55-
for metric in self._registry.collect():
56-
for name, labels, value in metric._samples:
57-
if labels:
58-
labelstr = '.' + '.'.join(
59-
['{0}.{1}'.format(
60-
_sanitize(k), _sanitize(v))
61-
for k, v in sorted(labels.items())])
62-
else:
63-
labelstr = ''
64-
output.append('{0}{1} {2} {3}\n'.format(
65-
_sanitize(name), labelstr, float(value), now))
53+
now = int(self._time.time())
54+
output = []
55+
for metric in self._registry.collect():
56+
for name, labels, value in metric._samples:
57+
if labels:
58+
labelstr = '.' + '.'.join(
59+
['{0}.{1}'.format(
60+
_sanitize(k), _sanitize(v))
61+
for k, v in sorted(labels.items())])
62+
else:
63+
labelstr = ''
64+
output.append('{0}{1} {2} {3}\n'.format(
65+
_sanitize(name), labelstr, float(value), now))
6666

67-
conn = socket.create_connection(self._address, self._timeout)
68-
conn.sendall(''.join(output).encode('ascii'))
69-
conn.close()
67+
conn = socket.create_connection(self._address, self._timeout)
68+
conn.sendall(''.join(output).encode('ascii'))
69+
conn.close()
7070

7171
def start(self, interval=60.0):
7272
t = _RegularPush(self, interval)
7373
t.daemon = True
7474
t.start()
75-
76-

0 commit comments

Comments
 (0)