|
80 | 80 | flags = $1.split(",") |
81 | 81 | iface[cint][:flags] = flags if flags.length > 0 |
82 | 82 | end |
83 | | - if line =~ /metric: (\d+) mtu: (\d+)/ |
| 83 | + if line =~ /metric (\d+) mtu (\d+)/ |
84 | 84 | iface[cint][:metric] = $1 |
85 | 85 | iface[cint][:mtu] = $2 |
86 | 86 | end |
| 87 | + if line =~ /media: (\w+)/ |
| 88 | + iface[cint][:encapsulation] = $1 |
| 89 | + end |
87 | 90 | end |
88 | 91 |
|
89 | 92 | so = shell_out("arp -an") |
|
104 | 107 | # which have been auto-configured (interfaces statically configured |
105 | 108 | # into a system, but not located at boot time are not shown). |
106 | 109 | so = shell_out("netstat -ibdn") |
107 | | - so.stdout.lines do |line| |
| 110 | + head = so.stdout.lines[0] |
| 111 | + have_drop = false |
| 112 | + if head =~ /Idrop/ |
| 113 | + have_drop = true |
| 114 | + # Name Mtu Network Address Ipkts Ierrs Idrop Ibytes Opkts Oerrs Obytes Coll Drop |
| 115 | + # vtnet0 1500 <Link#1> fa:16:3e:ba:3e:25 579 0 0 46746 210 0 26242 0 0 |
| 116 | + # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 |
| 117 | + regex = /^([\w\.\*]+)\s+\d+\s+<Link#\d+>\s+([\w\d:]*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ |
| 118 | + else |
108 | 119 | # Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop |
109 | 120 | # ed0 1500 <Link#1> 54:52:00:68:92:85 333604 26 151905886 175472 0 24897542 0 905 |
110 | 121 | # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 |
111 | | - if line =~ /^([\w\.\*]+)\s+\d+\s+<Link#\d+>\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ |
| 122 | + regex = /^([\w\.\*]+)\s+\d+\s+<Link#\d+>\s+([\w\d:]*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ |
| 123 | + end |
| 124 | + so.stdout.lines do |line| |
| 125 | + if line =~ regex |
112 | 126 | net_counters[$1] ||= Mash.new |
113 | 127 | net_counters[$1]["rx"] ||= Mash.new |
114 | 128 | net_counters[$1]["tx"] ||= Mash.new |
115 | 129 | net_counters[$1]["rx"]["packets"] = $3 |
116 | 130 | net_counters[$1]["rx"]["errors"] = $4 |
117 | | - net_counters[$1]["rx"]["bytes"] = $5 |
118 | | - net_counters[$1]["tx"]["packets"] = $6 |
119 | | - net_counters[$1]["tx"]["errors"] = $7 |
120 | | - net_counters[$1]["tx"]["bytes"] = $8 |
121 | | - net_counters[$1]["tx"]["collisions"] = $9 |
122 | | - net_counters[$1]["tx"]["dropped"] = $10 |
| 131 | + if have_drop |
| 132 | + net_counters[$1]["rx"]["dropped"] = $5 |
| 133 | + net_counters[$1]["rx"]["bytes"] = $6 |
| 134 | + net_counters[$1]["tx"]["packets"] = $7 |
| 135 | + net_counters[$1]["tx"]["errors"] = $8 |
| 136 | + net_counters[$1]["tx"]["bytes"] = $9 |
| 137 | + net_counters[$1]["tx"]["collisions"] = $10 |
| 138 | + net_counters[$1]["tx"]["dropped"] = $11 |
| 139 | + else |
| 140 | + net_counters[$1]["rx"]["bytes"] = $5 |
| 141 | + net_counters[$1]["tx"]["packets"] = $6 |
| 142 | + net_counters[$1]["tx"]["errors"] = $7 |
| 143 | + net_counters[$1]["tx"]["bytes"] = $8 |
| 144 | + net_counters[$1]["tx"]["collisions"] = $9 |
| 145 | + net_counters[$1]["tx"]["dropped"] = $10 |
| 146 | + end |
| 147 | + |
123 | 148 | end |
124 | 149 | end |
125 | 150 |
|
|
0 commit comments