1 // Copyright 2020 The Prometheus Authors 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package procfs 15 16 type ( 17 // NetUDP represents the contents of /proc/net/udp{,6} file without the header. 18 NetUDP []*netIPSocketLine 19 20 // NetUDPSummary provides already computed values like the total queue lengths or 21 // the total number of used sockets. In contrast to NetUDP it does not collect 22 // the parsed lines into a slice. 23 NetUDPSummary NetIPSocketSummary 24 ) 25 26 // NetUDP returns the IPv4 kernel/networking statistics for UDP datagrams 27 // read from /proc/net/udp. 28 func (fs FS) NetUDP() (NetUDP, error) { 29 return newNetUDP(fs.proc.Path("net/udp")) 30 } 31 32 // NetUDP6 returns the IPv6 kernel/networking statistics for UDP datagrams 33 // read from /proc/net/udp6. 34 func (fs FS) NetUDP6() (NetUDP, error) { 35 return newNetUDP(fs.proc.Path("net/udp6")) 36 } 37 38 // NetUDPSummary returns already computed statistics like the total queue lengths 39 // for UDP datagrams read from /proc/net/udp. 40 func (fs FS) NetUDPSummary() (*NetUDPSummary, error) { 41 return newNetUDPSummary(fs.proc.Path("net/udp")) 42 } 43 44 // NetUDP6Summary returns already computed statistics like the total queue lengths 45 // for UDP datagrams read from /proc/net/udp6. 46 func (fs FS) NetUDP6Summary() (*NetUDPSummary, error) { 47 return newNetUDPSummary(fs.proc.Path("net/udp6")) 48 } 49 50 // newNetUDP creates a new NetUDP{,6} from the contents of the given file. 51 func newNetUDP(file string) (NetUDP, error) { 52 n, err := newNetIPSocket(file) 53 n1 := NetUDP(n) 54 return n1, err 55 } 56 57 func newNetUDPSummary(file string) (*NetUDPSummary, error) { 58 n, err := newNetIPSocketSummary(file) 59 if n == nil { 60 return nil, err 61 } 62 n1 := NetUDPSummary(*n) 63 return &n1, err 64 } 65