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

[[inputs.ntpq]] works, but produce errors in the log "E! Error ntpq: parsing int: u" #2386

Closed
sunserg opened this issue Feb 9, 2017 · 6 comments
Labels
bug unexpected problem or unintended behavior help wanted Request for community participation, code, contribution
Milestone

Comments

@sunserg
Copy link

sunserg commented Feb 9, 2017

Bug report

telegraf.service log shows the error every 10s: "E! Error ntpq: parsing int: u"

osboxes@osboxes:~$ sudo systemctl status telegraf.service
● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB
   Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-02-09 13:05:04 GMT; 3h 40min ago
     Docs: https://github.com/influxdata/telegraf
 Main PID: 2237 (telegraf)
   CGroup: /system.slice/telegraf.service
           └─2237 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

Feb 09 16:44:30 osboxes telegraf[2237]: 2017-02-09T16:44:30Z E! Error ntpq: parsing int: u
Feb 09 16:44:40 osboxes telegraf[2237]: 2017-02-09T16:44:40Z E! Error ntpq: parsing int: u
Feb 09 16:44:50 osboxes telegraf[2237]: 2017-02-09T16:44:50Z E! Error ntpq: parsing int: u
Feb 09 16:45:00 osboxes telegraf[2237]: 2017-02-09T16:45:00Z E! Error ntpq: parsing int: u
Feb 09 16:45:10 osboxes telegraf[2237]: 2017-02-09T16:45:10Z E! Error ntpq: parsing int: u
Feb 09 16:45:20 osboxes telegraf[2237]: 2017-02-09T16:45:20Z E! Error ntpq: parsing int: u
Feb 09 16:45:30 osboxes telegraf[2237]: 2017-02-09T16:45:30Z E! Error ntpq: parsing int: u
Feb 09 16:45:40 osboxes telegraf[2237]: 2017-02-09T16:45:40Z E! Error ntpq: parsing int: u
Feb 09 16:45:50 osboxes telegraf[2237]: 2017-02-09T16:45:50Z E! Error ntpq: parsing int: u
Feb 09 16:46:00 osboxes telegraf[2237]: 2017-02-09T16:46:00Z E! Error ntpq: parsing int: u
osboxes@osboxes:~$

Relevant telegraf.conf:

# # Get standard NTP query metrics, requires ntpq executable.
[[inputs.ntpq]]
#   ## If false, set the -n ntpq flag. Can reduce metric gather time.
  dns_lookup = true

System info:

Linux osboxes 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
telegraf v. 1.2.1-1

Steps to reproduce:

  1. enable ntpq input in telegraf.conf
  2. restart telegraf.service

Expected behavior:

no errors

Actual behavior:

errors

Additional info:

output of ntpq is:

osboxes@osboxes:~$ ntpq -p 
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
#192.168.2.101   194.109.6.2      3 u  236 1024  377    0.598    4.504  11.352
+194.109.22.18   193.67.79.202    2 u  317 1024  377    5.177    1.202   0.202
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
@sparrc sparrc added bug unexpected problem or unintended behavior help wanted Request for community participation, code, contribution labels Feb 9, 2017
@sparrc sparrc added this to the Future Milestone milestone Feb 9, 2017
@danielnelson danielnelson removed this from the Future Milestone milestone Jun 14, 2017
@bascht
Copy link

bascht commented Jul 3, 2017

Same here. More output, if it helps debugging:

