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

Commit

Permalink
Split single 'tuples_total' metric to separate metrics. (#43)
Browse files Browse the repository at this point in the history
* Split single 'tuples_total' metric to separate metrics.
* Add extra memory metrics to test (with debug).
  • Loading branch information
lesovsky authored Aug 5, 2022
1 parent c833132 commit 3650072
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
13 changes: 12 additions & 1 deletion internal/collector/linux_memory_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package collector

import (
"fmt"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)

func TestMeminfoCollector_Update(t *testing.T) {
meminfo, err := os.ReadFile("/proc/meminfo")
assert.NoError(t, err)
fmt.Println(string(meminfo))

vmstat, err := os.ReadFile("/proc/vmstat")
assert.NoError(t, err)
fmt.Println(string(vmstat))

var input = pipelineInput{
required: []string{
"node_memory_MemTotal", "node_memory_MemFree", "node_memory_MemAvailable", "node_memory_MemUsed",
Expand All @@ -32,6 +41,7 @@ func TestMeminfoCollector_Update(t *testing.T) {
"node_memory_WritebackTmp", "node_memory_NFS_Unstable", "node_memory_DirectMap2M", "node_memory_Hugetlb",
"node_memory_CmaTotal", "node_memory_Mlocked", "node_memory_ShmemPmdMapped", "node_memory_SUnreclaim",
"node_memory_KernelStack", "node_memory_VmallocChunk", "node_memory_Percpu", "node_memory_HardwareCorrupted",
"node_memory_CmaFree", "node_memory_CmaTotal",
// vmstat
"node_vmstat_nr_free_pages", "node_vmstat_nr_zone_inactive_anon", "node_vmstat_nr_zone_active_anon",
"node_vmstat_nr_zone_inactive_file", "node_vmstat_nr_zone_active_file", "node_vmstat_nr_zone_unevictable",
Expand Down Expand Up @@ -83,7 +93,8 @@ func TestMeminfoCollector_Update(t *testing.T) {
"node_vmstat_pgsteal_anon", "node_vmstat_pgsteal_file", "node_vmstat_pgscan_file", "node_vmstat_pgscan_anon",
"node_vmstat_thp_file_fallback_charge", "node_vmstat_nr_foll_pin_released", "node_vmstat_thp_file_fallback",
"node_vmstat_thp_fault_fallback_charge", "node_vmstat_nr_swapcached", "node_vmstat_direct_map_level2_splits",
"node_vmstat_direct_map_level3_splits",
"node_vmstat_direct_map_level3_splits", "node_vmstat_workingset_refault", "node_vmstat_workingset_activate",
"node_vmstat_workingset_restore", "node_vmstat_pgdemote_kswapd", "node_vmstat_pgdemote_direct",
},
collector: NewMeminfoCollector,
}
Expand Down
46 changes: 37 additions & 9 deletions internal/collector/postgres_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ type postgresDatabasesCollector struct {
commits typedDesc
rollbacks typedDesc
blocks typedDesc
tuples typedDesc
tuplesReturned typedDesc
tuplesFetched typedDesc
tuplesInserted typedDesc
tuplesUpdated typedDesc
tuplesDeleted typedDesc
tempbytes typedDesc
tempfiles typedDesc
conflicts typedDesc
Expand Down Expand Up @@ -89,10 +93,34 @@ func NewPostgresDatabasesCollector(constLabels labels, settings model.CollectorS
[]string{"database", "access"}, constLabels,
settings.Filters,
),
tuples: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_total", "Total number of rows processed by each type of operation.", 0},
tuplesReturned: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_returned_total", "Total number of rows returned per each database.", 0},
prometheus.CounterValue,
[]string{"database", "tuples"}, constLabels,
[]string{"database"}, constLabels,
settings.Filters,
),
tuplesFetched: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_fetched_total", "Total number of rows fetched per each database.", 0},
prometheus.CounterValue,
[]string{"database"}, constLabels,
settings.Filters,
),
tuplesInserted: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_inserted_total", "Total number of rows inserted per each database.", 0},
prometheus.CounterValue,
[]string{"database"}, constLabels,
settings.Filters,
),
tuplesUpdated: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_updated_total", "Total number of rows updated per each database.", 0},
prometheus.CounterValue,
[]string{"database"}, constLabels,
settings.Filters,
),
tuplesDeleted: newBuiltinTypedDesc(
descOpts{"postgres", "database", "tuples_deleted_total", "Total number of rows deleted per each database.", 0},
prometheus.CounterValue,
[]string{"database"}, constLabels,
settings.Filters,
),
tempbytes: newBuiltinTypedDesc(
Expand Down Expand Up @@ -209,11 +237,11 @@ func (c *postgresDatabasesCollector) Update(config Config, ch chan<- prometheus.
ch <- c.rollbacks.newConstMetric(stat.xactrollback, stat.database)
ch <- c.blocks.newConstMetric(stat.blksread, stat.database, "read")
ch <- c.blocks.newConstMetric(stat.blkshit, stat.database, "hit")
ch <- c.tuples.newConstMetric(stat.tupreturned, stat.database, "returned")
ch <- c.tuples.newConstMetric(stat.tupfetched, stat.database, "fetched")
ch <- c.tuples.newConstMetric(stat.tupinserted, stat.database, "inserted")
ch <- c.tuples.newConstMetric(stat.tupupdated, stat.database, "updated")
ch <- c.tuples.newConstMetric(stat.tupdeleted, stat.database, "deleted")
ch <- c.tuplesReturned.newConstMetric(stat.tupreturned, stat.database)
ch <- c.tuplesFetched.newConstMetric(stat.tupfetched, stat.database)
ch <- c.tuplesInserted.newConstMetric(stat.tupinserted, stat.database)
ch <- c.tuplesUpdated.newConstMetric(stat.tupupdated, stat.database)
ch <- c.tuplesDeleted.newConstMetric(stat.tupdeleted, stat.database)

ch <- c.tempbytes.newConstMetric(stat.tempbytes, stat.database)
ch <- c.tempfiles.newConstMetric(stat.tempfiles, stat.database)
Expand Down
10 changes: 5 additions & 5 deletions internal/collector/postgres_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ func TestPostgresDatabasesCollector_Update(t *testing.T) {
"postgres_database_xact_commits_total",
"postgres_database_xact_rollbacks_total",
"postgres_database_blocks_total",
"postgres_database_tuples_total",
"postgres_database_tuples_returned_total",
"postgres_database_tuples_fetched_total",
"postgres_database_tuples_inserted_total",
"postgres_database_tuples_updated_total",
"postgres_database_tuples_deleted_total",
"postgres_database_temp_bytes_total",
"postgres_database_temp_files_total",
"postgres_database_conflicts_total",
Expand All @@ -25,10 +29,6 @@ func TestPostgresDatabasesCollector_Update(t *testing.T) {
"postgres_database_size_bytes",
"postgres_database_stats_age_seconds_total",
"postgres_xacts_left_before_wraparound",
},
// TODO: wait until Postgres 14 has been released, update Postgres version on pgscv-testing docker image
// and move these metrics to 'required' slice.
optional: []string{
"postgres_database_session_time_seconds_all_total",
"postgres_database_session_time_seconds_total",
"postgres_database_sessions_all_total",
Expand Down

0 comments on commit 3650072

Please sign in to comment.