mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
pkg/proxy/metrics: refactor nfacct metrics collection
Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
parent
a70089ab99
commit
f7fae7297c
@ -147,7 +147,8 @@ var (
|
|||||||
"kubeproxy_iptables_ct_state_invalid_dropped_packets_total",
|
"kubeproxy_iptables_ct_state_invalid_dropped_packets_total",
|
||||||
"packets dropped by iptables to work around conntrack problems",
|
"packets dropped by iptables to work around conntrack problems",
|
||||||
nil, nil, metrics.ALPHA, "")
|
nil, nil, metrics.ALPHA, "")
|
||||||
IPTablesCTStateInvalidDroppedNFAcctCounter = "ct_state_invalid_dropped_pkts"
|
IPTablesCTStateInvalidDroppedNFAcctCounter = "ct_state_invalid_dropped_pkts"
|
||||||
|
iptablesCTStateInvalidDroppedMetricCollector = newNFAcctMetricCollector(IPTablesCTStateInvalidDroppedNFAcctCounter, iptablesCTStateInvalidDroppedPacketsDescription)
|
||||||
|
|
||||||
// IPTablesRestoreFailuresTotal is the number of iptables restore failures that the proxy has
|
// IPTablesRestoreFailuresTotal is the number of iptables restore failures that the proxy has
|
||||||
// seen.
|
// seen.
|
||||||
@ -289,7 +290,7 @@ func RegisterMetrics(mode kubeproxyconfig.ProxyMode) {
|
|||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case kubeproxyconfig.ProxyModeIPTables:
|
case kubeproxyconfig.ProxyModeIPTables:
|
||||||
legacyregistry.CustomMustRegister(newCTStateInvalidPacketsCollector())
|
legacyregistry.CustomMustRegister(iptablesCTStateInvalidDroppedMetricCollector)
|
||||||
legacyregistry.MustRegister(SyncFullProxyRulesLatency)
|
legacyregistry.MustRegister(SyncFullProxyRulesLatency)
|
||||||
legacyregistry.MustRegister(SyncPartialProxyRulesLatency)
|
legacyregistry.MustRegister(SyncPartialProxyRulesLatency)
|
||||||
legacyregistry.MustRegister(IPTablesRestoreFailuresTotal)
|
legacyregistry.MustRegister(IPTablesRestoreFailuresTotal)
|
||||||
@ -315,34 +316,40 @@ func SinceInSeconds(start time.Time) float64 {
|
|||||||
return time.Since(start).Seconds()
|
return time.Since(start).Seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ metrics.StableCollector = &ctStateInvalidPacketsCollector{}
|
var _ metrics.StableCollector = &nfacctMetricCollector{}
|
||||||
|
|
||||||
func newCTStateInvalidPacketsCollector() *ctStateInvalidPacketsCollector {
|
func newNFAcctMetricCollector(counter string, description *metrics.Desc) *nfacctMetricCollector {
|
||||||
client, err := nfacct.New()
|
client, err := nfacct.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "failed to initialize nfacct client")
|
klog.ErrorS(err, "failed to initialize nfacct client")
|
||||||
}
|
}
|
||||||
return &ctStateInvalidPacketsCollector{client: client}
|
return &nfacctMetricCollector{
|
||||||
|
client: client,
|
||||||
|
counter: counter,
|
||||||
|
description: description,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ctStateInvalidPacketsCollector struct {
|
type nfacctMetricCollector struct {
|
||||||
metrics.BaseStableCollector
|
metrics.BaseStableCollector
|
||||||
client nfacct.Interface
|
client nfacct.Interface
|
||||||
|
counter string
|
||||||
|
description *metrics.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
// DescribeWithStability implements the metrics.StableCollector interface.
|
// DescribeWithStability implements the metrics.StableCollector interface.
|
||||||
func (c *ctStateInvalidPacketsCollector) DescribeWithStability(ch chan<- *metrics.Desc) {
|
func (n *nfacctMetricCollector) DescribeWithStability(ch chan<- *metrics.Desc) {
|
||||||
ch <- iptablesCTStateInvalidDroppedPacketsDescription
|
ch <- n.description
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectWithStability implements the metrics.StableCollector interface.
|
// CollectWithStability implements the metrics.StableCollector interface.
|
||||||
func (c *ctStateInvalidPacketsCollector) CollectWithStability(ch chan<- metrics.Metric) {
|
func (n *nfacctMetricCollector) CollectWithStability(ch chan<- metrics.Metric) {
|
||||||
if c.client != nil {
|
if n.client != nil {
|
||||||
counter, err := c.client.Get(IPTablesCTStateInvalidDroppedNFAcctCounter)
|
counter, err := n.client.Get(n.counter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "failed to collect nfacct counter")
|
klog.ErrorS(err, "failed to collect nfacct counter", "counter", n.counter)
|
||||||
} else {
|
} else {
|
||||||
metric, err := metrics.NewConstMetric(iptablesCTStateInvalidDroppedPacketsDescription, metrics.CounterValue, float64(counter.Packets))
|
metric, err := metrics.NewConstMetric(n.description, metrics.CounterValue, float64(counter.Packets))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "failed to create constant metric")
|
klog.ErrorS(err, "failed to create constant metric")
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user