8000 Merge pull request #52 from mafagafogigante/graphite.py · shamrin/client_python@c67b1e1 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c67b1e1

Browse files
committed
Merge pull request prometheus#52 from mafagafogigante/graphite.py
Fixed graphite.py formatting.
2 parents 91a928b + ac88040 commit c67b1e1

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 10000
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)
0