Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ping plugin returns 0 although ping not successful #4893

Closed
darox opened this issue Oct 20, 2018 · 8 comments
Closed

Ping plugin returns 0 although ping not successful #4893

darox opened this issue Oct 20, 2018 · 8 comments

Comments

@darox
Copy link

darox commented Oct 20, 2018

I've found a weird issue in Telegraf. Telegraf puts a 0 for the result_code even if the ping was not successful. But according to the documentation here https://github.com/influxdata/telegraf/tree/master/plugins/inputs/ping 0 stands for successful. The rest of the returned values from the ping plugin are set to null in my influxdb.

[ "2018-10-20T20:41:16Z", null, "host", null, null, null, null, null, 0, null, "tag1", "tag2", "twitter.com" ],

Besides that I also have the http plugin running which returns:
[ "2018-10-20T20:42:11Z", "host", null, "GET", null, "timeout", 4, "timeout", null, "itag1", "tag2" ],

Where 4 stands for timeout.

There must be something wrong in the ping plugin in my opinion.

@glinton
Copy link
Contributor

glinton commented Oct 21, 2018

This should be resolved in telegraf 1.8.2 by #4875 if it's not, please comment or reopen

@glinton glinton closed this as completed Oct 21, 2018
@darox
Copy link
Author

darox commented Oct 21, 2018

Ok thanks, I'll verify.

@david-guenault
Copy link

david-guenault commented Oct 22, 2018

Hello it seems that now result_code is 1 even if ping succeed ... this is not the correct behaviour.
Should be 0 for success, 1 for unresolved host and 2 for ping failure

Influx version is : influxdb-1.6.4-1.x86_64
Telegraf version is : telegraf-1.8.2-1.x86_64

Os:

LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.5.1804 (Core)
Release:        7.5.1804
Codename:       Core

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/ping

select * from ping where "name" =~ /^targethost$/ AND time >= now() - 5m  limit 100
time                average_response_ms host         maximum_response_ms minimum_response_ms name       packets_received packets_transmitted percent_packet_loss result_code standard_deviation_ms tag1      tag2           tag3       url
----                ------------------- ----         ------------------- ------------------- ----       ---------------- ------------------- ------------------- ----------- --------------------- ----      ----           ----       ---

1540226482000000000 0.57                host 0.617               0.523               targethost 2                2                   0                   1           0.047                 tag1 tag2 tag3 IP
1540226492000000000 0.589               host 0.632               0.546               targethost 2                2                   0                   1           0.043                 tag1 tag2 tag3 IP
1540226502000000000 0.595               host 0.67                0.521               targethost 2                2                   0                   1           0.078                 tag1 tag2 tag3 IP
1540226512000000000 0.58                host 0.604               0.557               targethost 2                2                   0                   1           0.033                 tag1 tag2 tag3 IP
1540226522000000000 0.583               host 0.613               0.553               targethost 2                2                   0                   1           0.03                  tag1 tag2 tag3 IP
1540226532000000000 0.592               host 0.673               0.511               targethost 2                2                   0                   1           0.081                 tag1 tag2 tag3 IP
1540226542000000000 0.593               host 0.67                0.516               targethost 2                2                   0                   1           0.077                 tag1 tag2 tag3 IP
1540226552000000000 1.083               host 1.498               0.668               targethost 2                2                   0                   1           0.415                 tag1 tag2 tag3 IP
1540226562000000000 0.608               host 0.674               0.543               targethost 2                3                   33.33333333333333   1           0.069                 tag1 tag2 tag3 IP
1540226572000000000 0.565               host 0.602               0.528               targethost 2                2                   0                   1           0.037                 tag1 tag2 tag3 IP
1540226582000000000 0.569               host 0.626               0.512               targethost 2                2                   0                   1           0.057                 tag1 tag2 tag3 IP
1540226592000000000 0.591               host 0.666               0.517               targethost 2                2                   0                   1           0.078                 tag1 tag2 tag3 IP
1540226602000000000 0.578               host 0.634               0.523               targethost 2                2                   0                   1           0.06                  tag1 tag2 tag3 IP

@glinton
Copy link
Contributor

glinton commented Oct 22, 2018

@david-guenault what OS are you running telegraf on, and can you run ping -c 2 <targethost> followed by echo $? to check the exit status of the previous successful ping.


edit
Ubuntu 18.04 I get result_code=0 on successful pings.

ping,url=172.17.0.3 maximum_response_ms=0.069,standard_deviation_ms=0.014,result_code=0i,packets_transmitted=2i,packets_received=2i,percent_packet_loss=0,minimum_response_ms=0.044,average_response_ms=0.056 1540233974000000000

