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
07680222
Commit
07680222
authored
6 years ago
by
Mariusz Brzeski
Committed by
Daniel Nelson
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support busybox ping in the ping input (#3877)
parent
92956104
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/inputs/ping/ping.go
+13
-10
13 additions, 10 deletions
plugins/inputs/ping/ping.go
plugins/inputs/ping/ping_test.go
+25
-3
25 additions, 3 deletions
plugins/inputs/ping/ping_test.go
with
38 additions
and
13 deletions
plugins/inputs/ping/ping.go
+
13
−
10
View file @
07680222
...
@@ -171,17 +171,17 @@ func (p *Ping) args(url string) []string {
...
@@ -171,17 +171,17 @@ func (p *Ping) args(url string) []string {
// Build the ping command args based on toml config
// Build the ping command args based on toml config
args
:=
[]
string
{
"-c"
,
strconv
.
Itoa
(
p
.
Count
),
"-n"
,
"-s"
,
"16"
}
args
:=
[]
string
{
"-c"
,
strconv
.
Itoa
(
p
.
Count
),
"-n"
,
"-s"
,
"16"
}
if
p
.
PingInterval
>
0
{
if
p
.
PingInterval
>
0
{
args
=
append
(
args
,
"-i"
,
strconv
.
FormatFloat
(
p
.
PingInterval
,
'f'
,
1
,
64
))
args
=
append
(
args
,
"-i"
,
strconv
.
FormatFloat
(
p
.
PingInterval
,
'f'
,
-
1
,
64
))
}
}
if
p
.
Timeout
>
0
{
if
p
.
Timeout
>
0
{
switch
runtime
.
GOOS
{
switch
runtime
.
GOOS
{
case
"darwin"
:
case
"darwin"
:
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
*
1000
,
'f'
,
1
,
64
))
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
*
1000
,
'f'
,
-
1
,
64
))
case
"linux"
:
case
"linux"
:
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
,
'f'
,
1
,
64
))
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
,
'f'
,
-
1
,
64
))
default
:
default
:
// Not sure the best option here, just assume GNU ping?
// Not sure the best option here, just assume GNU ping?
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
,
'f'
,
1
,
64
))
args
=
append
(
args
,
"-W"
,
strconv
.
FormatFloat
(
p
.
Timeout
,
'f'
,
-
1
,
64
))
}
}
}
}
if
p
.
Deadline
>
0
{
if
p
.
Deadline
>
0
{
...
@@ -243,21 +243,24 @@ func processPingOutput(out string) (int, int, float64, float64, float64, float64
...
@@ -243,21 +243,24 @@ func processPingOutput(out string) (int, int, float64, float64, float64, float64
}
}
}
else
if
strings
.
Contains
(
line
,
"min/avg/max"
)
{
}
else
if
strings
.
Contains
(
line
,
"min/avg/max"
)
{
stats
:=
strings
.
Split
(
line
,
" "
)[
3
]
stats
:=
strings
.
Split
(
line
,
" "
)[
3
]
min
,
err
=
strconv
.
ParseFloat
(
strings
.
Split
(
stats
,
"/"
)[
0
],
64
)
data
:=
strings
.
Split
(
stats
,
"/"
)
min
,
err
=
strconv
.
ParseFloat
(
data
[
0
],
64
)
if
err
!=
nil
{
if
err
!=
nil
{
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
}
}
avg
,
err
=
strconv
.
ParseFloat
(
strings
.
Split
(
stats
,
"/"
)
[
1
],
64
)
avg
,
err
=
strconv
.
ParseFloat
(
data
[
1
],
64
)
if
err
!=
nil
{
if
err
!=
nil
{
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
}
}
max
,
err
=
strconv
.
ParseFloat
(
strings
.
Split
(
stats
,
"/"
)
[
2
],
64
)
max
,
err
=
strconv
.
ParseFloat
(
data
[
2
],
64
)
if
err
!=
nil
{
if
err
!=
nil
{
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
}
}
stddev
,
err
=
strconv
.
ParseFloat
(
strings
.
Split
(
stats
,
"/"
)[
3
],
64
)
if
len
(
data
)
==
4
{
if
err
!=
nil
{
stddev
,
err
=
strconv
.
ParseFloat
(
data
[
3
],
64
)
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
if
err
!=
nil
{
return
trans
,
recv
,
min
,
avg
,
max
,
stddev
,
err
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/ping/ping_test.go
+
25
−
3
View file @
07680222
...
@@ -41,6 +41,19 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data.
...
@@ -41,6 +41,19 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data.
rtt min/avg/max/mdev = 35.225/43.628/51.806/5.325 ms
rtt min/avg/max/mdev = 35.225/43.628/51.806/5.325 ms
`
`
// BusyBox v1.24.1 (2017-02-28 03:28:13 CET) multi-call binary
var
busyBoxPingOutput
=
`
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=56 time=22.559 ms
64 bytes from 8.8.8.8: seq=1 ttl=56 time=15.810 ms
64 bytes from 8.8.8.8: seq=2 ttl=56 time=16.262 ms
64 bytes from 8.8.8.8: seq=3 ttl=56 time=15.815 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 15.810/17.611/22.559 ms
`
// Fatal ping output (invalid argument)
// Fatal ping output (invalid argument)
var
fatalPingOutput
=
`
var
fatalPingOutput
=
`
ping: -i interval too short: Operation not permitted
ping: -i interval too short: Operation not permitted
...
@@ -65,6 +78,15 @@ func TestProcessPingOutput(t *testing.T) {
...
@@ -65,6 +78,15 @@ func TestProcessPingOutput(t *testing.T) {
assert
.
InDelta
(
t
,
43.628
,
avg
,
0.001
)
assert
.
InDelta
(
t
,
43.628
,
avg
,
0.001
)
assert
.
InDelta
(
t
,
51.806
,
max
,
0.001
)
assert
.
InDelta
(
t
,
51.806
,
max
,
0.001
)
assert
.
InDelta
(
t
,
5.325
,
stddev
,
0.001
)
assert
.
InDelta
(
t
,
5.325
,
stddev
,
0.001
)
trans
,
rec
,
min
,
avg
,
max
,
stddev
,
err
=
processPingOutput
(
busyBoxPingOutput
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
4
,
trans
,
"4 packets were transmitted"
)
assert
.
Equal
(
t
,
4
,
rec
,
"4 packets were transmitted"
)
assert
.
InDelta
(
t
,
15.810
,
min
,
0.001
)
assert
.
InDelta
(
t
,
17.611
,
avg
,
0.001
)
assert
.
InDelta
(
t
,
22.559
,
max
,
0.001
)
assert
.
InDelta
(
t
,
-
1.0
,
stddev
,
0.001
)
}
}
// Test that processPingOutput returns an error when 'ping' fails to run, such
// Test that processPingOutput returns an error when 'ping' fails to run, such
...
@@ -106,7 +128,7 @@ func TestArgs(t *testing.T) {
...
@@ -106,7 +128,7 @@ func TestArgs(t *testing.T) {
"12000.0"
,
"www.google.com"
}
"12000.0"
,
"www.google.com"
}
default
:
default
:
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
"12
.0
"
,
"www.google.com"
}
"12"
,
"www.google.com"
}
}
}
p
.
Deadline
=
24
p
.
Deadline
=
24
...
@@ -117,7 +139,7 @@ func TestArgs(t *testing.T) {
...
@@ -117,7 +139,7 @@ func TestArgs(t *testing.T) {
"12000.0"
,
"-t"
,
"24"
,
"www.google.com"
}
"12000.0"
,
"-t"
,
"24"
,
"www.google.com"
}
default
:
default
:
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
"12
.0
"
,
"-w"
,
"24"
,
"www.google.com"
}
"12"
,
"-w"
,
"24"
,
"www.google.com"
}
}
}
sort
.
Strings
(
actual
)
sort
.
Strings
(
actual
)
...
@@ -133,7 +155,7 @@ func TestArgs(t *testing.T) {
...
@@ -133,7 +155,7 @@ func TestArgs(t *testing.T) {
"12000.0"
,
"-t"
,
"24"
,
"-i"
,
"1.2"
,
"www.google.com"
}
"12000.0"
,
"-t"
,
"24"
,
"-i"
,
"1.2"
,
"www.google.com"
}
default
:
default
:
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
expected
=
[]
string
{
"-c"
,
"2"
,
"-n"
,
"-s"
,
"16"
,
"-I"
,
"eth0"
,
"-W"
,
"12
.0
"
,
"-w"
,
"24"
,
"-i"
,
"1.2"
,
"www.google.com"
}
"12"
,
"-w"
,
"24"
,
"-i"
,
"1.2"
,
"www.google.com"
}
}
}
sort
.
Strings
(
actual
)
sort
.
Strings
(
actual
)
sort
.
Strings
(
expected
)
sort
.
Strings
(
expected
)
...
...
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