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

switch_legacy invalid memory address or nil pointer dereference 报错 #23

Closed
stiei13wangluo opened this issue Jun 13, 2022 · 2 comments

Comments

@stiei13wangluo
Copy link

Relevant config.toml

[global]
# whether print configs
print_configs = false

# add label(agent_hostname) to series
# "" -> auto detect hostname
# "xx" -> use specified string xx
# "$hostname" -> auto detect hostname
# "$ip" -> auto detect ip
# "$hostname-$ip" -> auto detect hostname and ip to replace the vars
hostname = ""

# will not add label(agent_hostname) if true
omit_hostname = false

# s | ms
precision = "ms"

# global collect interval
interval = 15

# [global.labels]
# region = "shanghai"
# env = "localhost"

[writer_opt]
# default: 2000
batch = 2000
# channel(as queue) size
chan_size = 10000

[[writers]]
url = "http://127.0.0.1:19000/prometheus/v1/write"

# Basic auth username
basic_auth_user = ""

# Basic auth password
basic_auth_pass = ""

# timeout settings, unit: ms
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100

Logs from categraf

[root@localhost categraf]# ./categraf -inputs switch_legacy --debug
2022/06/13 20:09:04 main.go:100: I! runner.binarydir: /opt/categraf
2022/06/13 20:09:04 main.go:101: I! runner.hostname: localhost.localdomain
2022/06/13 20:09:04 main.go:102: I! runner.fd_limits: (soft=1024, hard=4096)
2022/06/13 20:09:04 main.go:103: I! runner.vm_limits: (soft=unlimited, hard=unlimited)
2022/06/13 20:09:04 agent.go:59: I! agent starting
2022/06/13 20:09:04 agent.go:128: I! input: switch_legacy started
2022/06/13 20:09:19 switch_legacy.go:160: I! switch total ip count: 50
2022/06/13 20:09:20 switch_legacy.go:622: I! switch alive ip count: 20
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.21 use: 291.789105ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.12 use: 507.190428ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.20 use: 530.192047ms
2022/06/13 20:09:21 ifstat.go:481: 172.16.1.33 1.3.6.1.2.1.31.1.1.1.6 Error reading from UDP: read udp 192.168.30.196:44281->172.16.1.33:161: read: connection refused

2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.25 use: 531.690995ms
2022/06/13 20:09:21 ifstat.go:481: 172.16.1.33 1.3.6.1.2.1.31.1.1.1.10 Error reading from UDP: read udp 192.168.30.196:40044->172.16.1.33:161: read: connection refused

2022/06/13 20:09:21 ifstat.go:481: 172.16.1.33 1.3.6.1.2.1.31.1.1.1.1 Error reading from UDP: read udp 192.168.30.196:54286->172.16.1.33:161: read: connection refused

2022/06/13 20:09:21 ifstat.go:481: 172.16.1.33 1.3.6.1.2.1.31.1.1.1.15 Error reading from UDP: read udp 192.168.30.196:34306->172.16.1.33:161: read: connection refused

2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.26 use: 737.653433ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.27 use: 740.243693ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.23 use: 739.534897ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.22 use: 753.467539ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.28 use: 766.415817ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.10 use: 780.563246ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.2 use: 790.727224ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.24 use: 837.069319ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.29 use: 879.376911ms
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.9 use: 945.680532ms
2022/06/13 20:09:21 ifstat.go:481: 172.16.1.33 1.3.6.1.2.1.2.2.1.8 Error reading from UDP: read udp 192.168.30.196:38969->172.16.1.33:161: read: connection refused

