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

feat: Harvest should log RSS and MaxRSS every hour #2999

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
55 changes: 42 additions & 13 deletions cmd/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ import (

// default params
var (
pollerSchedule = "1m"
logFileName = ""
logMaxMegaBytes = logging.DefaultLogMaxMegaBytes
logMaxBackups = logging.DefaultLogMaxBackups
logMaxAge = logging.DefaultLogMaxAge
asupSchedule = "24h" // send every 24 hours
asupFirstWrite = "4m" // after this time, write 1st autosupport payload (for testing)
opts *options.Options
pollerSchedule = "1m"
pollerLogSchedule = "1h"
logFileName = ""
logMaxMegaBytes = logging.DefaultLogMaxMegaBytes
logMaxBackups = logging.DefaultLogMaxBackups
logMaxAge = logging.DefaultLogMaxAge
asupSchedule = "24h" // send every 24 hours
asupFirstWrite = "4m" // after this time, write 1st autosupport payload (for testing)
opts *options.Options
)

const (
Expand Down Expand Up @@ -335,10 +336,22 @@ func (p *Poller) Init() error {
}
p.schedule = schedule.New()
if err = p.schedule.NewTaskString("poller", pollerSchedule, 0, nil, true, "poller_"+p.name); err != nil {
logger.Error().Stack().Err(err).Msg("set schedule:")
logger.Error().Err(err).Msg("set schedule:")
return err
}
logger.Debug().Msgf("set poller schedule with %s frequency", pollerSchedule)

if p.params.PollerLogSchedule != "" {
pollerLogSchedule = p.params.PollerLogSchedule
}
if err = p.schedule.NewTaskString("log", pollerLogSchedule, 0, p.logPollerMetadata, true, "poller_log_"+p.name); err != nil {
rahulguptajss marked this conversation as resolved.
Show resolved Hide resolved
logger.Error().Err(err).Msg("set schedule:")
return err
}

logger.Debug().
Str("pollerSchedule", pollerSchedule).
Str("pollerLogSchedule", pollerLogSchedule).
Msg("set poller schedule")

// Check if autosupport is enabled
tools := conf.Config.Tools
Expand Down Expand Up @@ -437,7 +450,8 @@ func (p *Poller) Run() {

// poller schedule has the poller and asup task (when enabled)
task := p.schedule.GetTask("poller")
asuptask := p.schedule.GetTask("asup")
asupTask := p.schedule.GetTask("asup")
logTask := p.schedule.GetTask("log")

// number of collectors/exporters that are still up
upCollectors := 0
Expand Down Expand Up @@ -534,8 +548,12 @@ func (p *Poller) Run() {
}

// asup task will be nil when autosupport is disabled
if asuptask != nil && asuptask.IsDue() {
_, _ = asuptask.Run()
if asupTask != nil && asupTask.IsDue() {
_, _ = asupTask.Run()
}

if logTask.IsDue() {
_, _ = logTask.Run()
}

p.schedule.Sleep()
Expand Down Expand Up @@ -1274,6 +1292,17 @@ func (p *Poller) addMemoryMetadata() {
p.maxRssBytes = max(p.maxRssBytes, memInfo.RSS)
}

func (p *Poller) logPollerMetadata() (map[string]*matrix.Matrix, error) {
rss, _ := p.status.LazyGetValueFloat64("memory.rss", "host")
logger.Info().
Float64("rssKB", rss).
Uint64("maxRssKB", p.maxRssBytes/1024).
Str("version", strings.TrimSpace(version.String())).
Msg("Metadata")

return nil, nil
}

func startPoller(_ *cobra.Command, _ []string) {
poller := &Poller{}
poller.options = opts
Expand Down
1 change: 1 addition & 0 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ type Poller struct {
LogSet *[]string `yaml:"log,omitempty"`
Password string `yaml:"password,omitempty"`
PollerSchedule string `yaml:"poller_schedule,omitempty"`
PollerLogSchedule string `yaml:"poller_log_schedule,omitempty"`
SslCert string `yaml:"ssl_cert,omitempty"`
SslKey string `yaml:"ssl_key,omitempty"`
TLSMinVersion string `yaml:"tls_min_version,omitempty"`
Expand Down