MCPcopy Index your code
hub / github.com/prometheus/client_python / push

Method push

prometheus_client/bridge/graphite.py:62–89  ·  view source on GitHub ↗
(self, prefix: str = '')

Source from the content-addressed store, hash-verified

60 self._timer = _timer
61
62 def push(self, prefix: str = '') -> None:
63 now = int(self._timer())
64 output = []
65
66 prefixstr = ''
67 if prefix:
68 prefixstr = prefix + '.'
69
70 for metric in self._registry.collect():
71 for s in metric.samples:
72 if s.labels:
73 if self._tags:
74 sep = ';'
75 fmt = '{0}={1}'
76 else:
77 sep = '.'
78 fmt = '{0}.{1}'
79 labelstr = sep + sep.join(
80 [fmt.format(
81 _sanitize(k), _sanitize(v))
82 for k, v in sorted(s.labels.items())])
83 else:
84 labelstr = ''
85 output.append(f'{prefixstr}{_sanitize(s.name)}{labelstr} {float(s.value)} {now}\n')
86
87 conn = socket.create_connection(self._address, self._timeout)
88 conn.sendall(''.join(output).encode('ascii'))
89 conn.close()
90
91 def start(self, interval: float = 60.0, prefix: str = '') -> None:
92 t = _RegularPush(self, interval, prefix)

Callers 8

runMethod · 0.45
test_nolabelsMethod · 0.45
test_labelsMethod · 0.45
test_labels_tagsMethod · 0.45
test_prefixMethod · 0.45
test_prefix_tagsMethod · 0.45
test_sanitizingMethod · 0.45
test_sanitizing_tagsMethod · 0.45

Calls 4

_sanitizeFunction · 0.85
joinMethod · 0.80
closeMethod · 0.80
collectMethod · 0.45

Tested by 7

test_nolabelsMethod · 0.36
test_labelsMethod · 0.36
test_labels_tagsMethod · 0.36
test_prefixMethod · 0.36
test_prefix_tagsMethod · 0.36
test_sanitizingMethod · 0.36
test_sanitizing_tagsMethod · 0.36