In the 1.0 betaX versions of Kapacitor there is a "humanBytes" function 
that will take a numeric input and return a human readable string 
indicating the number of bytes.

It can be used like this:

// Parameters
var info = 10
var warn = 150
var crit = 170
var period = 2m
var every = 2m

stream
        |from() .database('k8s')
                .retentionPolicy('default')
                .measurement('memory/usage')
                .groupBy('hostname')

        |window()
             // keep the most recent 2m of data
            .period(period)
             // Every minute emit the last 2 minutes of data to check if 
the min is greater than 95
             // this could be any value, depending on how often you want to 
recheck the window.
            .every(every)
        |mean('value') 
            .as('used')
        |eval(lambda: humanBytes("used")
            .as('used_str')
            .keep()
        |alert()
                .id('{{index .Tags "hostname" }} memory utilization in MB')
                .message('{{ .ID }} is {{ .Level }} value:{{ index .Fields 
"used_str" }}')
                .info(lambda: "used" > info)
                .warn(lambda: "used" > warn)
                .crit(lambda: "used" > crit)
                .stateChangesOnly()
                .log('/tmp/alerts.log')

On Thursday, August 18, 2016 at 6:15:38 AM UTC-6, Vinoth Narasimhan wrote:
>
> We are trying kapacitor in kubernetes cluster to send the alert 
> notifications .
>
> As a example the "memory/usage" values send by heapster as stored as bytes 
> in influxDB like this (3.60463797709804e+08). The equivalent readable value 
> is  360MB.
>
> My question is how to convert those values from mean('value') from bytes 
> to Megabytes and compare.
>
> Below is the tick file i used. 
>
> // Parameters
> var info = 10
> var warn = 150
> var crit = 170
> var period = 2m
> var every = 2m
>
> stream
>         |from() .database('k8s')
>                 .retentionPolicy('default')
>                 .measurement('memory/usage')
>                 .groupBy('hostname')
>
>         |window()
>              // keep the most recent 2m of data
>             .period(period)
>              // Every minute emit the last 2 minutes of data to check if 
> the min is greater than 95
>              // this could be any value, depending on how often you want 
> to recheck the window.
>             .every(every)
>         |mean('value') 
>             .as('used')
>
>         |alert()
>                 .id('{{index .Tags "hostname" }} memory utilization in MB')
>                 .message('{{ .ID }} is {{ .Level }} value:{{ index .Fields 
> "used" }}')
>                 .info(lambda: "used" > info)
>                 .warn(lambda: "used" > warn)
>                 .crit(lambda: "used" > crit)
>                 .stateChangesOnly()
>                 .log('/tmp/alerts.log')
>

-- 
Remember to include the InfluxDB version number with all issue reports
--- 
You received this message because you are subscribed to the Google Groups 
"InfluxDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/influxdb.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/influxdb/5dabc6db-23bf-4c68-bcf5-69fa183045c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to