On 12.01.21 18:28, Derrick Lim wrote:
>
> I've a flat file with some metrics. This was created as a CounterVec and
> with the following code.
>
> ```
> processedTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
> Name: "app_processed_total",
> Help: "Number of times ran",
> }, []string{"status"})
> ```
>
> This was then serialized by expfmt.MetricFamilyToText() and produces the
> following flat file.
>
> ```
> # HELP app_processed_total Number of times ran
> # TYPE app_processed_total counter
> app_processed_total{status="ok"} 300
> ```
> I would like to serialize this back to a CounterVec.
>
> I've thus far followed this example,
> https://github.com/prometheus/client_golang/blob/master/prometheus/examples_test.go#L620,
>
> along with expfmt.ExtractSamples and ended with a Vector. Is this approach
> correct? How can I go from here to make this Vector into a CounterVec?
I cannot think about a straightforward way to do that. The CounterVec
is much more than just for data representation. It has all the logic
you need for direct instrumentation. While CounterVec obviously tracks
counts internally, it has nothing to do with samples. If you really
want to stretch it, you could say, the Collect method _creates_ a
sample from it. But it still doesn't have a timestamp. Which is only
created during a scrape.
The model.Vector you get from expfmt.ExtractSamples is just a slice of
model.Sample, and thus something completely different, even if it also
uses the word "vector". The types in the model package are more meant
on the server side, i.e. handling the data in time series and queries
and such.
I don't know what you are trying to accomplish, but if you want to
somehow persist and reconstruct a CounterVec, I guess you need to call
Inc(...) on each counter with the value you would like to reconstruct.
(But I have to admit, I have no clue why you would want to do that.)
--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] [email protected]
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/20210121224242.GK3352%40jahnn.