Data flow¶
This page describes how uptime is computed and propagated from the server to the frontend, and how polling is coordinated.
Server-side¶
- System uptime is read from
/proc/uptimeon Linux, withpsutil.boot_time()as a fallback (psutilis declared as a runtime dependency inpyproject.toml). OctoPrint process uptime is read from/proc/self/stat, falling back to thepsutilprocess creation time. - When no source yields a valid value, the API response carries
uptime_available: falseplus a localizeduptime_notehint; the field is omitted otherwise. - Formatting helpers convert raw seconds into human-friendly strings (
full,dhm,dh,d; see Algorithms & formatting).
API contract¶
Example response (partial):
{
"seconds": 3600.0,
"uptime": "1h 0m 0s",
"uptime_dhm": "1h 0m",
"display_format": "dhm",
"poll_interval_seconds": 5,
"uptime_available": true
}
Frontend polling¶
- The frontend ViewModel starts its polling loop in the OctoPrint
onStartupCompletelifecycle hook (not in the constructor) to guarantee thatsettingsViewModel.settingsis fully populated before the first settings read. - On each cycle the ViewModel reads
show_system_uptimeandshow_octoprint_uptimefrom the plugin settings. If both arefalsethe navbar is hidden immediately vianavbarEl.hide()and polling resumes after the configured interval. - Polling continues when both are disabled because: It keeps detecting runtime changes and config updates.
- When
icon_onlyistrue(and at least one uptime type is enabled), the navbar text is cleared so only the icon remains; the current uptime values are prepended to the tooltip instead. Icon-only mode takes precedence overcompact_display. - When both are enabled and
compact_displayistrue, the navbar alternates between system and OctoPrint uptime at the configuredcompact_toggle_interval_secondsinterval (default 5s, range 5-60 seconds) without an additional API call. - The poll interval is taken from the server response (
poll_interval_seconds); if absent it falls back to the local setting (the frontend-configuredpoll_interval_secondsvalue) and then to the built-in default of 5 seconds. - Configuration is accessed through a
getPluginSettings()helper that re-resolvessettingsViewModel.settings.plugins.octoprint_uptimeon every call, avoiding stale captures from early construction time. - On each fetch the UI updates the navbar text and refreshes the localized
tooltip content (
System Started,OctoPrint Started) in both regular and compact modes. - Scheduling is adjusted accordingly based on the poll interval.
Rationale¶
The ViewModel continues to poll to detect runtime changes to those settings (allowing the navbar to be re-shown without a page reload), to pick up remote or central config updates, and to keep the ViewModel lifecycle simple rather than introducing pause/resume logic.
Resilience¶
- Error handling: When the API fetch fails, the ViewModel displays "Error" in the navbar and continues polling at the fixed
DEFAULT_POLLinterval (5 seconds) without requiring manual intervention. - Graceful degradation: When uptime data is unavailable (e.g.,
/proc/uptimenot accessible on Linux orpsutilnot installed), the API returnsuptime_available: falseand includes an optional localizeduptime_noteindicating uptime could not be determined. The UI surfaces this note to explain the fallback state. - Throttled logging: Debug log entries are throttled to avoid spam; plugin debug flag controls only these throttled entries while general logs depend on OctoPrint's global log level.
- Continued operation: The widget tolerates transient failures and continues polling and refreshing the display, allowing automatic recovery when the API becomes available again without requiring a page reload.