Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add support of filters for all builtin collectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Jun 2, 2021
1 parent f47fdcb commit 02e84b1
Show file tree
Hide file tree
Showing 32 changed files with 170 additions and 141 deletions.
10 changes: 5 additions & 5 deletions internal/collector/linux_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type cpuCollector struct {
}

// NewCPUCollector returns a new Collector exposing kernel/system statistics.
func NewCPUCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewCPUCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
cmdOutput, err := exec.Command("getconf", "CLK_TCK").Output()
if err != nil {
return nil, fmt.Errorf("determine clock frequency failed: %s", err)
Expand All @@ -44,7 +44,7 @@ func NewCPUCollector(constLabels labels, _ model.CollectorSettings) (Collector,
descOpts{"node", "cpu", "seconds_total", "Seconds the CPUs spent in each mode.", 0},
prometheus.CounterValue,
[]string{"mode"}, constLabels,
filter.New(),
subsystems.Filters,
),
cpuAll: newBuiltinTypedDesc(
descOpts{"node", "cpu", "seconds_all_total", "Seconds the CPUs spent in all modes.", 0},
Expand All @@ -56,19 +56,19 @@ func NewCPUCollector(constLabels labels, _ model.CollectorSettings) (Collector,
descOpts{"node", "cpu", "guest_seconds_total", "Seconds the CPUs spent in guests (VMs) for each mode.", 0},
prometheus.CounterValue,
[]string{"mode"}, constLabels,
filter.New(),
subsystems.Filters,
),
uptime: newBuiltinTypedDesc(
descOpts{"node", "uptime", "up_seconds_total", "Total number of seconds the system has been up, accordingly to /proc/uptime.", 0},
prometheus.CounterValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
idletime: newBuiltinTypedDesc(
descOpts{"node", "uptime", "idle_seconds_total", "Total number of seconds all cores have spent idle, accordingly to /proc/uptime.", 0},
prometheus.CounterValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
}
return c, nil
Expand Down
26 changes: 13 additions & 13 deletions internal/collector/linux_diskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,81 +37,81 @@ type diskstatsCollector struct {

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt and https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
func NewDiskstatsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewDiskstatsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
var diskLabelNames = []string{"device", "type"}

return &diskstatsCollector{
completed: newBuiltinTypedDesc(
descOpts{"node", "disk", "completed_total", "The total number of IO requests completed successfully of each type.", 0},
prometheus.CounterValue,
diskLabelNames, constLabels,
filter.New(),
subsystems.Filters,
),
completedAll: newBuiltinTypedDesc(
descOpts{"node", "disk", "completed_all_total", "The total number of IO requests completed successfully.", 0},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
merged: newBuiltinTypedDesc(
descOpts{"node", "disk", "merged_total", "The total number of merged IO requests of each type.", 0},
prometheus.CounterValue,
diskLabelNames, constLabels,
filter.New(),
subsystems.Filters,
),
mergedAll: newBuiltinTypedDesc(
descOpts{"node", "disk", "merged_all_total", "The total number of merged IO requests.", 0},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
bytes: newBuiltinTypedDesc(
descOpts{"node", "disk", "bytes_total", "The total number of bytes processed by IO requests of each type.", diskSectorSize},
prometheus.CounterValue,
diskLabelNames, constLabels,
filter.New(),
subsystems.Filters,
),
bytesAll: newBuiltinTypedDesc(
descOpts{"node", "disk", "bytes_all_total", "The total number of bytes processed by IO requests.", diskSectorSize},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
times: newBuiltinTypedDesc(
descOpts{"node", "disk", "time_seconds_total", "The total number of seconds spent on all requests of each type.", .001},
prometheus.CounterValue,
diskLabelNames, constLabels,
filter.New(),
subsystems.Filters,
),
timesAll: newBuiltinTypedDesc(
descOpts{"node", "disk", "time_seconds_all_total", "The total number of seconds spent on all requests.", .001},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
ionow: newBuiltinTypedDesc(
descOpts{"node", "disk", "io_now", "The number of I/Os currently in progress.", 0},
prometheus.GaugeValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
iotime: newBuiltinTypedDesc(
descOpts{"node", "disk", "io_time_seconds_total", "Total seconds spent doing I/Os.", .001},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
iotimeweighted: newBuiltinTypedDesc(
descOpts{"node", "disk", "io_time_weighted_seconds_total", "The weighted number of seconds spent doing I/Os.", .001},
prometheus.CounterValue,
[]string{"device"}, constLabels,
filter.New(),
subsystems.Filters,
),
storages: newBuiltinTypedDesc(
descOpts{"node", "system", "storage_info", "Labeled information about storage devices present in the system.", 0},
prometheus.GaugeValue,
[]string{"device", "rotational", "scheduler"}, constLabels,
filter.New(),
subsystems.Filters,
),
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/linux_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type filesystemCollector struct {
}

// NewFilesystemCollector returns a new Collector exposing filesystem stats.
func NewFilesystemCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewFilesystemCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &filesystemCollector{
bytes: newBuiltinTypedDesc(
descOpts{"node", "filesystem", "bytes", "Number of bytes of filesystem by usage.", 0},
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/linux_load_average.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type loadaverageCollector struct {
}

// NewLoadAverageCollector returns a new Collector exposing load average statistics.
func NewLoadAverageCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewLoadAverageCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &loadaverageCollector{
load1: newBuiltinTypedDesc(
descOpts{"node", "", "load1", "1m load average.", 0},
Expand Down
24 changes: 13 additions & 11 deletions internal/collector/linux_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@ import (
)

type meminfoCollector struct {
re *regexp.Regexp
constLabels labels
memused typedDesc
swapused typedDesc
re *regexp.Regexp
subsysFilters filter.Filters
constLabels labels
memused typedDesc
swapused typedDesc
}

// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewMeminfoCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &meminfoCollector{
re: regexp.MustCompile(`\((.*)\)`),
constLabels: constLabels,
re: regexp.MustCompile(`\((.*)\)`),
subsysFilters: subsystems.Filters,
constLabels: constLabels,
memused: newBuiltinTypedDesc(
descOpts{"node", "memory", "MemUsed", "Memory information composite field MemUsed.", 0},
prometheus.GaugeValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
swapused: newBuiltinTypedDesc(
descOpts{"node", "memory", "SwapUsed", "Memory information composite field SwapUsed.", 0},
prometheus.GaugeValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
}, nil
}
Expand All @@ -60,7 +62,7 @@ func (c *meminfoCollector) Update(_ Config, ch chan<- prometheus.Metric) error {
descOpts{"node", "memory", param, fmt.Sprintf("Memory information field %s.", param), 0},
prometheus.GaugeValue,
nil, c.constLabels,
filter.New(),
c.subsysFilters,
)

ch <- desc.newConstMetric(value)
Expand All @@ -84,7 +86,7 @@ func (c *meminfoCollector) Update(_ Config, ch chan<- prometheus.Metric) error {

desc := newBuiltinTypedDesc(
descOpts{"node", "vmstat", param, fmt.Sprintf("Vmstat information field %s.", param), 0},
t, nil, c.constLabels, filter.New(),
t, nil, c.constLabels, c.subsysFilters,
)

ch <- desc.newConstMetric(value)
Expand Down
8 changes: 4 additions & 4 deletions internal/collector/linux_netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ type netdevCollector struct {
}

// NewNetdevCollector returns a new Collector exposing network interfaces stats.
func NewNetdevCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewNetdevCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &netdevCollector{
bytes: newBuiltinTypedDesc(
descOpts{"node", "network", "bytes_total", "Total number of bytes processed by network device, by each direction.", 0},
prometheus.CounterValue,
[]string{"device", "type"}, constLabels,
filter.New(),
subsystems.Filters,
),
packets: newBuiltinTypedDesc(
descOpts{"node", "network", "packets_total", "Total number of packets processed by network device, by each direction.", 0},
prometheus.CounterValue,
[]string{"device", "type"}, constLabels,
filter.New(),
subsystems.Filters,
),
events: newBuiltinTypedDesc(
descOpts{"node", "network", "events_total", "Total number of events occurred on network device, by each type and direction.", 0},
prometheus.CounterValue,
[]string{"device", "type", "event"}, constLabels,
filter.New(),
subsystems.Filters,
),
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/linux_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type networkCollector struct {
publicAddresses typedDesc
}

func NewNetworkCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewNetworkCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &networkCollector{
publicAddresses: newBuiltinTypedDesc(
descOpts{"node", "network", "public_addresses", "Number of public network addresses present on the system, by type.", 0},
Expand Down
17 changes: 8 additions & 9 deletions internal/collector/linux_sysconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/weaponry/pgscv/internal/filter"
"github.com/weaponry/pgscv/internal/log"
"github.com/weaponry/pgscv/internal/model"
"io"
Expand All @@ -29,7 +28,7 @@ type systemCollector struct {
}

// NewSystemCollector returns a new Collector exposing system-wide stats.
func NewSysconfigCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewSysconfigCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &systemCollector{
sysctlList: []string{
"kernel.sched_migration_cost_ns",
Expand All @@ -49,43 +48,43 @@ func NewSysconfigCollector(constLabels labels, _ model.CollectorSettings) (Colle
descOpts{"node", "system", "sysctl", "Node sysctl system settings.", 0},
prometheus.GaugeValue,
[]string{"sysctl"}, constLabels,
filter.New(),
subsystems.Filters,
),
cpucores: newBuiltinTypedDesc(
descOpts{"node", "system", "cpu_cores_total", "Total number of CPU cores in each state.", 0},
prometheus.GaugeValue,
[]string{"state"}, constLabels,
filter.New(),
subsystems.Filters,
),
governors: newBuiltinTypedDesc(
descOpts{"node", "system", "scaling_governors_total", "Total number of CPU scaling governors used of each type.", 0},
prometheus.GaugeValue,
[]string{"governor"}, constLabels,
filter.New(),
subsystems.Filters,
),
numanodes: newBuiltinTypedDesc(
descOpts{"node", "system", "numa_nodes_total", "Total number of NUMA nodes in the system.", 0},
prometheus.GaugeValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
ctxt: newBuiltinTypedDesc(
descOpts{"node", "", "context_switches_total", "Total number of context switches.", 0},
prometheus.CounterValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
forks: newBuiltinTypedDesc(
descOpts{"node", "", "forks_total", "Total number of forks.", 0},
prometheus.CounterValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
btime: newBuiltinTypedDesc(
descOpts{"node", "", "boot_time_seconds", "Node boot time, in unixtime.", 0},
prometheus.GaugeValue,
nil, constLabels,
filter.New(),
subsystems.Filters,
),
}, nil
}
Expand Down
9 changes: 4 additions & 5 deletions internal/collector/pgbouncer_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package collector

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/weaponry/pgscv/internal/filter"
"github.com/weaponry/pgscv/internal/log"
"github.com/weaponry/pgscv/internal/model"
"github.com/weaponry/pgscv/internal/store"
Expand All @@ -25,27 +24,27 @@ type pgbouncerPoolsCollector struct {

// NewPgbouncerPoolsCollector returns a new Collector exposing pgbouncer pools connections usage stats.
// For details see https://www.pgbouncer.org/usage.html#show-pools.
func NewPgbouncerPoolsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewPgbouncerPoolsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
var poolsLabelNames = []string{"user", "database", "pool_mode", "state"}

return &pgbouncerPoolsCollector{
conns: newBuiltinTypedDesc(
descOpts{"pgbouncer", "pool", "connections_in_flight", "The total number of connections established by each state.", 0},
prometheus.GaugeValue,
poolsLabelNames, constLabels,
filter.New(),
subsystems.Filters,
),
maxwait: newBuiltinTypedDesc(
descOpts{"pgbouncer", "pool", "max_wait_seconds", "Total time the first (oldest) client in the queue has waited, in seconds.", 0},
prometheus.GaugeValue,
[]string{"user", "database", "pool_mode"}, constLabels,
filter.New(),
subsystems.Filters,
),
clients: newBuiltinTypedDesc(
descOpts{"pgbouncer", "client", "connections_in_flight", "The total number of client connections established by source address.", 0},
prometheus.GaugeValue,
[]string{"user", "database", "address"}, constLabels,
filter.New(),
subsystems.Filters,
),
labelNames: poolsLabelNames,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/pgbouncer_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type pgbouncerSettingsCollector struct {

// NewPgbouncerSettingsCollector returns a new Collector exposing pgbouncer configuration.
// For details see https://www.pgbouncer.org/usage.html#show-config.
func NewPgbouncerSettingsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) {
func NewPgbouncerSettingsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) {
return &pgbouncerSettingsCollector{
settings: newBuiltinTypedDesc(
descOpts{"pgbouncer", "service", "settings_info", "Labeled information about Pgbouncer configuration settings.", 0},
Expand Down
Loading

0 comments on commit 02e84b1

Please sign in to comment.