Documentation
¶
Overview ¶
Package server contains the plexServer orchestrator: the refresh loop, per-subsystem refresh methods, and the Prometheus Describe/Collect implementation that emits metrics from plexServer state.
Index ¶
- type Server
- func (s *Server) Collect(ch chan<- prometheus.Metric)
- func (s *Server) Describe(ch chan<- *prometheus.Desc)
- func (s *Server) RecordError(typ string)
- func (s *Server) Refresh(outerCtx context.Context) error
- func (s *Server) RunRefreshLoop(ctx context.Context)
- func (s *Server) SetHTTPReachable(v bool)
- func (s *Server) SetWSConnected(v bool)
- func (s *Server) Snapshot() Snapshot
- func (s *Server) SnapshotLibraries() []library.Library
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
LastItemsRefresh time.Time
ErrorCounts map[string]float64
Client *plex.Client
Sessions *sessions.Tracker
ID string
Name string
Version string
Platform string
PlatformVersion string
Libraries []library.Library
HostCPU float64
HostMem float64
TransmitBytes float64
LastBandwidthAt int
ActiveTranscodes int
HTTPReachable bool
PlexPass bool
WSConnected bool
// contains filtered or unexported fields
}
Server is the Plex orchestrator. Fields are exported so that package main (Describe/Collect/websocket code still living there this step) and tests can read and mutate them under mu without a wall of accessor methods. The whole internal/* tree is a single trust boundary.
func NewServer ¶
NewServer returns an initialised Server for the given Plex HTTP client. LastBandwidthAt is seeded to "now" so the first bandwidth refresh only picks up samples produced after startup, matching legacy behaviour.
func (*Server) Collect ¶
func (s *Server) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector. It snapshots server state under s.mu (via Snapshot) and then emits metrics outside the lock so the collector never holds s.mu across a channel send.
func (*Server) Describe ¶
func (s *Server) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector. The descriptor set is the single source of truth published in metrics.AllDescs so that Describe and Collect cannot drift.
func (*Server) RecordError ¶
RecordError increments the error counter for the given type. The type must be a member of metrics.ErrorTypes; unknown types are silently dropped to preserve the Prometheus cardinality bound.
func (*Server) Refresh ¶
Refresh polls Plex for server identity, library list, host resources, and bandwidth. Intended to be called both from startup (to establish initial state) and from RunRefreshLoop on a ticker.
func (*Server) RunRefreshLoop ¶
RunRefreshLoop invokes Refresh on a 5-second ticker until ctx is cancelled. On failure it flips HTTPReachable to false and records a "refresh" error; on recovery it logs a single info-level line to keep log volume bounded. If a previous Refresh is still in-flight the tick is skipped to prevent redundant concurrent HTTP calls.
func (*Server) SetHTTPReachable ¶
SetHTTPReachable atomically sets the HTTPReachable flag.
func (*Server) SetWSConnected ¶
SetWSConnected atomically sets the WSConnected flag.
func (*Server) Snapshot ¶
Snapshot returns a consistent point-in-time copy of the server's metric-visible state. Callers emit Prometheus metrics from the snapshot so Collect never holds s.Mu across a channel send.
func (*Server) SnapshotLibraries ¶
SnapshotLibraries returns a copy of the current library list under the mutex.
type Snapshot ¶
type Snapshot struct {
ErrorCounts map[string]float64
PlatformVersion string
Name string
ID string
Version string
Platform string
PlexPass string
Libraries []library.Library
HostCPU float64
HostMem float64
TransmitBytes float64
ActiveTranscodes int
WSConnected float64
HTTPReachable float64
}
Snapshot is an immutable view of Server captured under s.Mu for metric emission. Keeping the snapshot/emit split tight keeps Collect's lock scope to a single block. PlexPass is stored as a string so the caller can emit it directly as a Prometheus label value.