Need help about how to use prometheus Predict_linear function

219 views
Skip to first unread message

qing zhangqing

unread,
Jun 14, 2019, 8:52:33 PM6/14/19
to Prometheus Users

I am pretty new to prometheus,

I am trying to predict the next 5 hours cpu usage on node 1 and node 2.

My code is

'''

    predict_linear(cpu_usage[5m],5*3600)

''' Since the cpu_usage includes two nodes, when I use the equation above, I got two prediction results, which I do not want it.

The results is below:


{node=node1} xxxxxxxx(prediction result 1)

{node=node2} xxxxxxxx(prediction result 2)


So I improve my code by adding '''

    sum(predict_linear(cpu_usage[5m],5*3600)).

''' I am not sure it is the right way or not. I read the document and it mentioned that predic_linear is only for gauge.


Also, I am confused about the timestamp after I predict.  for example, the prediction result on current timestamp 00:00:000, does it mean the value is for next 5 hours result on current timestamp?

Thanks guys,


Really appreciate it.

Christian Hoffmann

unread,
Jun 15, 2019, 2:33:42 AM6/15/19
to qing zhangqing, Prometheus Users
Hi,

On 2019-06-15 02:52, qing zhangqing wrote:
> I am trying to predict the next 5 hours cpu usage on node 1 and node 2.
>
> My code is
>
> '''
>
> |predict_linear(cpu_usage[5m],5*3600) |
>
> ''' Since the cpu_usage includes two nodes, when I use the equation
> above, I got two prediction results, which I do not want it.
>
>
> So I improve my code by adding '''
>
> |sum(predict_linear(cpu_usage[5m],5*3600)). |
>
> ''' I am not sure it is the right way or not.
This will return the sum of both predictions -- and summing timestamps
does not really make sense, IMO. :)

It sounds like you would like to predict on the sum (or avg?) of the two
node's cpu usage. For this to work, you will either need to set up a
recording rule or to use subqueries. Here's an example for the latter
(untested):

predict_linear(sum(cpu_usage)[5m:], 5*3600)

Kind regards,
Christian

qing zhangqing

unread,
Jun 15, 2019, 3:04:21 PM6/15/19
to Christian Hoffmann, Prometheus Users
Thank you Christian. 

My goal is try to predict the cpu usage for both node.  I want to see my result like :


CPU usage(include both nodes)     Xxxxxxxxxxxx   

But I read the document that Predict _linear is only work for Gauge value.  I am not sure if I use it here will be right.  Because the I was worry The CPU usage is a counter metric. I am not sure if I can use sub query like you mentioned to predict it. 

Sorry I am a little bit new here.  But thank you so much for the help.
--
Qing Zhang

UC Berkeley School of Information

SRE Engineering Management

415-509-1893

zhangqi...@gmail.com

https://www.linkedin.com/in/qizhang2


Christian Hoffmann

unread,
Jun 15, 2019, 3:16:43 PM6/15/19
to qing zhangqing, Prometheus Users
Hi,

On 2019-06-15 21:04, qing zhangqing wrote:
> Thank you Christian. 
>
> My goal is try to predict the cpu usage for both node.  I want to see my
> result like :
>
>
> CPU usage(include both nodes)     Xxxxxxxxxxxx   
>
> But I read the document that Predict _linear is only work for Gauge
> value.  I am not sure if I use it here will be right.  Because the I was
> worry The CPU usage is a counter metric. I am not sure if I can use sub
> query like you mentioned to predict it. 

I guess you are referring to [1]. I assume the "predict_linear should
only be used with gauges." is there because predict_linear might not
handle counter restricts -- although I'm speculating.

I don't think this would be relevant here, as you will be using
predict_linear on a (sum of a) rate.

Also, this should only be a semantical issue -- Prometheus does not
store the metric type at all. You will just have to make sure that your
calculation makes sense somehow.

I would suggest to just try with the query.

[1]
https://prometheus.io/docs/prometheus/latest/querying/functions/#predict_linear

Kind regards,
Christian

qing zhangqing

unread,
Jun 15, 2019, 6:56:43 PM6/15/19
to Christian Hoffmann, Prometheus Users
Thank you Christian. 
Reply all
Reply to author
Forward
0 new messages