@@ -20,14 +20,14 @@ const (
2020)
2121
2222var (
23- NfConnctrackCount = prometheus .NewGaugeVec (prometheus.GaugeOpts {
23+ NfConntrackCount = prometheus .NewGaugeVec (prometheus.GaugeOpts {
2424 Namespace : constants .MetricsNS ,
2525 Subsystem : "egress" ,
2626 Name : "nf_conntrack_entries_count" ,
2727 Help : "the number of entries in the nf_conntrack table" ,
2828 }, []string {"namespace" , "pod" , "egress" })
2929
30- NfConnctrackLimit = prometheus .NewGaugeVec (prometheus.GaugeOpts {
30+ NfConntrackLimit = prometheus .NewGaugeVec (prometheus.GaugeOpts {
3131 Namespace : constants .MetricsNS ,
3232 Subsystem : "egress" ,
3333 Name : "nf_conntrack_entries_limit" ,
@@ -64,31 +64,31 @@ var (
6464)
6565
6666type egressCollector struct {
67- conn * nftables.Conn
68- nfConnctrackCount prometheus.Gauge
69- nfConnctrackLimit prometheus.Gauge
70- perProtocol map [string ]* nfTablesPerProtocolMetrics
67+ conn * nftables.Conn
68+ nfConntrackCount prometheus.Gauge
69+ nfConntrackLimit prometheus.Gauge
70+ perProtocol map [string ]* nfTablesPerProtocolMetrics
7171}
7272
7373type nfTablesPerProtocolMetrics struct {
74- nfTablesNATPackets prometheus.Gauge
75- nfTablesNATBytes prometheus.Gauge
76- nfTablesInvalidPackets prometheus.Gauge
77- nfTablesInvalidBytes prometheus.Gauge
74+ NATPackets prometheus.Gauge
75+ NATBytes prometheus.Gauge
76+ InvalidPackets prometheus.Gauge
77+ InvalidBytes prometheus.Gauge
7878}
7979
8080func newNfTablesPerProtocolMetrics (ns , pod , egress , protocol string ) * nfTablesPerProtocolMetrics {
8181 return & nfTablesPerProtocolMetrics {
82- nfTablesNATPackets : NfTableMasqueradePackets .WithLabelValues (ns , pod , egress , protocol ),
83- nfTablesNATBytes : NfTableMasqueradeBytes .WithLabelValues (ns , pod , egress , protocol ),
84- nfTablesInvalidPackets : NfTableInvalidPackets .WithLabelValues (ns , pod , egress , protocol ),
85- nfTablesInvalidBytes : NfTableInvalidBytes .WithLabelValues (ns , pod , egress , protocol ),
82+ NATPackets : NfTableMasqueradePackets .WithLabelValues (ns , pod , egress , protocol ),
83+ NATBytes : NfTableMasqueradeBytes .WithLabelValues (ns , pod , egress , protocol ),
84+ InvalidPackets : NfTableInvalidPackets .WithLabelValues (ns , pod , egress , protocol ),
85+ InvalidBytes : NfTableInvalidBytes .WithLabelValues (ns , pod , egress , protocol ),
8686 }
8787}
8888
8989func NewEgressCollector (ns , pod , egress string , protocols []string ) (Collector , error ) {
90- NfConnctrackCount .Reset ()
91- NfConnctrackLimit .Reset ()
90+ NfConntrackCount .Reset ()
91+ NfConntrackLimit .Reset ()
9292 NfTableMasqueradeBytes .Reset ()
9393 NfTableMasqueradePackets .Reset ()
9494 NfTableInvalidPackets .Reset ()
@@ -105,10 +105,10 @@ func NewEgressCollector(ns, pod, egress string, protocols []string) (Collector,
105105 }
106106
107107 return & egressCollector {
108- conn : c ,
109- nfConnctrackCount : NfConnctrackCount .WithLabelValues (ns , pod , egress ),
110- nfConnctrackLimit : NfConnctrackLimit .WithLabelValues (ns , pod , egress ),
111- perProtocol : perProtocols ,
108+ conn : c ,
109+ nfConntrackCount : NfConntrackCount .WithLabelValues (ns , pod , egress ),
110+ nfConntrackLimit : NfConntrackLimit .WithLabelValues (ns , pod , egress ),
111+ perProtocol : perProtocols ,
112112 }, nil
113113}
114114
@@ -122,28 +122,28 @@ func (c *egressCollector) Update(ctx context.Context) error {
122122 if err != nil {
123123 return err
124124 }
125- c .nfConnctrackCount .Set (float64 (val ))
125+ c .nfConntrackCount .Set (float64 (val ))
126126
127127 val , err = readUintFromFile (NF_CONNTRACK_LIMIT_PATH )
128128 if err != nil {
129129 return err
130130 }
131- c .nfConnctrackLimit .Set (float64 (val ))
131+ c .nfConntrackLimit .Set (float64 (val ))
132132
133133 for protocol , nfTablesMetrics := range c .perProtocol {
134134 natPackets , natBytes , err := c .getNfTablesNATCounter (protocol )
135135 if err != nil {
136136 return err
137137 }
138- nfTablesMetrics .nfTablesNATPackets .Set (float64 (natPackets ))
139- nfTablesMetrics .nfTablesNATBytes .Set (float64 (natBytes ))
138+ nfTablesMetrics .NATPackets .Set (float64 (natPackets ))
139+ nfTablesMetrics .NATBytes .Set (float64 (natBytes ))
140140
141141 invalidPackets , invalidBytes , err := c .getNfTablesInvalidCounter (protocol )
142142 if err != nil {
143143 return err
144144 }
145- nfTablesMetrics .nfTablesInvalidPackets .Set (float64 (invalidPackets ))
146- nfTablesMetrics .nfTablesInvalidBytes .Set (float64 (invalidBytes ))
145+ nfTablesMetrics .InvalidPackets .Set (float64 (invalidPackets ))
146+ nfTablesMetrics .InvalidBytes .Set (float64 (invalidBytes ))
147147
148148 }
149149
@@ -215,10 +215,10 @@ func readUintFromFile(path string) (uint64, error) {
215215}
216216
217217func stringToTableFamily (protocol string ) (nftables.TableFamily , error ) {
218- switch strings . ToLower ( protocol ) {
219- case "ipv4" :
218+ switch protocol {
219+ case constants . FamilyIPv4 :
220220 return nftables .TableFamilyIPv4 , nil
221- case "ipv6" :
221+ case constants . FamilyIPv6 :
222222 return nftables .TableFamilyIPv6 , nil
223223 default :
224224 return nftables .TableFamilyUnspecified , fmt .Errorf ("unsupported family type: %s" , protocol )
0 commit comments