getSystemUptime gets system uptime
(ctx context.Context)
| 374 | |
| 375 | // getSystemUptime gets system uptime |
| 376 | func (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 |
| 399 | func (d *Detector) getLoadAverage(ctx context.Context) []float64 { |