Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 36371aa

Browse files
committed
Gatherer: don't require a Config DB connection in "ad-hoc" mode
1 parent cbe0baf commit 36371aa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pgwatch2/pgwatch2.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,13 @@ func SyncMonitoredDBsToDatastore(monitored_dbs []MonitoredDatabase, persistence_
42084208
}
42094209
}
42104210

4211+
func CheckFolderExistAndReadable(path string) bool {
4212+
if _, err := ioutil.ReadDir(path); err != nil {
4213+
return false
4214+
}
4215+
return true
4216+
}
4217+
42114218
type Options struct {
42124219
// Slice of bool will append 'true' each time the option
42134220
// is encountered (can be set multiple times, like -vvv)
@@ -4428,7 +4435,11 @@ func main() {
44284435
}
44294436

44304437
fileBased = true
4431-
} else if !adHocMode {
4438+
} else if adHocMode && (len(opts.MetricsFolder) == 0 && CheckFolderExistAndReadable("/etc/pgwatch2/metrics")) {
4439+
// don't need the Config DB connection actually for ad-hoc mode if metric definitions are there
4440+
opts.MetricsFolder = "/etc/pgwatch2/metrics" // prebuilt packages / Docker default location
4441+
log.Infof("--metrics-folder path not specified, using %s", opts.MetricsFolder)
4442+
} else { // normal "Config DB" mode
44324443
// make sure all PG params are there
44334444
if opts.User == "" {
44344445
opts.User = os.Getenv("USER")

0 commit comments

Comments
 (0)