diff --git a/cmd/poller/collector/asup.go b/cmd/poller/collector/asup.go index 74df2cebf..7d8778760 100644 --- a/cmd/poller/collector/asup.go +++ b/cmd/poller/collector/asup.go @@ -92,6 +92,10 @@ type harvestInfo struct { NumPollers uint64 NumExporters uint64 NumPortRange uint64 + Pid int + RssBytes uint64 + MaxRssBytes uint64 + EpochMilli int64 // milliseconds since the epoch, in UTC } type Counters struct { @@ -127,14 +131,14 @@ func (p *Payload) AddCollectorAsup(a AsupCollector) { *p.Collectors = append(*p.Collectors, a) } -func SendAutosupport(collectors []Collector, status *matrix.Matrix, pollerName string) error { +func SendAutosupport(collectors []Collector, status *matrix.Matrix, pollerName string, maxRss uint64) error { var ( msg *Payload err error ) - if msg, err = BuildAndWriteAutoSupport(collectors, status, pollerName); err != nil { + if msg, err = BuildAndWriteAutoSupport(collectors, status, pollerName, maxRss); err != nil { return fmt.Errorf("failed to build ASUP message poller:%s %w", pollerName, err) } @@ -193,13 +197,14 @@ func sendAsupVia(msg *Payload, asupExecPath string) error { return nil } -func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pollerName string) (*Payload, error) { +func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pollerName string, maxRss uint64) (*Payload, error) { var ( msg *Payload arch string cpus uint8 numPortRange uint64 + rssBytes uint64 ) // add info about the platform (where Harvest is running) @@ -227,7 +232,24 @@ func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pol numPortRange++ } } + hostname, _ := os.Hostname() + + // Get the PID and RSS in bytes of the current process. + // If there is an error, rssBytes will be zero + pid := os.Getpid() + newProcess, err := process.NewProcess(int32(pid)) + if err != nil { + logging.Get().Err(err).Msg("failed to get process info") + } else { + memInfo, err := newProcess.MemoryInfo() + if err != nil { + logging.Get().Err(err).Int("pid", pid).Msg("failed to get memory info") + } else { + rssBytes = memInfo.RSS + } + } + // add harvest release info msg.Harvest = &harvestInfo{ // harvest uuid creation from sha1 of cluster uuid @@ -241,6 +263,10 @@ func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pol NumPollers: uint64(len(conf.Config.Pollers)), NumExporters: uint64(len(conf.Config.Exporters)), NumPortRange: numPortRange, + Pid: pid, + RssBytes: rssBytes, + MaxRssBytes: max(maxRss, rssBytes), + EpochMilli: time.Now().UnixMilli(), } payloadPath, err := writeAutoSupport(msg, pollerName) if err != nil { diff --git a/cmd/poller/poller.go b/cmd/poller/poller.go index 6a6b489df..cc5f7faa6 100644 --- a/cmd/poller/poller.go +++ b/cmd/poller/poller.go @@ -126,6 +126,7 @@ type Poller struct { client *http.Client auth *auth.Credentials hasPromExporter bool + maxRssBytes uint64 } // Init starts Poller, reads parameters, opens zeroLog handler, initializes metadata, @@ -382,7 +383,7 @@ func (p *Poller) firstAutoSupport() { if p.collectors == nil { return } - if _, err := collector.BuildAndWriteAutoSupport(p.collectors, p.metadataTarget, p.name); err != nil { + if _, err := collector.BuildAndWriteAutoSupport(p.collectors, p.metadataTarget, p.name, p.maxRssBytes); err != nil { logger.Error().Err(err). Str("poller", p.name). Msg("First autosupport failed.") @@ -391,7 +392,7 @@ func (p *Poller) firstAutoSupport() { func (p *Poller) startAsup() (map[string]*matrix.Matrix, error) { if p.collectors != nil { - if err := collector.SendAutosupport(p.collectors, p.metadataTarget, p.name); err != nil { + if err := collector.SendAutosupport(p.collectors, p.metadataTarget, p.name, p.maxRssBytes); err != nil { logger.Error().Err(err). Str("poller", p.name). Msg("Start autosupport failed.") @@ -464,7 +465,6 @@ func (p *Poller) Run() { p.addMemoryMetadata() // add number of goroutines to metadata - // @TODO: cleanup, does not belong to "status" _ = p.metadataTarget.LazySetValueInt64("goroutines", "host", int64(runtime.NumGoroutine())) upc := 0 // up collectors @@ -1269,6 +1269,9 @@ func (p *Poller) addMemoryMetadata() { memPercentage := float64(memInfo.RSS) / float64(memory.Total) * 100 _ = p.status.LazySetValueFloat64("memory_percent", "host", memPercentage) + + // Update maxRssBytes + p.maxRssBytes = max(p.maxRssBytes, memInfo.RSS) } func startPoller(_ *cobra.Command, _ []string) {