ExpVar returns an expvar variable suitable for registering with expvar.Publish.
()
| 2164 | |
| 2165 | // ExpVar returns an expvar variable suitable for registering with expvar.Publish. |
| 2166 | func (ns *Impl) ExpVar() expvar.Var { |
| 2167 | m := new(metrics.Set) |
| 2168 | |
| 2169 | // Global metrics |
| 2170 | stats := ns.ipstack.Stats() |
| 2171 | m.Set("counter_dropped_packets", expvar.Func(func() any { |
| 2172 | return readStatCounter(stats.DroppedPackets) |
| 2173 | })) |
| 2174 | |
| 2175 | // IP statistics |
| 2176 | ipStats := ns.ipstack.Stats().IP |
| 2177 | ipMetrics := []struct { |
| 2178 | name string |
| 2179 | field *tcpip.StatCounter |
| 2180 | }{ |
| 2181 | {"packets_received", ipStats.PacketsReceived}, |
| 2182 | {"valid_packets_received", ipStats.ValidPacketsReceived}, |
| 2183 | {"disabled_packets_received", ipStats.DisabledPacketsReceived}, |
| 2184 | {"invalid_destination_addresses_received", ipStats.InvalidDestinationAddressesReceived}, |
| 2185 | {"invalid_source_addresses_received", ipStats.InvalidSourceAddressesReceived}, |
| 2186 | {"packets_delivered", ipStats.PacketsDelivered}, |
| 2187 | {"packets_sent", ipStats.PacketsSent}, |
| 2188 | {"outgoing_packet_errors", ipStats.OutgoingPacketErrors}, |
| 2189 | {"malformed_packets_received", ipStats.MalformedPacketsReceived}, |
| 2190 | {"malformed_fragments_received", ipStats.MalformedFragmentsReceived}, |
| 2191 | {"iptables_prerouting_dropped", ipStats.IPTablesPreroutingDropped}, |
| 2192 | {"iptables_input_dropped", ipStats.IPTablesInputDropped}, |
| 2193 | {"iptables_forward_dropped", ipStats.IPTablesForwardDropped}, |
| 2194 | {"iptables_output_dropped", ipStats.IPTablesOutputDropped}, |
| 2195 | {"iptables_postrouting_dropped", ipStats.IPTablesPostroutingDropped}, |
| 2196 | {"option_timestamp_received", ipStats.OptionTimestampReceived}, |
| 2197 | {"option_record_route_received", ipStats.OptionRecordRouteReceived}, |
| 2198 | {"option_router_alert_received", ipStats.OptionRouterAlertReceived}, |
| 2199 | {"option_unknown_received", ipStats.OptionUnknownReceived}, |
| 2200 | } |
| 2201 | for _, metric := range ipMetrics { |
| 2202 | m.Set("counter_ip_"+metric.name, expvar.Func(func() any { |
| 2203 | return readStatCounter(metric.field) |
| 2204 | })) |
| 2205 | } |
| 2206 | |
| 2207 | // IP forwarding statistics |
| 2208 | fwdStats := ipStats.Forwarding |
| 2209 | fwdMetrics := []struct { |
| 2210 | name string |
| 2211 | field *tcpip.StatCounter |
| 2212 | }{ |
| 2213 | {"unrouteable", fwdStats.Unrouteable}, |
| 2214 | {"exhausted_ttl", fwdStats.ExhaustedTTL}, |
| 2215 | {"initializing_source", fwdStats.InitializingSource}, |
| 2216 | {"link_local_source", fwdStats.LinkLocalSource}, |
| 2217 | {"link_local_destination", fwdStats.LinkLocalDestination}, |
| 2218 | {"packet_too_big", fwdStats.PacketTooBig}, |
| 2219 | {"host_unreachable", fwdStats.HostUnreachable}, |
| 2220 | {"extension_header_problem", fwdStats.ExtensionHeaderProblem}, |
| 2221 | {"unexpected_multicast_input_interface", fwdStats.UnexpectedMulticastInputInterface}, |
| 2222 | {"unknown_output_endpoint", fwdStats.UnknownOutputEndpoint}, |
| 2223 | {"no_multicast_pending_queue_buffer_space", fwdStats.NoMulticastPendingQueueBufferSpace}, |