Skip to content

Commit 3da7b80

Browse files
ajustes
Signed-off-by: Felipe Monteiro Jácome <[email protected]>
1 parent 2ef7e2a commit 3da7b80

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,8 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"):
621621

622622
* [Releases](https://github.com/prometheus/client_python/releases): The releases page shows the history of the project and acts as a changelog.
623623
* [PyPI](https://pypi.python.org/pypi/prometheus_client)
624+
625+
626+
```
627+
python -m pytest -vv -s -k test_gauge_pandas .\tests\
628+
```

prometheus_client/exposition.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def sample_line(line):
168168
return f'{line.name}{labelstr} {floatToGoString(line.value)}{timestamp}\n'
169169

170170
output = []
171+
output_string = ""
171172
for metric in registry.collect():
172173
try:
173174
mname = metric.name
@@ -186,7 +187,6 @@ def sample_line(line):
186187
mtype = 'histogram'
187188
elif mtype == 'unknown':
188189
mtype = 'untyped'
189-
import pdb; pdb.set_trace()
190190
if 'encoder' not in vars(metric) or ('encoder' in vars(metric) and metric.encoder != 'pandas'):
191191
# normal calls
192192
output.append('# HELP {} {}\n'.format(
@@ -215,8 +215,6 @@ def sample_line(line):
215215
except Exception as exception:
216216
exception.args = (exception.args or ('',)) + (metric,)
217217
raise
218-
import pdb; pdb.set_trace()
219-
220218

221219
return ''.join(output).encode('utf-8')
222220

prometheus_client/metrics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,24 @@ def __repr__(self):
758758
metric_type = type(self)
759759
return f"{metric_type.__module__}.{metric_type.__name__}({self._name})"
760760

761+
def generate_pandas_report(self, value='value', tag='report'):
762+
def make_str(row):
763+
return f"{self._name}({[ f'{col}={row[col]}, ' for col in self._metrics.columns if col not in [value, tag]]})"
764+
765+
# generate another column with metric formated
766+
# make_str = lambda x: "metric01(a={}, b={})".format(x['a'],x['b'])
767+
# a = s.apply(make_str , axis=1)
768+
# https://github.com/prometheus/client_python/discussions/772
769+
770+
self._metrics[value] = self._metrics.apply(make_str, axis=1)
771+
# self._metrics
772+
773+
def set_metric(self, df: pd.DataFrame):
774+
with self._lock:
775+
self._metrics = df
776+
self.generate_pandas_report()
777+
import pdb; pdb.set_trace()
778+
761779
#def __init__(self: T,
762780
# name: str,
763781
# documentation: str,

prometheus_client/registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def _get_names(self, collector):
7171

7272
def collect(self):
7373
"""Yields metrics from the collectors in the registry."""
74-
import pdb; pdb.set_trace()
7574
collectors = None
7675
ti = None
7776
with self._lock:

tests/test_exposition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def test_gauge_pandas(self):
204204
df2.unit = ''
205205
g = PandasGauge(df, registry=self.registry)
206206
g = PandasGauge(df2, registry=self.registry)
207+
g.generate_pandas_report()
207208
import pdb; pdb.set_trace()
208209
self.assertEqual(b'# HELP gg A gauge\n# TYPE gg gauge\ngg 17.0\n', generate_latest(self.registry))
209210

0 commit comments

Comments
 (0)