MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / getSystemUptime

Method getSystemUptime

agent-source-code/internal/system/system.go:376–396  ·  view source on GitHub ↗

getSystemUptime gets system uptime

(ctx context.Context)

Source from the content-addressed store, hash-verified

374
375// getSystemUptime gets system uptime
376func (d *Detector) getSystemUptime(ctx context.Context) string {
377 info, err := host.InfoWithContext(ctx)
378 if err != nil {
379 d.logger.WithError(err).Warn("Failed to get uptime")
380 return "Unknown"
381 }
382
383 uptime := time.Duration(info.Uptime) * time.Second
384
385 days := int(uptime.Hours() / 24)
386 hours := int(uptime.Hours()) % 24
387 minutes := int(uptime.Minutes()) % 60
388
389 if days > 0 {
390 return fmt.Sprintf("%d days, %d hours, %d minutes", days, hours, minutes)
391 }
392 if hours > 0 {
393 return fmt.Sprintf("%d hours, %d minutes", hours, minutes)
394 }
395 return fmt.Sprintf("%d minutes", minutes)
396}
397
398// getLoadAverage gets system load average
399func (d *Detector) getLoadAverage(ctx context.Context) []float64 {

Callers 1

GetSystemInfoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected