newNetDevSNMP6 creates a new NetDevSNMP6 from the contents of the given directory.
(dir string)
| 43 | |
| 44 | // newNetDevSNMP6 creates a new NetDevSNMP6 from the contents of the given directory. |
| 45 | func newNetDevSNMP6(dir string) (NetDevSNMP6, error) { |
| 46 | netDevSNMP6 := make(NetDevSNMP6) |
| 47 | |
| 48 | // The net/dev_snmp6 folders contain one file per interface |
| 49 | ifaceFiles, err := os.ReadDir(dir) |
| 50 | if err != nil { |
| 51 | // On systems with IPv6 disabled, this directory won't exist. |
| 52 | // Do nothing. |
| 53 | if errors.Is(err, os.ErrNotExist) { |
| 54 | return netDevSNMP6, err |
| 55 | } |
| 56 | return netDevSNMP6, err |
| 57 | } |
| 58 | |
| 59 | for _, iFaceFile := range ifaceFiles { |
| 60 | filePath := filepath.Join(dir, iFaceFile.Name()) |
| 61 | |
| 62 | f, err := os.Open(filePath) |
| 63 | if err != nil { |
| 64 | return netDevSNMP6, err |
| 65 | } |
| 66 | defer f.Close() |
| 67 | |
| 68 | netDevSNMP6[iFaceFile.Name()], err = parseNetDevSNMP6Stats(f) |
| 69 | if err != nil { |
| 70 | return netDevSNMP6, err |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return netDevSNMP6, nil |
| 75 | } |
| 76 | |
| 77 | func parseNetDevSNMP6Stats(r io.Reader) (map[string]uint64, error) { |
| 78 | m := make(map[string]uint64) |
no test coverage detected