diff options
author | Antoine Eiche <antoine.eiche@cloudwatt.com> | 2016-06-07 19:09:50 +0200 |
---|---|---|
committer | Antoine Eiche <antoine.eiche@cloudwatt.com> | 2016-06-07 19:09:50 +0200 |
commit | 50bf0d34d31c8f745e58b0f172c86fb617b92bf8 (patch) | |
tree | 5ed060b98d9ddfd1e6e15347aa1e1df570160880 /server | |
parent | c96b6d119849677aa8db8298a412f7ff501b879a (diff) |
collector: ping InfluxDB and create database at startup
Ping InfluxDB to verify the connection at collector initialization and
create the database.
Diffstat (limited to 'server')
-rw-r--r-- | server/collector.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/server/collector.go b/server/collector.go index 6860011e..1399f338 100644 --- a/server/collector.go +++ b/server/collector.go @@ -211,6 +211,19 @@ func NewCollector(grpcCh chan *GrpcRequest, url, dbName string, interval uint64) if err != nil { return nil, err } + + _, _, err = c.Ping(0) + if err != nil { + log.Error("can not connect to InfluxDB") + return nil, err + } + + q := client.NewQuery("CREATE DATABASE " + dbName, "", "") + if response, err := c.Query(q); err != nil || response.Error() != nil { + log.Error("can not create database " + dbName) + return nil, err + } + collector := &Collector{ grpcCh: grpcCh, url: url, |