Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added collect Tempfile stat if the service is remote #59

Merged
merged 2 commits into from
Nov 26, 2024
Merged
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
31 changes: 22 additions & 9 deletions internal/collector/postgres_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func (c *postgresStorageCollector) Update(config Config, ch chan<- prometheus.Me

if !config.localService {
// Collect a limited set of Wal metrics
log.Debugln("[postgres storage collector]: collecting limited WAL and Log metrics from remote services")
dirstats, err := newPostgresStat(conn, config.loggingCollector)
log.Debugln("[postgres storage collector]: collecting limited WAL, Log and Temp file metrics from remote services")
dirstats, err := newPostgresStat(conn, config.loggingCollector, config.serverVersionNum)
if err != nil {
return err
}
Expand All @@ -154,6 +154,11 @@ func (c *postgresStorageCollector) Update(config Config, ch chan<- prometheus.Me
ch <- c.logdirFiles.newConstMetric(dirstats.logdirFilesCount, "unknown", "unknown", dirstats.logdirPath)
}

// Temp directory
if config.serverVersionNum >= PostgresV12 {
ch <- c.tmpfilesBytes.newConstMetric(dirstats.tmpfilesSizeBytes, "temp", "temp", "temp")
}

log.Debugln("[postgres storage collector]: skip collecting full directories metrics from remote services")
return nil
}
Expand Down Expand Up @@ -284,7 +289,7 @@ type postgresDirStat struct {
}

// newPostgresStat returns sizes of Postgres server directories.
func newPostgresStat(conn *store.DB, logcollector bool) (*postgresDirStat, error) {
func newPostgresStat(conn *store.DB, logcollector bool, version int) (*postgresDirStat, error) {
// Get Wal properties.
waldirPath, waldirSize, waldirFilesCount, err := getWalStat(conn)
if err != nil {
Expand All @@ -296,14 +301,22 @@ func newPostgresStat(conn *store.DB, logcollector bool) (*postgresDirStat, error
log.Errorln(err)
}

// Get temp files and directories properties.
tmpfilesSize, tmpfilesCount, err := getTempfilesStat(conn, version)
if err != nil {
log.Errorln(err)
}

// Return stats.
return &postgresDirStat{
waldirPath: waldirPath,
waldirSizeBytes: float64(waldirSize),
waldirFilesCount: float64(waldirFilesCount),
logdirPath: logdirPath,
logdirSizeBytes: float64(logdirSize),
logdirFilesCount: float64(logdirFilesCount),
waldirPath: waldirPath,
waldirSizeBytes: float64(waldirSize),
waldirFilesCount: float64(waldirFilesCount),
logdirPath: logdirPath,
logdirSizeBytes: float64(logdirSize),
logdirFilesCount: float64(logdirFilesCount),
tmpfilesSizeBytes: float64(tmpfilesSize),
tmpfilesCount: float64(tmpfilesCount),
}, nil
}

Expand Down