Convert remaining collectors to use ConstMetrics
This commit is contained in:
parent
c53bc168fe
commit
8e50b80d12
17 changed files with 455 additions and 614 deletions
|
|
@ -26,8 +26,8 @@ import (
|
|||
type ipvsCollector struct {
|
||||
Collector
|
||||
fs procfs.FS
|
||||
backendConnectionsActive, backendConnectionsInact, backendWeight *prometheus.GaugeVec
|
||||
connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes prometheus.Counter
|
||||
backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc
|
||||
connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -59,74 +59,46 @@ func newIPVSCollector() (*ipvsCollector, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
c.connections = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "connections_total",
|
||||
Help: "The total number of connections made.",
|
||||
},
|
||||
)
|
||||
c.incomingPackets = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "incoming_packets_total",
|
||||
Help: "The total number of incoming packets.",
|
||||
},
|
||||
)
|
||||
c.outgoingPackets = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "outgoing_packets_total",
|
||||
Help: "The total number of outgoing packets.",
|
||||
},
|
||||
)
|
||||
c.incomingBytes = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "incoming_bytes_total",
|
||||
Help: "The total amount of incoming data.",
|
||||
},
|
||||
)
|
||||
c.outgoingBytes = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "outgoing_bytes_total",
|
||||
Help: "The total amount of outgoing data.",
|
||||
},
|
||||
)
|
||||
|
||||
c.backendConnectionsActive = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "backend_connections_active",
|
||||
Help: "The current active connections by local and remote address.",
|
||||
},
|
||||
ipvsBackendLabelNames,
|
||||
)
|
||||
c.backendConnectionsInact = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "backend_connections_inactive",
|
||||
Help: "The current inactive connections by local and remote address.",
|
||||
},
|
||||
ipvsBackendLabelNames,
|
||||
)
|
||||
c.backendWeight = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "backend_weight",
|
||||
Help: "The current backend weight by local and remote address.",
|
||||
},
|
||||
ipvsBackendLabelNames,
|
||||
)
|
||||
c.connections = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "connections_total"),
|
||||
"The total number of connections made.",
|
||||
nil, nil,
|
||||
), prometheus.CounterValue}
|
||||
c.incomingPackets = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "incoming_packets_total"),
|
||||
"The total number of incoming packets.",
|
||||
nil, nil,
|
||||
), prometheus.CounterValue}
|
||||
c.outgoingPackets = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "outgoing_packets_total"),
|
||||
"The total number of outgoing packets.",
|
||||
nil, nil,
|
||||
), prometheus.CounterValue}
|
||||
c.incomingBytes = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "incoming_bytes_total"),
|
||||
"The total amount of incoming data.",
|
||||
nil, nil,
|
||||
), prometheus.CounterValue}
|
||||
c.outgoingBytes = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "outgoing_bytes_total"),
|
||||
"The total amount of outgoing data.",
|
||||
nil, nil,
|
||||
), prometheus.CounterValue}
|
||||
c.backendConnectionsActive = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "backend_connections_active"),
|
||||
"The current active connections by local and remote address.",
|
||||
ipvsBackendLabelNames, nil,
|
||||
), prometheus.GaugeValue}
|
||||
c.backendConnectionsInact = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "backend_connections_inactive"),
|
||||
"The current inactive connections by local and remote address.",
|
||||
ipvsBackendLabelNames, nil,
|
||||
), prometheus.GaugeValue}
|
||||
c.backendWeight = typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "backend_weight"),
|
||||
"The current backend weight by local and remote address.",
|
||||
ipvsBackendLabelNames, nil,
|
||||
), prometheus.GaugeValue}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
|
@ -136,18 +108,11 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("could not get IPVS stats: %s", err)
|
||||
}
|
||||
|
||||
c.connections.Set(float64(ipvsStats.Connections))
|
||||
c.incomingPackets.Set(float64(ipvsStats.IncomingPackets))
|
||||
c.outgoingPackets.Set(float64(ipvsStats.OutgoingPackets))
|
||||
c.incomingBytes.Set(float64(ipvsStats.IncomingBytes))
|
||||
c.outgoingBytes.Set(float64(ipvsStats.OutgoingBytes))
|
||||
|
||||
c.connections.Collect(ch)
|
||||
c.incomingPackets.Collect(ch)
|
||||
c.outgoingPackets.Collect(ch)
|
||||
c.incomingBytes.Collect(ch)
|
||||
c.outgoingBytes.Collect(ch)
|
||||
ch <- c.connections.mustNewConstMetric(float64(ipvsStats.Connections))
|
||||
ch <- c.incomingPackets.mustNewConstMetric(float64(ipvsStats.IncomingPackets))
|
||||
ch <- c.outgoingPackets.mustNewConstMetric(float64(ipvsStats.OutgoingPackets))
|
||||
ch <- c.incomingBytes.mustNewConstMetric(float64(ipvsStats.IncomingBytes))
|
||||
ch <- c.outgoingBytes.mustNewConstMetric(float64(ipvsStats.OutgoingBytes))
|
||||
|
||||
backendStats, err := c.fs.NewIPVSBackendStatus()
|
||||
if err != nil {
|
||||
|
|
@ -162,14 +127,9 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
strconv.FormatUint(uint64(backend.RemotePort), 10),
|
||||
backend.Proto,
|
||||
}
|
||||
c.backendConnectionsActive.WithLabelValues(labelValues...).Set(float64(backend.ActiveConn))
|
||||
c.backendConnectionsInact.WithLabelValues(labelValues...).Set(float64(backend.InactConn))
|
||||
c.backendWeight.WithLabelValues(labelValues...).Set(float64(backend.Weight))
|
||||
ch <- c.backendConnectionsActive.mustNewConstMetric(float64(backend.ActiveConn), labelValues...)
|
||||
ch <- c.backendConnectionsInact.mustNewConstMetric(float64(backend.InactConn), labelValues...)
|
||||
ch <- c.backendWeight.mustNewConstMetric(float64(backend.Weight), labelValues...)
|
||||
}
|
||||
|
||||
c.backendConnectionsActive.Collect(ch)
|
||||
c.backendConnectionsInact.Collect(ch)
|
||||
c.backendWeight.Collect(ch)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue