Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
cc97b48c
Unverified
Commit
cc97b48c
authored
7 years ago
by
Daniel Nelson
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add support for skipping database creation (#3941)
parent
36b82201
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/outputs/influxdb/README.md
+5
-0
5 additions, 0 deletions
plugins/outputs/influxdb/README.md
plugins/outputs/influxdb/influxdb.go
+31
-27
31 additions, 27 deletions
plugins/outputs/influxdb/influxdb.go
with
36 additions
and
27 deletions
plugins/outputs/influxdb/README.md
+
5
−
0
View file @
cc97b48c
...
...
@@ -17,6 +17,11 @@ This InfluxDB output plugin writes metrics to the [InfluxDB](https://github.com/
## The target database for metrics; will be created as needed.
# database = "telegraf"
## If true, no CREATE DATABASE queries will be sent. Set to true when using
## Telegraf with a user without permissions to create databases or when the
## database already exists.
# skip_database_creation = false
## Name of existing retention policy to write to. Empty string writes to
## the default retention policy.
# retention_policy = ""
...
...
This diff is collapsed.
Click to expand it.
plugins/outputs/influxdb/influxdb.go
+
31
−
27
View file @
cc97b48c
...
...
@@ -31,19 +31,20 @@ type Client interface {
// InfluxDB struct is the primary data structure for the plugin
type
InfluxDB
struct
{
URL
string
// url deprecated in 0.1.9; use urls
URLs
[]
string
`toml:"urls"`
Username
string
Password
string
Database
string
UserAgent
string
RetentionPolicy
string
WriteConsistency
string
Timeout
internal
.
Duration
UDPPayload
int
`toml:"udp_payload"`
HTTPProxy
string
`toml:"http_proxy"`
HTTPHeaders
map
[
string
]
string
`toml:"http_headers"`
ContentEncoding
string
`toml:"content_encoding"`
URL
string
// url deprecated in 0.1.9; use urls
URLs
[]
string
`toml:"urls"`
Username
string
Password
string
Database
string
UserAgent
string
RetentionPolicy
string
WriteConsistency
string
Timeout
internal
.
Duration
UDPPayload
int
`toml:"udp_payload"`
HTTPProxy
string
`toml:"http_proxy"`
HTTPHeaders
map
[
string
]
string
`toml:"http_headers"`
ContentEncoding
string
`toml:"content_encoding"`
SkipDatabaseCreation
bool
`toml:"skip_database_creation"`
// Path to CA file
SSLCA
string
`toml:"ssl_ca"`
...
...
@@ -75,6 +76,11 @@ var sampleConfig = `
## The target database for metrics; will be created as needed.
# database = "telegraf"
## If true, no CREATE DATABASE queries will be sent. Set to true when using
## Telegraf with a user without permissions to create databases or when the
## database already exists.
# skip_database_creation = false
## Name of existing retention policy to write to. Empty string writes to
## the default retention policy.
# retention_policy = ""
...
...
@@ -194,11 +200,13 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
switch
apiError
:=
err
.
(
type
)
{
case
APIError
:
if
apiError
.
Type
==
DatabaseNotFound
{
err
:=
client
.
CreateDatabase
(
ctx
)
if
err
!=
nil
{
log
.
Printf
(
"E! [outputs.influxdb] when writing to [%s]: database %q not found and failed to recreate"
,
client
.
URL
(),
client
.
Database
())
if
!
i
.
SkipDatabaseCreation
{
if
apiError
.
Type
==
DatabaseNotFound
{
err
:=
client
.
CreateDatabase
(
ctx
)
if
err
!=
nil
{
log
.
Printf
(
"E! [outputs.influxdb] when writing to [%s]: database %q not found and failed to recreate"
,
client
.
URL
(),
client
.
Database
())
}
}
}
}
...
...
@@ -252,16 +260,12 @@ func (i *InfluxDB) httpClient(ctx context.Context, url *url.URL, proxy *url.URL)
return
nil
,
fmt
.
Errorf
(
"error creating HTTP client [%s]: %v"
,
url
,
err
)
}
err
=
c
.
CreateDatabase
(
ctx
)
if
err
!=
nil
{
if
err
,
ok
:=
err
.
(
APIError
);
ok
{
if
err
.
StatusCode
==
503
{
return
c
,
nil
}
if
!
i
.
SkipDatabaseCreation
{
err
=
c
.
CreateDatabase
(
ctx
)
if
err
!=
nil
{
log
.
Printf
(
"W! [outputs.influxdb] when writing to [%s]: database %q creation failed: %v"
,
c
.
URL
(),
c
.
Database
(),
err
)
}
log
.
Printf
(
"W! [outputs.influxdb] when writing to [%s]: database %q creation failed: %v"
,
c
.
URL
(),
c
.
Database
(),
err
)
}
return
c
,
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment