@@ -103,15 +103,17 @@ def _parse_labels(labels_string):
103
103
104
104
105
105
# If we have multiple values only consider the first
106
- def _parse_value (s ):
106
+ def _parse_value_and_timestamp (s ):
107
107
s = s .lstrip ()
108
108
separator = " "
109
109
if separator not in s :
110
110
separator = "\t "
111
- i = s .find (separator )
112
- if i == - 1 :
113
- return s
114
- return s [:i ]
111
+ values = [value .strip () for value in s .split (separator ) if value .strip ()]
112
+ if not values :
113
+ return float (s ), None
114
+ value = float (values [0 ])
115
+ timestamp = (float (values [- 1 ])/ 1000 ) if len (values ) > 1 else None
116
+ return value , timestamp
115
117
116
118
117
119
def _parse_sample (text ):
@@ -123,8 +125,8 @@ def _parse_sample(text):
123
125
# We ignore the starting curly brace
124
126
label = text [label_start + 1 :label_end ]
125
127
# The value is after the label end (ignoring curly brace and space)
126
- value = float ( _parse_value ( text [label_end + 2 :]) )
127
- return Sample (name , _parse_labels (label ), value )
128
+ value , timestamp = _parse_value_and_timestamp ( text [label_end + 2 :])
129
+ return Sample (name , _parse_labels (label ), value , timestamp )
128
130
129
131
# We don't have labels
130
132
except ValueError :
@@ -135,8 +137,8 @@ def _parse_sample(text):
135
137
name_end = text .index (separator )
136
138
name = text [:name_end ]
137
139
# The value is after the name
138
- value = float ( _parse_value ( text [name_end :]) )
139
- return Sample (name , {}, value )
140
+ value , timestamp = _parse_value_and_timestamp ( text [name_end :])
141
+ return Sample (name , {}, value , timestamp )
140
142
141
143
142
144
def text_fd_to_metric_families (fd ):
0 commit comments