blob: 0396d72015c01a55e0139065e8f9a5cdfcab1776 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001// 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
14package procfs
15
16type (
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.
Abhay Kumara2ae5992025-11-10 14:02:24 +000028// Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead.
khenaidood948f772021-08-11 17:49:24 -040029func (fs FS) NetTCP() (NetTCP, error) {
30 return newNetTCP(fs.proc.Path("net/tcp"))
31}
32
33// NetTCP6 returns the IPv6 kernel/networking statistics for TCP datagrams
34// read from /proc/net/tcp6.
Abhay Kumara2ae5992025-11-10 14:02:24 +000035// Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead.
khenaidood948f772021-08-11 17:49:24 -040036func (fs FS) NetTCP6() (NetTCP, error) {
37 return newNetTCP(fs.proc.Path("net/tcp6"))
38}
39
40// NetTCPSummary returns already computed statistics like the total queue lengths
41// for TCP datagrams read from /proc/net/tcp.
Abhay Kumara2ae5992025-11-10 14:02:24 +000042// Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead.
khenaidood948f772021-08-11 17:49:24 -040043func (fs FS) NetTCPSummary() (*NetTCPSummary, error) {
44 return newNetTCPSummary(fs.proc.Path("net/tcp"))
45}
46
47// NetTCP6Summary returns already computed statistics like the total queue lengths
48// for TCP datagrams read from /proc/net/tcp6.
Abhay Kumara2ae5992025-11-10 14:02:24 +000049// Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead.
khenaidood948f772021-08-11 17:49:24 -040050func (fs FS) NetTCP6Summary() (*NetTCPSummary, error) {
51 return newNetTCPSummary(fs.proc.Path("net/tcp6"))
52}
53
54// newNetTCP creates a new NetTCP{,6} from the contents of the given file.
55func newNetTCP(file string) (NetTCP, error) {
56 n, err := newNetIPSocket(file)
57 n1 := NetTCP(n)
58 return n1, err
59}
60
61func newNetTCPSummary(file string) (*NetTCPSummary, error) {
62 n, err := newNetIPSocketSummary(file)
63 if n == nil {
64 return nil, err
65 }
66 n1 := NetTCPSummary(*n)
67 return &n1, err
68}