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

fix netdev collector for linux #890

Conversation

dmitriy-lukyanchikov
Copy link
Contributor

header for transmit traffic is differs from recieve, so we cannot use recieve header as transmit, now we can see carier and colls metrics in prometheus

root@dimon-note:~# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
wlp3s0:  615351    3633    0    0    0     0          0         0   139984     968    0    0    0     0       0          0
    lo:  626743    3507    0    0    0     0          0         0   626743    3507    0    0    0     0       0          0
enp2s0: 137449283  136651    0    0    0     0          0      1718 32085642   98565    0    0    0     0       0          0
  tun0: 8585664   20643    0    0    0     0          0         0 14582735   24569    0    0    0     0       0          0
docker0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

@dmitriy-lukyanchikov
Copy link
Contributor Author

for some reason the test promt worning

# github.com/prometheus/node_exporter
/tmp/go-link-531251375/000003.o: In function `mygetgrouplist':
/usr/local/go/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-531251375/000003.o: In function `mygetgrgid_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-531251375/000003.o: In function `mygetgrnam_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-531251375/000003.o: In function `mygetpwnam_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-531251375/000003.o: In function `mygetpwuid_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-531251375/000001.o: In function `_cgo_b0c710f30cfd_C2func_getaddrinfo':
/tmp/go-build/net/_obj/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

but looks like the problem not in this changes

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this bug.

@@ -50,12 +50,14 @@ func parseNetDevStats(r io.Reader, ignore *regexp.Regexp) (map[string]map[string
scanner.Text())
}

header := strings.Fields(parts[1])
header_recieve := strings.Fields(parts[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use go-style variable names. For example this should be recieveHeader.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also receive, not recieve

netDev := map[string]map[string]string{}
for scanner.Scan() {
line := strings.TrimLeft(scanner.Text(), " ")
parts := procNetDevFieldSep.Split(line, -1)
if len(parts) != 2*len(header)+1 {
if len(parts) != len(header_recieve)+len(header_transmit)+1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move len(header_recieve)+len(header_transmit)+1 up to line 55 as something like this:

headerLength := len(recieveHeader)+len(transmitHeader)+1

Then we can test len(parts) != headerLength.

@SuperQ
Copy link
Member

SuperQ commented Apr 10, 2018

The actual test failure is below what you posted.

--- FAIL: TestNetDevStats (0.00s)
	netdev_linux_test.go:43: want netstat tun0 packets 934, got 24

}

for i := 0; i < len(header_transmit); i++ {
netDev[dev]["transmit_"+header_transmit[i]] = parts[i+1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offset on parts here is incorrect. It should be parts[i+1+len(recieveHeader)].

@dmitriy-lukyanchikov
Copy link
Contributor Author

@SuperQ fixed, please review

@grobie
Copy link
Member

grobie commented Apr 10, 2018

@dmitriy-lukyanchikov the indentation is off. Please ensure that make all passes.

@SuperQ
Copy link
Member

SuperQ commented Apr 11, 2018

The end-to-end fixture needs to be updated. You can run ./end-to-end-test.sh -u to do this.

Please also use git commit -s to sign-off your commits. We require that you sign off a Developer Certificate of Origin.

@SuperQ
Copy link
Member

SuperQ commented Apr 11, 2018

Please make sure to make format, I'm still seeing some formatting issues.

fix variable name, fix transmitHeader extracting
modify fixtures to run tests with updated netdev_linux collector

Signed-off-by: dmitriy-lukyanchikov <d.lukyanchikov@anchorfree.com>
@dmitriy-lukyanchikov
Copy link
Contributor Author

dmitriy-lukyanchikov commented Apr 11, 2018

@SuperQ thank you for helping with this) now looks like all tests are passsed

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Awesome.

@SuperQ
Copy link
Member

SuperQ commented Apr 13, 2018

Ping @discordianfish / @grobie, any other comments?

@discordianfish
Copy link
Member

LGTM

@discordianfish discordianfish merged commit eddd1b9 into prometheus:master Apr 14, 2018
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
fix variable name, fix transmitHeader extracting
modify fixtures to run tests with updated netdev_linux collector

Signed-off-by: dmitriy-lukyanchikov <d.lukyanchikov@anchorfree.com>
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

Successfully merging this pull request may close these issues.

None yet

4 participants