khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 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 | // NetTCP represents the contents of /proc/net/tcp{,6} file without the header. |
| 18 | NetTCP []*netIPSocketLine |
| 19 | |
| 20 | // NetTCPSummary provides already computed values like the total queue lengths or |
| 21 | // the total number of used sockets. In contrast to NetTCP it does not collect |
| 22 | // the parsed lines into a slice. |
| 23 | NetTCPSummary NetIPSocketSummary |
| 24 | ) |
| 25 | |
| 26 | // NetTCP returns the IPv4 kernel/networking statistics for TCP datagrams |
| 27 | // read from /proc/net/tcp. |
| 28 | func (fs FS) NetTCP() (NetTCP, error) { |
| 29 | return newNetTCP(fs.proc.Path("net/tcp")) |
| 30 | } |
| 31 | |
| 32 | // NetTCP6 returns the IPv6 kernel/networking statistics for TCP datagrams |
| 33 | // read from /proc/net/tcp6. |
| 34 | func (fs FS) NetTCP6() (NetTCP, error) { |
| 35 | return newNetTCP(fs.proc.Path("net/tcp6")) |
| 36 | } |
| 37 | |
| 38 | // NetTCPSummary returns already computed statistics like the total queue lengths |
| 39 | // for TCP datagrams read from /proc/net/tcp. |
| 40 | func (fs FS) NetTCPSummary() (*NetTCPSummary, error) { |
| 41 | return newNetTCPSummary(fs.proc.Path("net/tcp")) |
| 42 | } |
| 43 | |
| 44 | // NetTCP6Summary returns already computed statistics like the total queue lengths |
| 45 | // for TCP datagrams read from /proc/net/tcp6. |
| 46 | func (fs FS) NetTCP6Summary() (*NetTCPSummary, error) { |
| 47 | return newNetTCPSummary(fs.proc.Path("net/tcp6")) |
| 48 | } |
| 49 | |
| 50 | // newNetTCP creates a new NetTCP{,6} from the contents of the given file. |
| 51 | func newNetTCP(file string) (NetTCP, error) { |
| 52 | n, err := newNetIPSocket(file) |
| 53 | n1 := NetTCP(n) |
| 54 | return n1, err |
| 55 | } |
| 56 | |
| 57 | func newNetTCPSummary(file string) (*NetTCPSummary, error) { |
| 58 | n, err := newNetIPSocketSummary(file) |
| 59 | if n == nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | n1 := NetTCPSummary(*n) |
| 63 | return &n1, err |
| 64 | } |