diff --git a/agent/jobmanager.go b/agent/jobmanager.go index 94fac136c..80be003a5 100644 --- a/agent/jobmanager.go +++ b/agent/jobmanager.go @@ -9,10 +9,10 @@ package agent import ( "errors" "io" - "os" + "os/exec" "strconv" + "strings" "sync" - "syscall" "time" "github.com/apex/log" @@ -120,12 +120,21 @@ func (mgr *JobManager) CleanupJob(job *model.Job) { } func (mgr *JobManager) updateOnlineTime(src string) { - fi, err := os.Stat(src) + cmd := exec.Command("stat", src, "-c", "%W") + var out strings.Builder + cmd.Stdout = &out + err := cmd.Run() if err != nil { + log.WithField("statSrcFile", src).WithError(err).Error("unable to run stat against original dir") return } - stat := fi.Sys().(*syscall.Stat_t) - mgr.node.OnlineTime = time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)) + secondsSinceEpochStr := strings.TrimSpace(out.String()) + secondsSinceEpoch, parseerr := strconv.ParseInt(secondsSinceEpochStr, 10, 64) + if parseerr != nil { + log.WithField("statOutput", secondsSinceEpochStr).WithError(parseerr).Error("unable to convert stat output to number") + return + } + mgr.node.OnlineTime = time.Unix(int64(secondsSinceEpoch), 0) log.WithField("onlineTime", mgr.node.OnlineTime).Info("Updated online time (node installation time)") } diff --git a/server/modules/influxdb/influxdbmetrics.go b/server/modules/influxdb/influxdbmetrics.go index 74192adb2..919acb975 100644 --- a/server/modules/influxdb/influxdbmetrics.go +++ b/server/modules/influxdb/influxdbmetrics.go @@ -151,6 +151,10 @@ func (metrics *InfluxDBMetrics) fetchLatestValuesByHostDirect(filter string, val } else { values[hostname] = result.Record().ValueByKey(valueField) } + log.WithFields(log.Fields{ + "hostname": hostname, + "value": values[hostname], + }).Debug("Got value from InflubDB for host") } else { log.Warn("Host key is not of the expected type 'string'") } @@ -316,7 +320,7 @@ func (metrics *InfluxDBMetrics) updateOsStatus() { metrics.swapTotalGB = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("swap", "total", "", ""), bytesToGB) metrics.swapUsedPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("swap", "used_percent", "", ""), identity) metrics.pcapDays = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("pcapage", "seconds", "", ""), secondsToDays) - metrics.stenoLossPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("stenodrop", "drop", "", ""), toPercent) + metrics.stenoLossPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("stenodrop", "drop", "", ""), identity) metrics.suriLossPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("suridrop", "drop", "", ""), toPercent) metrics.zeekLossPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("zeekdrop", "drop", "", ""), toPercent) metrics.captureLossPct = metrics.convertValuesToFloat64(metrics.fetchLatestValuesByHost("zeekcaptureloss", "loss", "", ""), identity)