2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.33 use: 1.07100339s
2022/06/13 20:09:21 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.1 use: 1.132475892s
2022/06/13 20:09:22 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.16 use: 1.555391329s
2022/06/13 20:09:26 ifstat.go:481: 172.16.1.40 1.3.6.1.2.1.31.1.1.1.6 Error reading from UDP: read udp 192.168.30.196:33697->172.16.1.40:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.41 1.3.6.1.2.1.31.1.1.1.6 Error reading from UDP: read udp 192.168.30.196:39162->172.16.1.41:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.49 1.3.6.1.2.1.31.1.1.1.6 Error reading from UDP: read udp 192.168.30.196:50882->172.16.1.49:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.40 1.3.6.1.2.1.31.1.1.1.10 Error reading from UDP: read udp 192.168.30.196:47804->172.16.1.40:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.41 1.3.6.1.2.1.31.1.1.1.10 Error reading from UDP: read udp 192.168.30.196:57841->172.16.1.41:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.40 1.3.6.1.2.1.31.1.1.1.1 Error reading from UDP: read udp 192.168.30.196:58825->172.16.1.40:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.49 1.3.6.1.2.1.31.1.1.1.10 Error reading from UDP: read udp 192.168.30.196:52002->172.16.1.49:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.49 1.3.6.1.2.1.31.1.1.1.1 Error reading from UDP: read udp 192.168.30.196:46410->172.16.1.49:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.41 1.3.6.1.2.1.31.1.1.1.1 Error reading from UDP: read udp 192.168.30.196:37835->172.16.1.41:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.41 1.3.6.1.2.1.31.1.1.1.15 Error reading from UDP: read udp 192.168.30.196:51284->172.16.1.41:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.49 1.3.6.1.2.1.31.1.1.1.15 Error reading from UDP: read udp 192.168.30.196:59658->172.16.1.49:161: i/o timeout

2022/06/13 20:09:26 ifstat.go:481: 172.16.1.40 1.3.6.1.2.1.31.1.1.1.15 Error reading from UDP: read udp 192.168.30.196:51417->172.16.1.40:161: i/o timeout

2022/06/13 20:09:31 ifstat.go:481: 172.16.1.40 1.3.6.1.2.1.2.2.1.8 Error reading from UDP: read udp 192.168.30.196:35029->172.16.1.40:161: i/o timeout

2022/06/13 20:09:31 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.40 use: 11.016978694s
2022/06/13 20:09:31 ifstat.go:481: 172.16.1.41 1.3.6.1.2.1.2.2.1.8 Error reading from UDP: read udp 192.168.30.196:45716->172.16.1.41:161: i/o timeout

2022/06/13 20:09:31 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.41 use: 11.016114441s
2022/06/13 20:09:31 ifstat.go:481: 172.16.1.49 1.3.6.1.2.1.2.2.1.8 Error reading from UDP: read udp 192.168.30.196:41289->172.16.1.49:161: i/o timeout

2022/06/13 20:09:31 switch_legacy.go:575: D! switch gather ifstat, ip: 172.16.1.49 use: 11.014485164s
2022/06/13 20:09:31 switch_legacy.go:157: I! switch gather use: 12.505793784s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xbc377d]

goroutine 19 [running]:
flashcat.cloud/categraf/inputs/switch_legacy.(*Instance).gatherFlowMetrics(0xc0003e8c60, {0xc0003a6a80, 0x14, 0x50?}, 0xc00005cc00?)
        /home/runner/work/categraf/categraf/inputs/switch_legacy/switch_legacy.go:327 +0x33d
flashcat.cloud/categraf/inputs/switch_legacy.(*Instance).gatherOnce(0xc0003e8c60, 0x0?)
        /home/runner/work/categraf/categraf/inputs/switch_legacy/switch_legacy.go:167 +0x185
flashcat.cloud/categraf/inputs/switch_legacy.(*Switch).Gather.func1(0x7637a6?, 0x0?)
        /home/runner/work/categraf/categraf/inputs/switch_legacy/switch_legacy.go:77 +0xac
created by flashcat.cloud/categraf/inputs/switch_legacy.(*Switch).Gather
        /home/runner/work/categraf/categraf/inputs/switch_legacy/switch_legacy.go:67 +0x3f

System info

Categraf v0.1.3,Centos7.9.2009

Docker

No response

Steps to reproduce

填写特定段地址报错

Expected behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xbc377d]

Actual behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xbc377d]

Additional info

No response

@UlricQin
Copy link
Contributor

一大早看到你这个 issue,看了一下代码,确实考虑不周,做了修复:7d57ac5

@stiei13wangluo
Copy link
Author

感谢,可以了

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

2 participants