Bosun Graph or GraphAll using inline or dynamic query


Example

Graph queries can be defined inline if you don't want to use an Alert variable.

template graph.template {
    subject = ...

    body = `{{template "header" .}}

    <strong>Graph With Inline Query</strong>
    <div>{{.Graph "q(\"avg:300s-avg:os.mem.percent_free{host=specifichost}\", \"1d\", \"\")" "Free Memory in GB"}}</div>

    <strong>GraphAll with Inline Query</strong>
    <div>{{.GraphAll "q(\"avg:300s-avg:os.mem.percent_free{host=host1|host2|host3}\", \"1d\", \"\")" "All Systems Free Memory in GB"}}</div>

    `
}

Sometimes you may want to create the query for a graph dynamically in the template itself by combining one or more variables. For instance a host down alert might want to include the Bosun known hosts ping metric using the dst_host tag.

template host.down {
    subject = ...

    body = `{{template "header" .}}

    <strong>Graph from one variable</strong>
    <div>{{printf "q(\"sum:bosun.ping.timeout{dst_host=%s}\", \"8h\", \"\")" (.Group.host) | .Graph}}</div>

    <strong>Graph from multiple variables</strong>
    <div>{{printf "q(\"sum:%s{host=%s,anothertag=%s}\", \"8h\", \"\")" "some.metric.name" .Group.host "anothervalue" | .Graph}}</div>
    `
}

The printf statement will generate q("sum:bosun.ping.timeout{dst_host=alerthostname}", "8h", "") when that host triggers an alert and then use that to create the graph in the notification.