// Copyright 2023 The Prometheus Authors// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package procfsimport ()// Wireless models the content of /proc/net/wireless.typeWirelessstruct { Name string// Status is the current 4-digit hex value status of the interface. Status uint64// QualityLink is the link quality. QualityLink int// QualityLevel is the signal gain (dBm). QualityLevel int// QualityNoise is the signal noise baseline (dBm). QualityNoise int// DiscardedNwid is the number of discarded packets with wrong nwid/essid. DiscardedNwid int// DiscardedCrypt is the number of discarded packets with wrong code/decode (WEP). DiscardedCrypt int// DiscardedFrag is the number of discarded packets that can't perform MAC reassembly. DiscardedFrag int// DiscardedRetry is the number of discarded packets that reached max MAC retries. DiscardedRetry int// DiscardedMisc is the number of discarded packets for other reasons. DiscardedMisc int// MissedBeacon is the number of missed beacons/superframe. MissedBeacon int}// Wireless returns kernel wireless statistics.func ( FS) () ([]*Wireless, error) { , := util.ReadFileNoStat(.proc.Path("net/wireless"))if != nil {returnnil, } , := parseWireless(bytes.NewReader())if != nil {returnnil, fmt.Errorf("%w: wireless: %w", ErrFileParse, ) }return , nil}// parseWireless parses the contents of /proc/net/wireless./*Inter-| sta-| Quality | Discarded packets | Missed | WEface | tus | link level noise | nwid crypt frag retry misc | beacon | 22 eth1: 0000 5. -256. -10. 0 1 0 3 0 0 eth2: 0000 5. -256. -20. 0 2 0 4 0 0*/func parseWireless( io.Reader) ([]*Wireless, error) {var ( []*Wireless = bufio.NewScanner() )for := 0; .Scan(); ++ {// Skip the 2 header lines.if < 2 {continue } := .Text() := strings.Split(, ":")iflen() != 2 {returnnil, fmt.Errorf("%w: expected 2 parts after splitting line by ':', got %d for line %q", ErrFileParse, len(), ) } := strings.TrimSpace([0]) := strings.Fields([1])iflen() < 10 {returnnil, fmt.Errorf("%w: invalid number of fields in line %d, expected 10+, got %d: %q", ErrFileParse, , len(), ) } , := strconv.ParseUint([0], 16, 16)if != nil {returnnil, fmt.Errorf("%w: invalid status in line %d: %q", ErrFileParse, , ) } , := strconv.Atoi(strings.TrimSuffix([1], "."))if != nil {returnnil, fmt.Errorf("%w: parse Quality:link as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi(strings.TrimSuffix([2], "."))if != nil {returnnil, fmt.Errorf("%w: Quality:level as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi(strings.TrimSuffix([3], "."))if != nil {returnnil, fmt.Errorf("%w: Quality:noise as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([4])if != nil {returnnil, fmt.Errorf("%w: Discarded:nwid as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([5])if != nil {returnnil, fmt.Errorf("%w: Discarded:crypt as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([6])if != nil {returnnil, fmt.Errorf("%w: Discarded:frag as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([7])if != nil {returnnil, fmt.Errorf("%w: Discarded:retry as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([8])if != nil {returnnil, fmt.Errorf("%w: Discarded:misc as integer %q: %w", ErrFileParse, , ) } , := strconv.Atoi([9])if != nil {returnnil, fmt.Errorf("%w: Missed:beacon as integer %q: %w", ErrFileParse, , ) } := &Wireless{Name: ,Status: ,QualityLink: ,QualityLevel: ,QualityNoise: ,DiscardedNwid: ,DiscardedCrypt: ,DiscardedFrag: ,DiscardedRetry: ,DiscardedMisc: ,MissedBeacon: , } = append(, ) }if := .Err(); != nil {returnnil, fmt.Errorf("%w: Failed to scan /proc/net/wireless: %w", ErrFileRead, ) }return , nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.