$ ntpq -p 
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
*char-ntp-pool.c .SHM.            1 u  579 1024  377   21.200    0.296   0.362
+37.58.57.238 (d 192.53.103.103   2 u   10 1024  377    1.748    0.373   0.101
+srv24.globale-g 131.188.3.222    2 u  682 1024  377    5.637    0.611   0.295
-re.uni-paderbor .DCF.            1 u  268 1024  377   21.700    4.553   1.030
-tms-proxy.smart 193.67.79.202    2 u  688 1024  377    5.101   -0.233   0.303

@dsalbert
Copy link
Contributor

I think this error is related to vary number of columns provided by ntpq command for some cases like e.g.

+37.58.57.238 (d 192.53.103.103   2 u   10 1024  377    1.748    0.373   0.101

Character that is splitting columns is a regular space, so adjusting fields := strings.Fields(line) function to use only TAB is not possible.

My propose is a little bit "hacky":

		fields := strings.Fields(line)

		if len(fields) < 2 {
			continue
		}

		// In case when, there will be more columns that desired (10)		
		desiredColumns := 10
		if len(fields) > desiredColumns {
			var (
				deleteStop = (len(fields) - desiredColumns) + 1
				firstField = strings.Join(fields[0:deleteStop], "")
			)

			fields = append(fields[:1], fields[deleteStop:]...)
			fields[0] = firstField
		}

What do you think?

@danielnelson
Copy link
Contributor

I wonder if ought to first enable -w before spending time fixing the current format. It will allow us to report the full dns entry instead of a potentially truncated value. This will change the output to be like:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.ntp.org
                 .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.debian.pool.ntp.org
                 .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.debian.pool.ntp.org
                 .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.debian.pool.ntp.org
                 .POOL.          16 p    -   64    0    0.000    0.000   0.000
#kapu.ruselabs.com
                 200.98.196.212   2 u   56   64    1   87.060    0.095   0.388
#triton.ellipse.net
                 216.229.0.179    2 u   55   64    1   69.776  -17.777   0.492
#ns1.oninit.net  198.55.111.5     3 u   55   64    1   53.744    1.926   0.592
+x.ns.gin.ntt.net
                 249.224.99.213   2 u   29   64    3   13.428   -0.100   0.674
-138.68.46.177 (au.kashra.pictures)
                 90.187.7.5       3 u   29   64    3   14.746   -1.147   1.262
-services.quadranet.com
                 45.79.111.114    3 u   29   64    3   24.820   -3.205   0.653
-ntp-3.jonlight.com
                 66.220.9.122     2 u   28   64    3   14.785    2.040   1.326
-chimera.bufferoverflow.xyz
                 128.252.19.1     2 u   28   64    3   63.300   -5.883   0.568
#eterna.binary.net
                 216.229.0.50     3 u   29   64    3   70.741  -12.018   0.948
-time-a.timefreq.bldrdoc.gov
                 .NIST.           1 u   30   64    3   84.074   -2.977   0.548
+ntp.idealab.com 208.76.2.12      2 u   28   64    3   24.207    0.570   0.713
*utcnist2.colorado.edu
                 .NIST.           1 u   27   64    3   42.894   -1.280   0.436
-ec2-75-101-249-126.compute-1.amazonaws.com
                 138.39.23.13     2 u   25   64    3   80.911   -0.274   0.740
#96.226.123.195 (smtp.visionnet.us)
                 216.229.0.179    2 u   27   64    3   53.842  -12.868   0.581
#lithium.constant.com
                 18.26.4.105      2 u   27   64    3   83.253    2.217   0.638
-209.208.79.69   209.51.161.238   2 u   27   64    3   84.091   -1.290   0.419

From man ntpq:

              Display the full value of the 'remote' value.  If this requires
              more than 15 characters, display the full value, emit a newline,
              and continue the data display properly indented on the next
              line.

If we do this the parser will need to change quite a bit, but I think I would either try tokenizing with a regex or possibly iterating right to left.

@dsalbert
Copy link
Contributor

dsalbert commented Jul 17, 2017

I do not have this option in my binary. Which version of ntpq are you using?
If we know that we need to remove from a string an expression that starts from ( and end up with a space, what about just using \((\s|\S+) regexp, on whole stream or on each line?
e.g.

	reg, _ := regexp.Compile("\\((\\s|\\S+)")
	output1 := reg.ReplaceAllString("#96.226.123.195 (smtp.visionnet.us) 16.229.0.179    2 u   27   64    3   53.842 -12.868 0.581", "")
	output2 := reg.ReplaceAllString("#96.226.123.195 (s 216.229.0.179    2 u   27   64    3   53.842  -12.868   0.581", "")
	output3 := reg.ReplaceAllString("#96.226.123.195 ( 216.229.0.179    2 u   27   64    3   53.842  -12.868   0.581", "")

result:

#96.226.123.195  16.229.0.179    2 u   27   64    3   53.842 -12.868 0.581
#96.226.123.195  216.229.0.179    2 u   27   64    3   53.842  -12.868   0.581
#96.226.123.195 216.229.0.179    2 u   27   64    3   53.842  -12.868   0.581

@danielnelson
Copy link
Contributor

I guess -w is too new, both 4.2.8p10 in debian stretch and gentoo have it, but 4.2.6p5 in Centos 7 does not.

Regex replacement on the whole line sounds good, if you want to line up the whitespace for no reason other than because you are crazy like me you could do:

`\([^\s]*`

@dsalbert
Copy link
Contributor

As a proof that I am, I've used \([\S]*;>

@danielnelson danielnelson added this to the 1.4.0 milestone Jul 18, 2017
@danielnelson danielnelson modified the milestones: 1.3.5, 1.4.0 Jul 25, 2017
jawi pushed a commit to jawi/telegraf that referenced this issue Aug 24, 2017
- added test cases for SHM remotes;
- slightly changed the fix for influxdata#2386 to improve and fix the parsing of
  SHM remotes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior help wanted Request for community participation, code, contribution
Projects
None yet
Development

No branches or pull requests

5 participants