From 02e84b1a308a3f65dc6da5b2edd4a251d83df013 Mon Sep 17 00:00:00 2001 From: Alexey Lesovsky Date: Wed, 2 Jun 2021 09:08:41 +0500 Subject: [PATCH] Add support of filters for all builtin collectors. --- internal/collector/linux_cpu.go | 10 ++--- internal/collector/linux_diskstats.go | 26 ++++++------- internal/collector/linux_filesystem.go | 2 +- internal/collector/linux_load_average.go | 2 +- internal/collector/linux_memory.go | 24 ++++++------ internal/collector/linux_netdev.go | 8 ++-- internal/collector/linux_network.go | 2 +- internal/collector/linux_sysconfig.go | 17 ++++---- internal/collector/pgbouncer_pools.go | 9 ++--- internal/collector/pgbouncer_settings.go | 2 +- internal/collector/pgbouncer_stats.go | 11 +++--- internal/collector/pgscv_services.go | 5 +-- internal/collector/postgres_activity.go | 2 +- internal/collector/postgres_archiver.go | 11 +++--- internal/collector/postgres_bgwriter.go | 12 +++--- internal/collector/postgres_conflicts.go | 2 +- internal/collector/postgres_database.go | 27 +++++++------ internal/collector/postgres_functions.go | 9 ++--- internal/collector/postgres_indexes.go | 2 +- internal/collector/postgres_locks.go | 9 ++--- internal/collector/postgres_logs.go | 2 +- internal/collector/postgres_replication.go | 15 ++++--- .../collector/postgres_replication_slots.go | 5 +-- internal/collector/postgres_schema.go | 2 +- internal/collector/postgres_settings.go | 7 ++-- internal/collector/postgres_statements.go | 39 +++++++++---------- internal/collector/postgres_storage.go | 2 +- internal/collector/postgres_tables.go | 2 +- internal/model/model.go | 9 +++-- internal/pgscv/config.go | 5 +++ internal/pgscv/config_test.go | 25 ++++++++++++ .../testdata/pgscv-filters-example-v2.yaml | 6 +++ 32 files changed, 170 insertions(+), 141 deletions(-) create mode 100644 internal/pgscv/testdata/pgscv-filters-example-v2.yaml diff --git a/internal/collector/linux_cpu.go b/internal/collector/linux_cpu.go index 8a260a0b..9f448c39 100644 --- a/internal/collector/linux_cpu.go +++ b/internal/collector/linux_cpu.go @@ -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) @@ -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}, @@ -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 diff --git a/internal/collector/linux_diskstats.go b/internal/collector/linux_diskstats.go index e26169a7..97a10d86 100644 --- a/internal/collector/linux_diskstats.go +++ b/internal/collector/linux_diskstats.go @@ -37,7 +37,7 @@ 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{ @@ -45,73 +45,73 @@ func NewDiskstatsCollector(constLabels labels, _ model.CollectorSettings) (Colle 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 } diff --git a/internal/collector/linux_filesystem.go b/internal/collector/linux_filesystem.go index 888d3b1e..6a27385a 100644 --- a/internal/collector/linux_filesystem.go +++ b/internal/collector/linux_filesystem.go @@ -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}, diff --git a/internal/collector/linux_load_average.go b/internal/collector/linux_load_average.go index 93cb609a..b11263ea 100644 --- a/internal/collector/linux_load_average.go +++ b/internal/collector/linux_load_average.go @@ -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}, diff --git a/internal/collector/linux_memory.go b/internal/collector/linux_memory.go index e59105f0..46f44016 100644 --- a/internal/collector/linux_memory.go +++ b/internal/collector/linux_memory.go @@ -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 } @@ -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) @@ -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) diff --git a/internal/collector/linux_netdev.go b/internal/collector/linux_netdev.go index 09e9a7fd..ace3c84a 100644 --- a/internal/collector/linux_netdev.go +++ b/internal/collector/linux_netdev.go @@ -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 } diff --git a/internal/collector/linux_network.go b/internal/collector/linux_network.go index 00bf68ce..90e9cc5c 100644 --- a/internal/collector/linux_network.go +++ b/internal/collector/linux_network.go @@ -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}, diff --git a/internal/collector/linux_sysconfig.go b/internal/collector/linux_sysconfig.go index f5d77ec6..82f69f0c 100644 --- a/internal/collector/linux_sysconfig.go +++ b/internal/collector/linux_sysconfig.go @@ -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" @@ -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", @@ -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 } diff --git a/internal/collector/pgbouncer_pools.go b/internal/collector/pgbouncer_pools.go index 4f72b5a7..9fa26667 100644 --- a/internal/collector/pgbouncer_pools.go +++ b/internal/collector/pgbouncer_pools.go @@ -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" @@ -25,7 +24,7 @@ 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{ @@ -33,19 +32,19 @@ func NewPgbouncerPoolsCollector(constLabels labels, _ model.CollectorSettings) ( 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 diff --git a/internal/collector/pgbouncer_settings.go b/internal/collector/pgbouncer_settings.go index 1e20e263..79129b22 100644 --- a/internal/collector/pgbouncer_settings.go +++ b/internal/collector/pgbouncer_settings.go @@ -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}, diff --git a/internal/collector/pgbouncer_stats.go b/internal/collector/pgbouncer_stats.go index 816c3c4e..bc6016b0 100644 --- a/internal/collector/pgbouncer_stats.go +++ b/internal/collector/pgbouncer_stats.go @@ -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" @@ -21,7 +20,7 @@ type pgbouncerStatsCollector struct { // NewPgbouncerStatsCollector returns a new Collector exposing pgbouncer pools usage stats (except averages). // For details see https://www.pgbouncer.org/usage.html#show-stats. -func NewPgbouncerStatsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPgbouncerStatsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { var pgbouncerLabelNames = []string{"database"} return &pgbouncerStatsCollector{ @@ -30,19 +29,19 @@ func NewPgbouncerStatsCollector(constLabels labels, _ model.CollectorSettings) ( descOpts{"pgbouncer", "", "transactions_total", "Total number of SQL transactions processed, for each database.", 0}, prometheus.CounterValue, pgbouncerLabelNames, constLabels, - filter.New(), + subsystems.Filters, ), queries: newBuiltinTypedDesc( descOpts{"pgbouncer", "", "queries_total", "Total number of SQL queries processed, for each database.", 0}, prometheus.CounterValue, pgbouncerLabelNames, constLabels, - filter.New(), + subsystems.Filters, ), bytes: newBuiltinTypedDesc( descOpts{"pgbouncer", "", "bytes_total", "Total volume of network traffic processed by pgbouncer in each direction, in bytes.", 0}, prometheus.CounterValue, []string{"database", "type"}, constLabels, - filter.New(), + subsystems.Filters, ), time: newBuiltinTypedDesc( descOpts{ @@ -52,7 +51,7 @@ func NewPgbouncerStatsCollector(constLabels labels, _ model.CollectorSettings) ( }, prometheus.CounterValue, []string{"database", "type", "mode"}, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/pgscv_services.go b/internal/collector/pgscv_services.go index 20ffc591..d073bb7e 100644 --- a/internal/collector/pgscv_services.go +++ b/internal/collector/pgscv_services.go @@ -2,7 +2,6 @@ package collector import ( "github.com/prometheus/client_golang/prometheus" - "github.com/weaponry/pgscv/internal/filter" "github.com/weaponry/pgscv/internal/model" ) @@ -12,13 +11,13 @@ type pgscvServicesCollector struct { } // NewPgscvServicesCollector creates new collector. -func NewPgscvServicesCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPgscvServicesCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &pgscvServicesCollector{ service: newBuiltinTypedDesc( descOpts{"pgscv", "services", "registered_total", "Total number of services registered by pgSCV.", 0}, prometheus.GaugeValue, []string{"service"}, constLabels, - filter.New(), + subsystems.Filters, )}, nil } diff --git a/internal/collector/postgres_activity.go b/internal/collector/postgres_activity.go index 8b2cf4f1..3722a9d0 100644 --- a/internal/collector/postgres_activity.go +++ b/internal/collector/postgres_activity.go @@ -70,7 +70,7 @@ type postgresActivityCollector struct { // For details see // 1. https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW // 2. https://www.postgresql.org/docs/current/view-pg-prepared-xacts.html -func NewPostgresActivityCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresActivityCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresActivityCollector{ waitEvents: newBuiltinTypedDesc( descOpts{"postgres", "activity", "wait_events_in_flight", "Number of wait events in-flight in each state.", 0}, diff --git a/internal/collector/postgres_archiver.go b/internal/collector/postgres_archiver.go index b5e1be38..553664f4 100644 --- a/internal/collector/postgres_archiver.go +++ b/internal/collector/postgres_archiver.go @@ -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" @@ -23,31 +22,31 @@ type postgresWalArchivingCollector struct { // NewPostgresWalArchivingCollector returns a new Collector exposing postgres WAL archiving stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ARCHIVER-VIEW -func NewPostgresWalArchivingCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresWalArchivingCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresWalArchivingCollector{ archived: newBuiltinTypedDesc( descOpts{"postgres", "archiver", "archived_total", "Total number of WAL segments had been successfully archived.", 0}, prometheus.CounterValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), failed: newBuiltinTypedDesc( descOpts{"postgres", "archiver", "failed_total", "Total number of attempts when WAL segments had been failed to archive.", 0}, prometheus.CounterValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), sinceArchivedSeconds: newBuiltinTypedDesc( descOpts{"postgres", "archiver", "since_last_archive_seconds", "Number of seconds since last WAL segment had been successfully archived.", 0}, prometheus.GaugeValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), archivingLag: newBuiltinTypedDesc( descOpts{"postgres", "archiver", "lag_bytes", "Amount of WAL segments ready, but not archived, in bytes.", 0}, prometheus.GaugeValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_bgwriter.go b/internal/collector/postgres_bgwriter.go index d842b6f7..cc28e095 100644 --- a/internal/collector/postgres_bgwriter.go +++ b/internal/collector/postgres_bgwriter.go @@ -24,38 +24,38 @@ type postgresBgwriterCollector struct { // NewPostgresBgwriterCollector returns a new Collector exposing postgres bgwriter and checkpointer stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-BGWRITER-VIEW -func NewPostgresBgwriterCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresBgwriterCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresBgwriterCollector{ descs: map[string]typedDesc{ "checkpoints": newBuiltinTypedDesc( descOpts{"postgres", "checkpoints", "total", "Total number of checkpoints that have been performed of each type.", 0}, prometheus.CounterValue, []string{"checkpoint"}, constLabels, - filter.New(), + subsystems.Filters, ), "checkpoints_all": newBuiltinTypedDesc( descOpts{"postgres", "checkpoints", "all_total", "Total number of checkpoints that have been performed.", 0}, prometheus.CounterValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), "checkpoint_time": newBuiltinTypedDesc( descOpts{"postgres", "checkpoints", "seconds_total", "Total amount of time that has been spent processing data during checkpoint in each stage, in seconds.", .001}, prometheus.CounterValue, []string{"stage"}, constLabels, - filter.New(), + subsystems.Filters, ), "checkpoint_time_all": newBuiltinTypedDesc( descOpts{"postgres", "checkpoints", "seconds_all_total", "Total amount of time that has been spent processing data during checkpoint, in seconds.", .001}, prometheus.CounterValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), "written_bytes": newBuiltinTypedDesc( descOpts{"postgres", "written", "bytes_total", "Total number of bytes written by each subsystem, in bytes.", 0}, prometheus.CounterValue, []string{"process"}, constLabels, - filter.New(), + subsystems.Filters, ), "maxwritten_clean": newBuiltinTypedDesc( descOpts{"postgres", "bgwriter", "maxwritten_clean_total", "Total number of times the background writer stopped a cleaning scan because it had written too many buffers.", 0}, diff --git a/internal/collector/postgres_conflicts.go b/internal/collector/postgres_conflicts.go index ee9d4ff0..881fdc6e 100644 --- a/internal/collector/postgres_conflicts.go +++ b/internal/collector/postgres_conflicts.go @@ -19,7 +19,7 @@ type postgresConflictsCollector struct { // NewPostgresConflictsCollector returns a new Collector exposing postgres databases recovery conflicts stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-DATABASE-CONFLICTS-VIEW -func NewPostgresConflictsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresConflictsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresConflictsCollector{ conflicts: newBuiltinTypedDesc( descOpts{"postgres", "recovery", "conflicts_total", "Total number of recovery conflicts occurred by each conflict type.", 0}, diff --git a/internal/collector/postgres_database.go b/internal/collector/postgres_database.go index 22f56e72..3ab13cfe 100644 --- a/internal/collector/postgres_database.go +++ b/internal/collector/postgres_database.go @@ -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" @@ -41,7 +40,7 @@ type postgresDatabasesCollector struct { // NewPostgresDatabasesCollector returns a new Collector exposing postgres databases stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-DATABASE-VIEW -func NewPostgresDatabasesCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresDatabasesCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { var labels = []string{"database"} return &postgresDatabasesCollector{ @@ -50,73 +49,73 @@ func NewPostgresDatabasesCollector(constLabels labels, _ model.CollectorSettings descOpts{"postgres", "database", "xact_commits_total", "Total number of transactions had been committed.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), rollbacks: newBuiltinTypedDesc( descOpts{"postgres", "database", "xact_rollbacks_total", "Total number of transactions had been rolled back.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), conflicts: newBuiltinTypedDesc( descOpts{"postgres", "database", "conflicts_total", "Total number of recovery conflicts occurred.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), deadlocks: newBuiltinTypedDesc( descOpts{"postgres", "database", "deadlocks_total", "Total number of deadlocks occurred.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), blocks: newBuiltinTypedDesc( descOpts{"postgres", "database", "blocks_total", "Total number of disk blocks had been accessed by each type of access.", 0}, prometheus.CounterValue, []string{"database", "access"}, constLabels, - filter.New(), + subsystems.Filters, ), tuples: newBuiltinTypedDesc( descOpts{"postgres", "database", "tuples_total", "Total number of rows processed by each type of operation.", 0}, prometheus.CounterValue, []string{"database", "tuples"}, constLabels, - filter.New(), + subsystems.Filters, ), tempbytes: newBuiltinTypedDesc( descOpts{"postgres", "database", "temp_bytes_total", "Total amount of data written to temporary files by queries.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), tempfiles: newBuiltinTypedDesc( descOpts{"postgres", "database", "temp_files_total", "Total number of temporary files created by queries.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), blockstime: newBuiltinTypedDesc( descOpts{"postgres", "database", "blk_time_seconds_total", "Total time spent accessing data blocks by backends in this database in each access type, in seconds.", .001}, prometheus.CounterValue, []string{"database", "type"}, constLabels, - filter.New(), + subsystems.Filters, ), sizes: newBuiltinTypedDesc( descOpts{"postgres", "database", "size_bytes", "Total size of the database, in bytes.", 0}, prometheus.GaugeValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), statsage: newBuiltinTypedDesc( descOpts{"postgres", "database", "stats_age_seconds_total", "The age of the databases activity statistics, in seconds.", 0}, prometheus.CounterValue, labels, constLabels, - filter.New(), + subsystems.Filters, ), xidlimit: newBuiltinTypedDesc( descOpts{"postgres", "xacts", "left_before_wraparound", "The number of transactions left before force shutdown due to XID wraparound.", 0}, prometheus.CounterValue, []string{"xid_from"}, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_functions.go b/internal/collector/postgres_functions.go index 644debdd..80fe3a7c 100644 --- a/internal/collector/postgres_functions.go +++ b/internal/collector/postgres_functions.go @@ -3,7 +3,6 @@ package collector import ( "github.com/jackc/pgx/v4" "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" @@ -22,7 +21,7 @@ type postgresFunctionsCollector struct { // NewPostgresFunctionsCollector returns a new Collector exposing postgres SQL functions stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-USER-FUNCTIONS-VIEW -func NewPostgresFunctionsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresFunctionsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { var labelNames = []string{"database", "schema", "function"} return &postgresFunctionsCollector{ @@ -31,19 +30,19 @@ func NewPostgresFunctionsCollector(constLabels labels, _ model.CollectorSettings descOpts{"postgres", "function", "calls_total", "Total number of times functions had been called.", 0}, prometheus.CounterValue, labelNames, constLabels, - filter.New(), + subsystems.Filters, ), totaltime: newBuiltinTypedDesc( descOpts{"postgres", "function", "total_time_seconds_total", "Total time spent in function and all other functions called by it, in seconds.", .001}, prometheus.CounterValue, labelNames, constLabels, - filter.New(), + subsystems.Filters, ), selftime: newBuiltinTypedDesc( descOpts{"postgres", "function", "self_time_seconds_total", "Total time spent in function itself, not including other functions called by it, in seconds.", .001}, prometheus.CounterValue, labelNames, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_indexes.go b/internal/collector/postgres_indexes.go index 4634c02b..0a3bcf29 100644 --- a/internal/collector/postgres_indexes.go +++ b/internal/collector/postgres_indexes.go @@ -32,7 +32,7 @@ type postgresIndexesCollector struct { // For details see // https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ALL-INDEXES-VIEW // https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STATIO-ALL-INDEXES-VIEW -func NewPostgresIndexesCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresIndexesCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresIndexesCollector{ indexes: newBuiltinTypedDesc( descOpts{"postgres", "index", "scans_total", "Total number of index scans initiated.", 0}, diff --git a/internal/collector/postgres_locks.go b/internal/collector/postgres_locks.go index c3b38393..a95e0d1d 100644 --- a/internal/collector/postgres_locks.go +++ b/internal/collector/postgres_locks.go @@ -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" @@ -32,25 +31,25 @@ type postgresLocksCollector struct { } // NewPostgresLocksCollector creates new postgresLocksCollector. -func NewPostgresLocksCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresLocksCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresLocksCollector{ locks: newBuiltinTypedDesc( descOpts{"postgres", "locks", "in_flight", "Number of in-flight locks held by active processes in each mode.", 0}, prometheus.GaugeValue, []string{"mode"}, constLabels, - filter.New(), + subsystems.Filters, ), locksAll: newBuiltinTypedDesc( descOpts{"postgres", "locks", "all_in_flight", "Total number of all in-flight locks held by active processes.", 0}, prometheus.GaugeValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), notgranted: newBuiltinTypedDesc( descOpts{"postgres", "locks", "not_granted_in_flight", "Number of in-flight not granted locks held by active processes.", 0}, prometheus.GaugeValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_logs.go b/internal/collector/postgres_logs.go index d6f242fa..f09f1324 100644 --- a/internal/collector/postgres_logs.go +++ b/internal/collector/postgres_logs.go @@ -39,7 +39,7 @@ type postgresLogsCollector struct { } // NewPostgresLogsCollector creates new collector for Postgres log messages. -func NewPostgresLogsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresLogsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { collector := &postgresLogsCollector{ updateLogfile: make(chan string), totals: syncKV{ diff --git a/internal/collector/postgres_replication.go b/internal/collector/postgres_replication.go index 57befcef..08d4df70 100644 --- a/internal/collector/postgres_replication.go +++ b/internal/collector/postgres_replication.go @@ -3,7 +3,6 @@ package collector import ( "context" "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" @@ -53,7 +52,7 @@ type postgresReplicationCollector struct { // NewPostgresReplicationCollector returns a new Collector exposing postgres replication stats. // For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-REPLICATION-VIEW -func NewPostgresReplicationCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresReplicationCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { var labelNames = []string{"client_addr", "user", "application_name", "state", "lag"} return &postgresReplicationCollector{ @@ -62,37 +61,37 @@ func NewPostgresReplicationCollector(constLabels labels, _ model.CollectorSettin descOpts{"postgres", "recovery", "info", "Current recovery state, 0 - not in recovery; 1 - in recovery.", 0}, prometheus.GaugeValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), wal: newBuiltinTypedDesc( descOpts{"postgres", "wal", "written_bytes_total", "Total amount of WAL written (or received in case of standby), in bytes.", 0}, prometheus.CounterValue, nil, constLabels, - filter.New(), + subsystems.Filters, ), lagbytes: newBuiltinTypedDesc( descOpts{"postgres", "replication", "lag_bytes", "Number of bytes standby is behind than primary in each WAL processing phase.", 0}, prometheus.GaugeValue, labelNames, constLabels, - filter.New(), + subsystems.Filters, ), lagseconds: newBuiltinTypedDesc( descOpts{"postgres", "replication", "lag_seconds", "Number of seconds standby is behind than primary in each WAL processing phase.", 0}, prometheus.GaugeValue, labelNames, constLabels, - filter.New(), + subsystems.Filters, ), lagtotalbytes: newBuiltinTypedDesc( descOpts{"postgres", "replication", "lag_all_bytes", "Number of bytes standby is behind than primary including all phases.", 0}, prometheus.GaugeValue, []string{"client_addr", "user", "application_name", "state"}, constLabels, - filter.New(), + subsystems.Filters, ), lagtotalseconds: newBuiltinTypedDesc( descOpts{"postgres", "replication", "lag_all_seconds", "Number of seconds standby is behind than primary including all phases.", 0}, prometheus.GaugeValue, []string{"client_addr", "user", "application_name", "state"}, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_replication_slots.go b/internal/collector/postgres_replication_slots.go index 3505c133..2a95577c 100644 --- a/internal/collector/postgres_replication_slots.go +++ b/internal/collector/postgres_replication_slots.go @@ -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" @@ -25,13 +24,13 @@ type postgresReplicationSlotCollector struct { // NewPostgresReplicationSlotsCollector returns a new Collector exposing postgres replication slots stats. // For details see https://www.postgresql.org/docs/current/view-pg-replication-slots.html -func NewPostgresReplicationSlotsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresReplicationSlotsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresReplicationSlotCollector{ restart: newBuiltinTypedDesc( descOpts{"postgres", "replication_slot", "wal_retain_bytes", "Number of WAL retained and required by consumers, in bytes.", 0}, prometheus.GaugeValue, []string{"database", "slot_name", "slot_type", "active"}, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_schema.go b/internal/collector/postgres_schema.go index 19f52724..4f8412e8 100644 --- a/internal/collector/postgres_schema.go +++ b/internal/collector/postgres_schema.go @@ -24,7 +24,7 @@ type postgresSchemaCollector struct { // NewPostgresSchemaCollector returns a new Collector exposing postgres schema stats. Stats are based on different // sources inside system catalog. -func NewPostgresSchemasCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresSchemasCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresSchemaCollector{ syscatalog: newBuiltinTypedDesc( descOpts{"postgres", "schema", "system_catalog_bytes", "Number of bytes occupied by system catalog.", 0}, diff --git a/internal/collector/postgres_settings.go b/internal/collector/postgres_settings.go index d53fcc53..f0a674bc 100644 --- a/internal/collector/postgres_settings.go +++ b/internal/collector/postgres_settings.go @@ -3,7 +3,6 @@ package collector import ( "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" "github.com/weaponry/pgscv/internal/store" @@ -22,19 +21,19 @@ type postgresSettingsCollector struct { // NewPostgresSettingsCollector returns a new Collector exposing postgres settings stats. // For details see https://www.postgresql.org/docs/current/view-pg-settings.html // and https://www.postgresql.org/docs/current/view-pg-file-settings.html -func NewPostgresSettingsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresSettingsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresSettingsCollector{ settings: newBuiltinTypedDesc( descOpts{"postgres", "service", "settings_info", "Labeled information about Postgres configuration settings.", 0}, prometheus.GaugeValue, []string{"name", "setting", "unit", "vartype", "source"}, constLabels, - filter.New(), + subsystems.Filters, ), files: newBuiltinTypedDesc( descOpts{"postgres", "service", "files_info", "Labeled information about Postgres system files.", 0}, prometheus.GaugeValue, []string{"guc", "mode", "path"}, constLabels, - filter.New(), + subsystems.Filters, ), }, nil } diff --git a/internal/collector/postgres_statements.go b/internal/collector/postgres_statements.go index ff0b8cf3..d50a1f23 100644 --- a/internal/collector/postgres_statements.go +++ b/internal/collector/postgres_statements.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/jackc/pgx/v4" "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" @@ -63,115 +62,115 @@ type postgresStatementsCollector struct { // NewPostgresStatementsCollector returns a new Collector exposing postgres statements stats. // For details see https://www.postgresql.org/docs/current/pgstatstatements.html -func NewPostgresStatementsCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresStatementsCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresStatementsCollector{ query: newBuiltinTypedDesc( descOpts{"postgres", "statements", "query_info", "Labeled info about statements has been executed.", 0}, prometheus.GaugeValue, []string{"user", "database", "md5", "query"}, constLabels, - filter.New(), + subsystems.Filters, ), calls: newBuiltinTypedDesc( descOpts{"postgres", "statements", "calls_total", "Total number of times statement has been executed.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), rows: newBuiltinTypedDesc( descOpts{"postgres", "statements", "rows_total", "Total number of rows retrieved or affected by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), times: newBuiltinTypedDesc( descOpts{"postgres", "statements", "time_seconds_total", "Time spent by the statement in each mode, in seconds.", .001}, prometheus.CounterValue, []string{"user", "database", "md5", "mode"}, constLabels, - filter.New(), + subsystems.Filters, ), allTimes: newBuiltinTypedDesc( descOpts{"postgres", "statements", "time_seconds_all_total", "Total time spent by the statement, in seconds.", .001}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), sharedHit: newBuiltinTypedDesc( descOpts{"postgres", "statements", "shared_hit_bytes_total", "Total number of bytes found in shared buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), sharedRead: newBuiltinTypedDesc( descOpts{"postgres", "statements", "shared_read_bytes_total", "Total number of bytes read from disk or OS page cache when reading from shared buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), sharedDirtied: newBuiltinTypedDesc( descOpts{"postgres", "statements", "shared_dirtied_bytes_total", "Total number of bytes dirtied in shared buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), sharedWritten: newBuiltinTypedDesc( descOpts{"postgres", "statements", "shared_written_bytes_total", "Total number of bytes written to shared buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), localHit: newBuiltinTypedDesc( descOpts{"postgres", "statements", "local_hit_bytes_total", "Total number of bytes found in local buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), localRead: newBuiltinTypedDesc( descOpts{"postgres", "statements", "local_read_bytes_total", "Total number of bytes read from disk or OS page cache when reading from local buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), localDirtied: newBuiltinTypedDesc( descOpts{"postgres", "statements", "local_dirtied_bytes_total", "Total number of bytes dirtied in local buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), localWritten: newBuiltinTypedDesc( descOpts{"postgres", "statements", "local_written_bytes_total", "Total number of bytes written to local buffers by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), tempRead: newBuiltinTypedDesc( descOpts{"postgres", "statements", "temp_read_bytes_total", "Total number of bytes read from temporary files by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), tempWritten: newBuiltinTypedDesc( descOpts{"postgres", "statements", "temp_written_bytes_total", "Total number of bytes written to temporary files by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), walRecords: newBuiltinTypedDesc( descOpts{"postgres", "statements", "wal_records_total", "Total number of WAL records generated by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), walFPI: newBuiltinTypedDesc( descOpts{"postgres", "statements", "wal_fpi_bytes_total", "Total number of WAL full-page images generated by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), walBytes: newBuiltinTypedDesc( descOpts{"postgres", "statements", "wal_bytes_total", "Total number of WAL bytes (not including FPI) generated by the statement.", 0}, prometheus.CounterValue, []string{"user", "database", "md5"}, constLabels, - filter.New(), + subsystems.Filters, ), chain: newNormalizationChain(), }, nil diff --git a/internal/collector/postgres_storage.go b/internal/collector/postgres_storage.go index 48e9375c..82268ff2 100644 --- a/internal/collector/postgres_storage.go +++ b/internal/collector/postgres_storage.go @@ -36,7 +36,7 @@ type postgresStorageCollector struct { // NewPostgresStorageCollector returns a new Collector exposing various stats related to Postgres storage layer. // This stats observed using different stats sources. -func NewPostgresStorageCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresStorageCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { return &postgresStorageCollector{ tempFiles: newBuiltinTypedDesc( descOpts{"postgres", "temp_files", "in_flight", "Number of temporary files processed in flight.", 0}, diff --git a/internal/collector/postgres_tables.go b/internal/collector/postgres_tables.go index cb16e21e..734d7572 100644 --- a/internal/collector/postgres_tables.go +++ b/internal/collector/postgres_tables.go @@ -47,7 +47,7 @@ type postgresTablesCollector struct { // For details see // https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ALL-TABLES-VIEW // https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STATIO-ALL-TABLES-VIEW -func NewPostgresTablesCollector(constLabels labels, _ model.CollectorSettings) (Collector, error) { +func NewPostgresTablesCollector(constLabels labels, subsystems model.CollectorSettings) (Collector, error) { var labels = []string{"database", "schema", "table"} return &postgresTablesCollector{ diff --git a/internal/model/model.go b/internal/model/model.go index d15c0cfb..a2cfae53 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -3,6 +3,7 @@ package model import ( "database/sql" "github.com/jackc/pgproto3/v2" + "github.com/weaponry/pgscv/internal/filter" "regexp" ) @@ -29,7 +30,9 @@ type PGResult struct { // // collectors: <- Collectors (root level in YAML) // postgres/archiver: <- CollectorSettings -// echo: "example" <- CollectorSettings.Echo (example) +// filters: <- CollectorSettings.Filters +// query: <- label +// exclude: "(UPDATE|DELETE)" <- exclude metrics with labels contains these values // subsystems: <- Subsystems // activity: <- MetricsSubsystem // databases: "^db(1|2)$" <- MetricsSubsystem.Databases @@ -51,8 +54,8 @@ type CollectorsSettings map[string]CollectorSettings // CollectorSettings unions all settings related to a single collector. type CollectorSettings struct { - // - //Filters filter.Filters `yaml:"filters"` + // Filters defines label-based filters applied to metrics. + Filters filter.Filters `yaml:"filters"` // Subsystems defines subsystem with user-defined metrics. Subsystems Subsystems `yaml:"subsystems"` } diff --git a/internal/pgscv/config.go b/internal/pgscv/config.go index 649297a8..d8873779 100644 --- a/internal/pgscv/config.go +++ b/internal/pgscv/config.go @@ -170,6 +170,11 @@ func validateCollectorSettings(cs model.CollectorsSettings) error { return fmt.Errorf("invalid collector name: %s", csName) } + err := settings.Filters.Compile() + if err != nil { + return err + } + // Validate subsystems level for ssName, subsys := range settings.Subsystems { re2 := regexp.MustCompilePOSIX(`^[a-zA-Z0-9_]+$`) diff --git a/internal/pgscv/config_test.go b/internal/pgscv/config_test.go index b56be2f8..3f346761 100644 --- a/internal/pgscv/config_test.go +++ b/internal/pgscv/config_test.go @@ -72,6 +72,22 @@ func TestNewConfig(t *testing.T) { }, }, }, + { + name: "valid: with filters V2", + valid: true, + file: "testdata/pgscv-filters-example-v2.yaml", + want: &Config{ + ListenAddress: "127.0.0.1:8080", + Defaults: map[string]string{}, + CollectorsSettings: model.CollectorsSettings{ + "postgres/custom": { + Filters: filter.Filters{ + "device": {Exclude: "^(test|example)$"}, + }, + }, + }, + }, + }, { name: "valid: with collectors settings", valid: true, @@ -265,6 +281,15 @@ func Test_validateCollectorSettings(t *testing.T) { "example/example": {Subsystems: map[string]model.MetricsSubsystem{"inva:lid": {}}}, }, }, + { + valid: false, // Invalid filters specified + settings: map[string]model.CollectorSettings{ + "example/example": { + Filters: filter.Filters{"test": filter.Filter{Exclude: "["}}, + Subsystems: map[string]model.MetricsSubsystem{"example": {}}, + }, + }, + }, { valid: false, // No query specified when metric exists settings: map[string]model.CollectorSettings{ diff --git a/internal/pgscv/testdata/pgscv-filters-example-v2.yaml b/internal/pgscv/testdata/pgscv-filters-example-v2.yaml new file mode 100644 index 00000000..afa5c8fc --- /dev/null +++ b/internal/pgscv/testdata/pgscv-filters-example-v2.yaml @@ -0,0 +1,6 @@ +listen_address: "127.0.0.1:8080" +collectors: + postgres/custom: + filters: + device: + exclude: "^(test|example)$" \ No newline at end of file