-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
package daemon | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/docker/docker/libnetwork/resolvconf" | ||
"github.com/kubeovn/kube-ovn/pkg/util" | ||
) | ||
|
||
func (c *Controller) setIPLocalPortRangeMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/ipv4/ip_local_port_range") | ||
if err != nil { | ||
klog.Errorf("failed to get value of ip_local_port_range, err %v", err) | ||
return | ||
} | ||
|
||
values := strings.Fields(string(output)) | ||
if len(values) != 2 { | ||
klog.Errorf("unexpected ip_local_port_range value: %q", string(output)) | ||
return | ||
} | ||
metricIPLocalPortRange.WithLabelValues(hostname, values[0], values[1]).Set(1) | ||
} | ||
|
||
func (c *Controller) setCheckSumErrMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
cmdstr := "netstat -us" | ||
cmd := exec.Command("sh", "-c", cmdstr) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
klog.Errorf("failed to exec cmd 'netstat -us', err %v", err) | ||
return | ||
} | ||
|
||
found := false | ||
lines := strings.Split(string(output), "\n") | ||
for _, line := range lines { | ||
line = strings.TrimSpace(line) | ||
if line == "" { | ||
continue | ||
} | ||
|
||
if strings.Contains(line, "InCsumErrors") { | ||
values := strings.Split(line, ":") | ||
if len(values) == 2 { | ||
val, _ := strconv.Atoi(strings.TrimSpace(values[1])) | ||
metricCheckSumErr.WithLabelValues(hostname).Set(float64(val)) | ||
found = true | ||
} | ||
} | ||
} | ||
if !found { | ||
metricCheckSumErr.WithLabelValues(hostname).Set(float64(0)) | ||
} | ||
} | ||
|
||
func (c *Controller) setCniConfigMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
cmdstr := fmt.Sprintf("ls %s", c.config.CniConfDir) | ||
cmd := exec.Command("sh", "-c", cmdstr) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
klog.Errorf("failed to list cni config file, err %v", err) | ||
return | ||
} | ||
|
||
found := false | ||
lines := strings.Split(string(output), "\n") | ||
for _, line := range lines { | ||
line = strings.TrimSpace(line) | ||
if line == "" { | ||
continue | ||
} | ||
|
||
names := strings.Fields(line) | ||
for _, name := range names { | ||
if name == c.config.CniConfName { | ||
continue | ||
} | ||
found = true | ||
metricCniConfig.WithLabelValues(hostname, c.config.CniConfName, name).Set(1) | ||
} | ||
} | ||
if !found { | ||
metricCniConfig.WithLabelValues(hostname, c.config.CniConfName, "no other cni config").Set(1) | ||
} | ||
} | ||
|
||
func (c *Controller) setDNSSearchMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
file, err := resolvconf.Get() | ||
if err != nil { | ||
klog.Errorf("failed to get /etc/resolv.conf content: %v", err) | ||
return | ||
} | ||
domains := resolvconf.GetSearchDomains(file.Content) | ||
|
||
found := false | ||
for _, domain := range domains { | ||
if strings.Contains(domain, "local") { | ||
continue | ||
} | ||
|
||
found = true | ||
metricDNSSearch.WithLabelValues(hostname, domain).Set(1) | ||
} | ||
if !found { | ||
metricDNSSearch.WithLabelValues(hostname, "no additional search domain").Set(1) | ||
} | ||
} | ||
|
||
func (c *Controller) setTCPTwRecycleMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/ipv4/tcp_tw_recycle") | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return | ||
} | ||
klog.Errorf("failed to get value of tcp_tw_recycle, err %v", err) | ||
return | ||
} | ||
|
||
val, _ := strconv.Atoi(strings.TrimSpace(string(output))) | ||
metricTCPTwRecycle.WithLabelValues(hostname).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setTCPMtuProbingMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/ipv4/tcp_mtu_probing") | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return | ||
} | ||
klog.Errorf("failed to get value of tcp_mtu_probing, err %v", err) | ||
return | ||
} | ||
|
||
val, _ := strconv.Atoi(strings.TrimSpace(string(output))) | ||
metricTCPMtuProbing.WithLabelValues(hostname).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setConntrackTCPLiberalMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal") | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return | ||
} | ||
klog.Errorf("failed to get value of nf_conntrack_tcp_be_liberal, err %v", err) | ||
return | ||
} | ||
|
||
val, _ := strconv.Atoi(strings.TrimSpace(string(output))) | ||
metricConntrackTCPLiberal.WithLabelValues(hostname).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setBridgeNfCallIptablesMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/bridge/bridge-nf-call-iptables") | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return | ||
} | ||
klog.Errorf("failed to get value of bridge-nf-call-iptables, err %v", err) | ||
return | ||
} | ||
|
||
val, _ := strconv.Atoi(strings.TrimSpace(string(output))) | ||
metricBridgeNfCallIptables.WithLabelValues(hostname).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setIPv6RouteMaxsizeMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/ipv6/route/max_size") | ||
if err != nil { | ||
klog.Errorf("failed to get value of ipv6 route max_size, err %v", err) | ||
return | ||
} | ||
|
||
val, _ := strconv.Atoi(strings.TrimSpace(string(output))) | ||
metricIPv6RouteMaxsize.WithLabelValues(hostname).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setTCPMemMetric() { | ||
hostname := os.Getenv(util.HostnameEnv) | ||
|
||
output, err := os.ReadFile("/proc/sys/net/ipv4/tcp_mem") | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return | ||
} | ||
klog.Errorf("failed to get value of ipv4 tcp_mem, err %v", err) | ||
return | ||
} | ||
|
||
values := strings.Fields(string(output)) | ||
if len(values) != 3 { | ||
klog.Errorf("unexpected tcp_mem value: %q", string(output)) | ||
return | ||
} | ||
metricTCPMem.WithLabelValues(hostname, values[0], values[1], values[2]).Set(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters