Skip to content

Commit

Permalink
Update collector/netstat_freebsd.go to keep the naming convention
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Kochie <[email protected]>
Signed-off-by: K Rin <[email protected]>
  • Loading branch information
Rin0913 and SuperQ committed Dec 27, 2024
1 parent 93cd34a commit 955e44a
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions collector/netstat_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ import (
*/
import "C"

var metricDescs = []*prometheus.Desc{
prometheus.NewDesc(
"tcp_send_packet_total",
"tcp_send_packet_total",
var (
bsdNetstatTcpSendPacketsTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "netstat", "tcp_transmit_packets_total"),
"TCP packets sent",
nil, nil,
),
prometheus.NewDesc(
"tcp_recv_packet_total",
"tcp_recv_packet_total",
)

bsdNetstatTcpRecvPacketsTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "netstat", "tcp_receive_packets_total"),
"TCP packets received",
nil, nil,
),
}
)
)

type netStatCollector struct {
netStatMetric *prometheus.Desc
Expand Down Expand Up @@ -84,25 +85,24 @@ func getData(queryString string) ([]byte, error) {

func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error {

var result []float64

tcpData, err := getData("net.inet.tcp.stats")
if err != nil {
return err
}

tcpStats := *(*C.struct_tcpstat)(unsafe.Pointer(&tcpData[0]))

result = append(result, float64(tcpStats.tcps_sndtotal))
result = append(result, float64(tcpStats.tcps_rcvtotal))

for index, value := range metricDescs {
ch <- prometheus.MustNewConstMetric(
value,
prometheus.UntypedValue,
result[index],
)
}
ch <- prometheus.MustNewConstMetric(
bsdNetstatTcpSendPacketsTotal,
prometheus.CounterValue,
float64(tcpStats.tcps_sndtotal),
)

ch <- prometheus.MustNewConstMetric(
bsdNetstatTcpRecvPacketsTotal,
prometheus.CounterValue,
float64(tcpStats.tcps_rcvtotal),
)

return nil
}

0 comments on commit 955e44a

Please sign in to comment.