func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
	interval := d.Interval.MustRandWindow(devops.HighCPUDuration)
	hosts, err := d.GetRandomHosts(nHosts)
	panicIfErr(err)
	sql := fmt.Sprintf(`
		SELECT *
		FROM cpu
		WHERE usage_user > 90.0
		  AND ts >= %d
		  AND ts < %d
		  AND %s IN ('%s')`,
		interval.StartUnixMillis(),
		interval.EndUnixMillis(),
		hostnameField,
		strings.Join(hosts, "', '"))
	humanLabel, err := devops.GetHighCPULabel("CrateDB", nHosts)
	panicIfErr(err)
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, sql)
}
HighCPUForHosts populates a query that gets CPU metrics when the CPU has
high usage between a time period for a number of hosts (if 0, it will
search all hosts)

Queries:
high-cpu-1
high-cpu-all
package cratedb
import (
	"fmt"
	"strings"
	"time"
	"github.com/timescale/tsbs/cmd/tsbs_generate_queries/uses/devops"
	"github.com/timescale/tsbs/pkg/query"
)
func panicIfErr(err error) {
	if err != nil {
		panic(err.Error())
	}
}
type Devops struct {
	*BaseGenerator
	*devops.Core
}
const hostnameField = "tags['hostname']"
func (d *Devops) getSelectAggClauses(aggFunc string, idents []string) []string {
	selectAggClauses := make([]string, len(idents))
	for i, ident := range idents {
		selectAggClauses[i] =
			fmt.Sprintf("%[1]s(%[2]s) AS %[1]s_%[2]s", aggFunc, ident)
	}
	return selectAggClauses
}
func (d *Devops) MaxAllCPU(qi query.Query, nHosts int) {
	interval := d.Interval.MustRandWindow(devops.MaxAllDuration)
	selectClauses := d.getSelectAggClauses("max", devops.GetAllCPUMetrics())
	hosts, err := d.GetRandomHosts(nHosts)
	panicIfErr(err)
	sql := fmt.Sprintf(`
		SELECT
			date_trunc('hour', ts) AS hour,
			%s
		FROM cpu
		WHERE %s IN ('%s')
		  AND ts >= %d
		  AND ts < %d
		GROUP BY hour
		ORDER BY hour`,
		strings.Join(selectClauses, ", "),
		hostnameField,
		strings.Join(hosts, "', '"),
		interval.StartUnixMillis(),
		interval.EndUnixMillis())
	humanLabel := devops.GetMaxAllLabel("CrateDB", nHosts)
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, sql)
}
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
	metrics, err := devops.GetCPUMetricsSlice(numMetrics)
	panicIfErr(err)
	interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
	selectClauses := d.getSelectAggClauses("mean", metrics)
	sql := fmt.Sprintf(`
		SELECT
			date_trunc('hour', ts) AS hour,
			%s
		FROM cpu
		WHERE ts >= %d
		  AND ts < %d
		GROUP BY hour, %s
		ORDER BY hour`,
		strings.Join(selectClauses, ", "),
		interval.StartUnixMillis(),
		interval.EndUnixMillis(),
		hostnameField)
	humanLabel := devops.GetDoubleGroupByLabel("CrateDB", numMetrics)
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, sql)
}
func (d *Devops) GroupByOrderByLimit(qi query.Query) {
	interval := d.Interval.MustRandWindow(time.Hour)
	sql := fmt.Sprintf(`
		SELECT
			date_trunc('minute', ts) as minute,
			max(usage_user)
		FROM cpu
		WHERE ts < %d
		GROUP BY minute
		ORDER BY minute DESC
		LIMIT 5`,
		interval.EndUnixMillis())
	humanLabel := "CrateDB max cpu over last 5 min-intervals (random end)"
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.EndString())
	d.fillInQuery(qi, humanLabel, humanDesc, sql)
}
func (d *Devops) LastPointPerHost(qi query.Query) {
	sql := fmt.Sprintf(`
		SELECT *
		FROM
		  (
			SELECT %[1]s AS host, max(ts) AS max_ts
			FROM cpu
			GROUP BY %[1]s
		  ) t, cpu c
		WHERE t.max_ts = c.ts
		  AND t.host = c.%[1]s`, hostnameField)
	humanLabel := "CrateDB last row per host"
	humanDesc := humanLabel
	d.fillInQuery(qi, humanLabel, humanDesc, sql)
}