Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ var (
type arpCollector struct {
fs procfs.FS
deviceFilter deviceFilter
entries *prometheus.Desc
logger *slog.Logger
}

func init() {
registerCollector("arp", defaultEnabled, NewARPCollector)
}

var (
arpEntries = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device",
[]string{"device"}, nil,
)
)

// NewARPCollector returns a new Collector exposing ARP stats.
func NewARPCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
Expand All @@ -53,12 +60,7 @@ func NewARPCollector(logger *slog.Logger) (Collector, error) {
return &arpCollector{
fs: fs,
deviceFilter: newDeviceFilter(*arpDeviceExclude, *arpDeviceInclude),
entries: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device",
[]string{"device"}, nil,
),
logger: logger,
logger: logger,
}, nil
}

Expand Down Expand Up @@ -123,7 +125,7 @@ func (c *arpCollector) Update(ch chan<- prometheus.Metric) error {
continue
}
ch <- prometheus.MustNewConstMetric(
c.entries, prometheus.GaugeValue, float64(entryCount), device)
arpEntries, prometheus.GaugeValue, float64(entryCount), device)
}

return nil
Expand Down
14 changes: 8 additions & 6 deletions collector/buddyinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@ const (

type buddyinfoCollector struct {
fs procfs.FS
desc *prometheus.Desc
logger *slog.Logger
}

func init() {
registerCollector("buddyinfo", defaultDisabled, NewBuddyinfoCollector)
}

// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector(logger *slog.Logger) (Collector, error) {
desc := prometheus.NewDesc(
var (
buddyinfoBlocks = prometheus.NewDesc(
prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"),
"Count of free blocks according to size.",
[]string{"node", "zone", "size"}, nil,
)
)

// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &buddyinfoCollector{fs, desc, logger}, nil
return &buddyinfoCollector{fs, logger}, nil
}

// Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific
Expand All @@ -64,7 +66,7 @@ func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error {
for _, entry := range buddyInfo {
for size, value := range entry.Sizes {
ch <- prometheus.MustNewConstMetric(
c.desc,
buddyinfoBlocks,
prometheus.GaugeValue, value,
entry.Node, entry.Zone, strconv.Itoa(size),
)
Expand Down
35 changes: 18 additions & 17 deletions collector/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,35 @@ import (
const cgroupsCollectorSubsystem = "cgroups"

type cgroupSummaryCollector struct {
fs procfs.FS
cgroups *prometheus.Desc
enabled *prometheus.Desc
logger *slog.Logger
fs procfs.FS
logger *slog.Logger
}

func init() {
registerCollector(cgroupsCollectorSubsystem, defaultDisabled, NewCgroupSummaryCollector)
}

var (
cgroupsCgroups = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "cgroups"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name"}, nil,
)
cgroupsEnabled = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "enabled"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name"}, nil,
)
)

// NewCgroupSummaryCollector returns a new Collector exposing a summary of cgroups.
func NewCgroupSummaryCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &cgroupSummaryCollector{
fs: fs,
cgroups: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "cgroups"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name"}, nil,
),
enabled: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "enabled"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name"}, nil,
),
fs: fs,
logger: logger,
}, nil
}
Expand All @@ -65,8 +66,8 @@ func (c *cgroupSummaryCollector) Update(ch chan<- prometheus.Metric) error {
return err
}
for _, cs := range cgroupSummarys {
ch <- prometheus.MustNewConstMetric(c.cgroups, prometheus.GaugeValue, float64(cs.Cgroups), cs.SubsysName)
ch <- prometheus.MustNewConstMetric(c.enabled, prometheus.GaugeValue, float64(cs.Enabled), cs.SubsysName)
ch <- prometheus.MustNewConstMetric(cgroupsCgroups, prometheus.GaugeValue, float64(cs.Cgroups), cs.SubsysName)
ch <- prometheus.MustNewConstMetric(cgroupsEnabled, prometheus.GaugeValue, float64(cs.Enabled), cs.SubsysName)
}
return nil
}
155 changes: 74 additions & 81 deletions collector/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ import (
)

type conntrackCollector struct {
current *prometheus.Desc
limit *prometheus.Desc
found *prometheus.Desc
invalid *prometheus.Desc
ignore *prometheus.Desc
insert *prometheus.Desc
insertFailed *prometheus.Desc
drop *prometheus.Desc
earlyDrop *prometheus.Desc
searchRestart *prometheus.Desc
logger *slog.Logger
logger *slog.Logger
}

type conntrackStatistics struct {
Expand All @@ -54,59 +44,62 @@ func init() {
registerCollector("conntrack", defaultEnabled, NewConntrackCollector)
}

var (
conntrackCurrent = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
"Number of currently allocated flow entries for connection tracking.",
nil, nil,
)
conntrackLimit = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries_limit"),
"Maximum size of connection tracking table.",
nil, nil,
)
conntrackFound = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_found"),
"Number of searched entries which were successful.",
nil, nil,
)
conntrackInvalid = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_invalid"),
"Number of packets seen which can not be tracked.",
nil, nil,
)
conntrackIgnore = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_ignore"),
"Number of packets seen which are already connected to a conntrack entry.",
nil, nil,
)
conntrackInsert = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_insert"),
"Number of entries inserted into the list.",
nil, nil,
)
conntrackInsertFailed = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_insert_failed"),
"Number of entries for which list insertion was attempted but failed.",
nil, nil,
)
conntrackDrop = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_drop"),
"Number of packets dropped due to conntrack failure.",
nil, nil,
)
conntrackEarlyDrop = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_early_drop"),
"Number of dropped conntrack entries to make room for new ones, if maximum table size was reached.",
nil, nil,
)
conntrackSearchRestart = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_search_restart"),
"Number of conntrack table lookups which had to be restarted due to hashtable resizes.",
nil, nil,
)
)

