-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add monitor for sysctl para Signed-off-by: 马洪贞 <hzma@alauda.io> * Update pkg/daemon/exporter_metric.go Co-authored-by: 张祖建 <zhangzujian.7@gmail.com> Signed-off-by: 马洪贞 <hzma@alauda.io> --------- Signed-off-by: 马洪贞 <hzma@alauda.io> Co-authored-by: 张祖建 <zhangzujian.7@gmail.com>
- Loading branch information
Showing
3 changed files
with
304 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,186 @@ | ||
package daemon | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/containernetworking/cni/libcni" | ||
"github.com/docker/docker/libnetwork/resolvconf" | ||
) | ||
|
||
func (c *Controller) setIPLocalPortRangeMetric() { | ||
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(c.config.NodeName, values[0], values[1]).Set(1) | ||
} | ||
|
||
func (c *Controller) setCheckSumErrMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
found = true | ||
} | ||
} | ||
} | ||
if !found { | ||
metricCheckSumErr.WithLabelValues(c.config.NodeName).Set(float64(0)) | ||
} | ||
} | ||
|
||
func (c *Controller) setCniConfigMetric() { | ||
files, err := libcni.ConfFiles(c.config.CniConfDir, []string{".conf", ".conflist"}) | ||
if err != nil { | ||
klog.Errorf("failed to list cni config files in %s: %v", c.config.CniConfDir, err) | ||
return | ||
} | ||
|
||
found := false | ||
for _, file := range files { | ||
if file == c.config.CniConfName { | ||
continue | ||
} | ||
found = true | ||
metricCniConfig.WithLabelValues(c.config.NodeName, c.config.CniConfName, file).Set(1) | ||
} | ||
if !found { | ||
metricCniConfig.WithLabelValues(c.config.NodeName, c.config.CniConfName, "no other cni config").Set(1) | ||
} | ||
} | ||
|
||
func (c *Controller) setDNSSearchMetric() { | ||
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(c.config.NodeName, domain).Set(1) | ||
} | ||
if !found { | ||
metricDNSSearch.WithLabelValues(c.config.NodeName, "no additional search domain").Set(1) | ||
} | ||
} | ||
|
||
func (c *Controller) setTCPTwRecycleMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setTCPMtuProbingMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setConntrackTCPLiberalMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setBridgeNfCallIptablesMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setIPv6RouteMaxsizeMetric() { | ||
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(c.config.NodeName).Set(float64(val)) | ||
} | ||
|
||
func (c *Controller) setTCPMemMetric() { | ||
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(c.config.NodeName, 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