Skip to content

Commit

Permalink
Fix for issue #77, create telegraf database if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Aug 10, 2015
1 parent a3e20ab commit c0cef8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#71](https://github.com/influxdb/telegraf/pull/71): HAProxy plugin. Thanks @kureikain!
- [#72](https://github.com/influxdb/telegraf/pull/72): Adding TokuDB metrics to MySQL. Thanks vadimtk!
- [#73](https://github.com/influxdb/telegraf/pull/73): RabbitMQ plugin. Thanks @ianunruh!
- [#77](https://github.com/influxdb/telegraf/issues/77): Automatically create database.
- [#79](https://github.com/influxdb/telegraf/pull/56): Nginx plugin. Thanks @codeb2cc!
- [#86](https://github.com/influxdb/telegraf/pull/86): Lustre2 plugin. Thanks srfraser!
- [#91](https://github.com/influxdb/telegraf/pull/91): Unit testing
Expand Down
9 changes: 9 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"os"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -84,6 +85,14 @@ func (a *Agent) Connect() error {
return err
}

_, err = c.Query(client.Query{
Command: fmt.Sprintf("CREATE DATABASE telegraf"),
})

if err != nil && !strings.Contains(err.Error(), "database already exists") {
log.Fatal(err)
}

a.conn = c

return nil
Expand Down

0 comments on commit c0cef8c

Please sign in to comment.