// NewConntrackCollector returns a new Collector exposing conntrack stats.
func NewConntrackCollector(logger *slog.Logger) (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
"Number of currently allocated flow entries for connection tracking.",
nil, nil,
),
limit: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries_limit"),
"Maximum size of connection tracking table.",
nil, nil,
),
found: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_found"),
"Number of searched entries which were successful.",
nil, nil,
),
invalid: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_invalid"),
"Number of packets seen which can not be tracked.",
nil, nil,
),
ignore: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_ignore"),
"Number of packets seen which are already connected to a conntrack entry.",
nil, nil,
),
insert: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_insert"),
"Number of entries inserted into the list.",
nil, nil,
),
insertFailed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_insert_failed"),
"Number of entries for which list insertion was attempted but failed.",
nil, nil,
),
drop: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_drop"),
"Number of packets dropped due to conntrack failure.",
nil, nil,
),
earlyDrop: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_early_drop"),
"Number of dropped conntrack entries to make room for new ones, if maximum table size was reached.",
nil, nil,
),
searchRestart: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_stat_search_restart"),
"Number of conntrack table lookups which had to be restarted due to hashtable resizes.",
nil, nil,
),
logger: logger,
}, nil
}
Expand All @@ -117,36 +110,36 @@ func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error {
return c.handleErr(err)
}
ch <- prometheus.MustNewConstMetric(
c.current, prometheus.GaugeValue, float64(value))
conntrackCurrent, prometheus.GaugeValue, float64(value))

value, err = readUintFromFile(procFilePath("sys/net/netfilter/nf_conntrack_max"))
if err != nil {
return c.handleErr(err)
}
ch <- prometheus.MustNewConstMetric(
c.limit, prometheus.GaugeValue, float64(value))
conntrackLimit, prometheus.GaugeValue, float64(value))

conntrackStats, err := getConntrackStatistics()
if err != nil {
return c.handleErr(err)
}

ch <- prometheus.MustNewConstMetric(
c.found, prometheus.GaugeValue, float64(conntrackStats.found))
conntrackFound, prometheus.GaugeValue, float64(conntrackStats.found))
ch <- prometheus.MustNewConstMetric(
c.invalid, prometheus.GaugeValue, float64(conntrackStats.invalid))
conntrackInvalid, prometheus.GaugeValue, float64(conntrackStats.invalid))
ch <- prometheus.MustNewConstMetric(
c.ignore, prometheus.GaugeValue, float64(conntrackStats.ignore))
conntrackIgnore, prometheus.GaugeValue, float64(conntrackStats.ignore))
ch <- prometheus.MustNewConstMetric(
c.insert, prometheus.GaugeValue, float64(conntrackStats.insert))
conntrackInsert, prometheus.GaugeValue, float64(conntrackStats.insert))
ch <- prometheus.MustNewConstMetric(
c.insertFailed, prometheus.GaugeValue, float64(conntrackStats.insertFailed))
conntrackInsertFailed, prometheus.GaugeValue, float64(conntrackStats.insertFailed))
ch <- prometheus.MustNewConstMetric(
c.drop, prometheus.GaugeValue, float64(conntrackStats.drop))
conntrackDrop, prometheus.GaugeValue, float64(conntrackStats.drop))
ch <- prometheus.MustNewConstMetric(
c.earlyDrop, prometheus.GaugeValue, float64(conntrackStats.earlyDrop))
conntrackEarlyDrop, prometheus.GaugeValue, float64(conntrackStats.earlyDrop))
ch <- prometheus.MustNewConstMetric(
c.searchRestart, prometheus.GaugeValue, float64(conntrackStats.searchRestart))
conntrackSearchRestart, prometheus.GaugeValue, float64(conntrackStats.searchRestart))
return nil
}

Expand All @@ -159,7 +152,7 @@ func (c *conntrackCollector) handleErr(err error) error {
}

func getConntrackStatistics() (*conntrackStatistics, error) {
c := conntrackStatistics{}
s := conntrackStatistics{}

fs, err := procfs.NewFS(*procPath)
if err != nil {
Expand All @@ -172,15 +165,15 @@ func getConntrackStatistics() (*conntrackStatistics, error) {
}

for _, connStat := range connStats {
c.found += connStat.Found
c.invalid += connStat.Invalid
c.ignore += connStat.Ignore
c.insert += connStat.Insert
c.insertFailed += connStat.InsertFailed
c.drop += connStat.Drop
c.earlyDrop += connStat.EarlyDrop
c.searchRestart += connStat.SearchRestart
s.found += connStat.Found
s.invalid += connStat.Invalid
s.ignore += connStat.Ignore
s.insert += connStat.Insert
s.insertFailed += connStat.InsertFailed
s.drop += connStat.Drop
s.earlyDrop += connStat.EarlyDrop
s.searchRestart += connStat.SearchRestart
}

return &c, nil
return &s, nil
}
Loading
Loading