@darox
Copy link
Author

darox commented Oct 23, 2018

Problem seems to be fixed for me on the latest telegraf release i.e 1.8.x

@david-guenault
Copy link

@david-guenault what OS are you running telegraf on, and can you run ping -c 2 <targethost> followed by echo $? to check the exit status of the previous successful ping.

For the OS:

LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.5.1804 (Core)
Release:        7.5.1804
Codename:       Core

For the ping command i get 0 as return code

ping -c 2 targethost.domain.tld && echo $?
PING targethost.domain.tld (192.168.10.5) 56(84) bytes of data.
64 bytes targethost.domain.tld (192.168.10.5): icmp_seq=1 ttl=251 time=1.52 ms
64 bytes from targethost.domain.tld (192.168.10.5): icmp_seq=2 ttl=251 time=1.44 ms

--- targethost.domain.tld ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 1.448/1.484/1.521/0.053 ms
0

This is what i get in influx

> select * from ping where "name" =~ /^targethost.domain.tld$/ AND time >= now() - 5m  limit 100
name: ping
time                average_response_ms host         maximum_response_ms minimum_response_ms name                packets_received packets_transmitted percent_packet_loss result_code standard_deviation_ms tag1      tag2         tag3                 url
----                ------------------- ----         ------------------- ------------------- ----                ---------------- ------------------- ------------------- ----------- --------------------- ----      ----         ----                 ---
1540275972000000000 1.484               telegraf1 1.542               1.427               targethost.domain.tld 2                2                   0                   1           0.069                 tag1 tag2 tag3 192.168.10.5
1540275982000000000 1.539               telegraf1 1.654               1.424               targethost.domain.tld 2                2                   0                   1           0.115                 tag1 tag2 tag3 192.168.10.5
1540275992000000000 1.484               telegraf1 1.497               1.472               targethost.domain.tld 2                2                   0                   1           0.04                  tag1 tag2 tag3 192.168.10.5
1540276002000000000 1.673               telegraf1 1.864               1.482               targethost.domain.tld 2                2                   0                   1           0.191                 tag1 tag2 tag3 192.168.10.5
1540276012000000000 1.475               telegraf1 1.513               1.437               targethost.domain.tld 2                2                   0                   1           0.038                 tag1 tag2 tag3 192.168.10.5
1540276022000000000 2.215               telegraf1 2.36                2.07                targethost.domain.tld 2                2                   0                   1           0.145                 tag1 tag2 tag3 192.168.10.5
1540276032000000000 1.497               telegraf1 1.625               1.37                targethost.domain.tld 2                2                   0                   1           0.133                 tag1 tag2 tag3 192.168.10.5
1540276042000000000 1.726               telegraf1 2.018               1.434               targethost.domain.tld 2                2                   0                   1           0.292                 tag1 tag2 tag3 192.168.10.5
1540276052000000000 1.576               telegraf1 1.674               1.478               targethost.domain.tld 2                2                   0                   1           0.098                 tag1 tag2 tag3 192.168.10.5
1540276062000000000 1.451               telegraf1 1.464               1.438               targethost.domain.tld 2                2                   0                   1           0.013                 tag1 tag2 tag3 192.168.10.5
1540276072000000000 1.473               telegraf1 1.51                1.436               targethost.domain.tld 2                2                   0                   1           0.037                 tag1 tag2 tag3 192.168.10.5
1540276082000000000 1.464               telegraf1 1.501               1.428               targethost.domain.tld 2                2                   0                   1           0.052                 tag1 tag2 tag3 192.168.10.5
1540276092000000000 1.459               telegraf1 1.472               1.447               targethost.domain.tld 2                2                   0                   1           0.04                  tag1 tag2 tag3 192.168.10.5

And the related configuration in telegraf

[[inputs.ping]]
  urls = ["192.168.10.5"]
  count = 3
  interval = "10.0s"
  timeout = 1.0
  deadline = 2
  [inputs.ping.tags]
    tag1 = "tag1"
    tag2 = "tag2"
    tag3 = "tag3"
    name = "targethost.domain.tld"

@glinton
Copy link
Contributor

glinton commented Oct 23, 2018

Ok, it's because it's being canceled. You are sending 3 pings, but with a deadline of 2, it sends/receives 2 then cancels the third, resulting in an exit code of 1. Either drop your count or increase your deadline.

@david-guenault
Copy link

Oh crap should have been reading (and testing) more carrefuly ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants