Skip to content
Snippets Groups Projects
Commit f334268f authored by Lars Janssen's avatar Lars Janssen
Browse files

added four queries to be executed at start.

Those should create the two databases, a retention policy and a continuous query.
parent 8aa8f644
No related branches found
No related tags found
No related merge requests found
......@@ -76,9 +76,11 @@ func main() {
return
}
// InfluxDB 1 fix, create database
createDB := func(databaseName string) {
// Does multiple HTTP posts to DB
// It creates two databases, one retention policy and one continuous query on settings.InfluxdbDatabase
postTODB := func(queryPostString string) {
data := url.Values{}
data.Set("q", "CREATE DATABASE "+databaseName)
data.Set("q", queryPostString)
res, err := http.Post(
settings.InfluxDbUrl+"/query", "application/x-www-form-urlencoded",
......@@ -92,12 +94,25 @@ func main() {
rawResponse, _ := ioutil.ReadAll(res.Body)
strResponse := string(rawResponse)
log.Fatal("failed to create database, status code was " + strconv.Itoa(res.StatusCode) + ": " + strResponse)
log.Fatal("failed to do the post, post was: " + queryPostString +
" and status code was " + strconv.Itoa(res.StatusCode) + ": " + strResponse)
return
}
}
createDB(settings.InfluxDbDatabase)
createDB(settings.InfluxDbDatabase + "_avg")
normalDB := settings.InfluxDbDatabase
avgDB := settings.InfluxDbDatabase + "_avg"
postStrings := []string{
"CREATE DATABASE " + normalDB,
"CREATE DATABASE " + avgDB,
"CREATE RETENTION POLICY one_day ON " + normalDB +
" DURATION 24h REPLICATION 1 DEFAULT",
"CREATE CONTINUOUS QUERY ON " + normalDB +
"BEGIN SELECT mean(*) INTO " + avgDB +
".one_day.:MEASUREMENT FROM /.*/ GROUP BY time(12h) END",
}
for i := 0; i < len(postStrings); i++ {
postTODB(postStrings[i])
}
log.SetLevel(logLevel)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment