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
f2b0ea67
Commit
f2b0ea67
authored
8 years ago
by
Cameron Sparr
Browse files
Options
Downloads
Patches
Plain Diff
value parser: doc & string handling
parent
46f4be88
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/DATA_FORMATS_INPUT.md
+6
-1
6 additions, 1 deletion
docs/DATA_FORMATS_INPUT.md
plugins/parsers/value/parser.go
+16
-9
16 additions, 9 deletions
plugins/parsers/value/parser.go
with
22 additions
and
10 deletions
docs/DATA_FORMATS_INPUT.md
+
6
−
1
View file @
f2b0ea67
...
@@ -156,7 +156,12 @@ as the parsed metric.
...
@@ -156,7 +156,12 @@ as the parsed metric.
#### Value Configuration:
#### Value Configuration:
You
**must**
tell Telegraf what type of metric to collect by using the
You
**must**
tell Telegraf what type of metric to collect by using the
`data_type`
configuration option.
`data_type`
configuration option. Available options are:
1.
integer
2.
float or long
3.
string
4.
boolean
**Note:**
It is also recommended that you set
`name_override`
to a measurement
**Note:**
It is also recommended that you set
`name_override`
to a measurement
name that makes sense for your metric, otherwise it will just be set to the
name that makes sense for your metric, otherwise it will just be set to the
...
...
This diff is collapsed.
Click to expand it.
plugins/parsers/value/parser.go
+
16
−
9
View file @
f2b0ea67
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"strconv"
"strconv"
"strings"
"time"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf"
...
@@ -16,24 +17,30 @@ type ValueParser struct {
...
@@ -16,24 +17,30 @@ type ValueParser struct {
}
}
func
(
v
*
ValueParser
)
Parse
(
buf
[]
byte
)
([]
telegraf
.
Metric
,
error
)
{
func
(
v
*
ValueParser
)
Parse
(
buf
[]
byte
)
([]
telegraf
.
Metric
,
error
)
{
// separate out any fields in the buffer, ignore anything but the last.
// unless it's a string, separate out any fields in the buffer,
values
:=
bytes
.
Fields
(
buf
)
// ignore anything but the last.
if
len
(
values
)
<
1
{
var
vStr
string
return
[]
telegraf
.
Metric
{},
nil
if
v
.
DataType
==
"string"
{
vStr
=
strings
.
TrimSpace
(
string
(
buf
))
}
else
{
values
:=
bytes
.
Fields
(
buf
)
if
len
(
values
)
<
1
{
return
[]
telegraf
.
Metric
{},
nil
}
vStr
=
string
(
values
[
len
(
values
)
-
1
])
}
}
valueStr
:=
string
(
values
[
len
(
values
)
-
1
])
var
value
interface
{}
var
value
interface
{}
var
err
error
var
err
error
switch
v
.
DataType
{
switch
v
.
DataType
{
case
""
,
"int"
,
"integer"
:
case
""
,
"int"
,
"integer"
:
value
,
err
=
strconv
.
Atoi
(
v
alue
Str
)
value
,
err
=
strconv
.
Atoi
(
vStr
)
case
"float"
,
"long"
:
case
"float"
,
"long"
:
value
,
err
=
strconv
.
ParseFloat
(
v
alue
Str
,
64
)
value
,
err
=
strconv
.
ParseFloat
(
vStr
,
64
)
case
"str"
,
"string"
:
case
"str"
,
"string"
:
value
=
v
alue
Str
value
=
vStr
case
"bool"
,
"boolean"
:
case
"bool"
,
"boolean"
:
value
,
err
=
strconv
.
ParseBool
(
v
alue
Str
)
value
,
err
=
strconv
.
ParseBool
(
vStr
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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