adding a few more vars, setting collection to 60 secs
This commit is contained in:
@@ -13,6 +13,8 @@ type plexStats struct {
|
||||
currentSessions float64
|
||||
numMovies float64
|
||||
numTV float64
|
||||
numTranscodes float64
|
||||
numAllSessions float64
|
||||
}
|
||||
|
||||
type PlexClient struct {
|
||||
@@ -76,7 +78,7 @@ func (pc *PlexClient) getNumMovies() *ActiveSessions {
|
||||
libraryAll := ActiveSessions{}
|
||||
err := json.Unmarshal(result, &libraryAll)
|
||||
if err != nil {
|
||||
fmt.Println("Error unmarshalling current active sessions: ", err)
|
||||
fmt.Println("Error unmarshalling num movies: ", err)
|
||||
}
|
||||
return &libraryAll
|
||||
}
|
||||
@@ -86,20 +88,45 @@ func (pc *PlexClient) getNumTV() *ActiveSessions {
|
||||
libraryAll := ActiveSessions{}
|
||||
err := json.Unmarshal(result, &libraryAll)
|
||||
if err != nil {
|
||||
fmt.Println("Error unmarshalling current active sessions: ", err)
|
||||
fmt.Println("Error unmarshalling num tv: ", err)
|
||||
}
|
||||
return &libraryAll
|
||||
}
|
||||
|
||||
func (pc *PlexClient) getNumTranscodes() *RawPlexModel {
|
||||
result := pc.sendRequest("/transcode/sessions", nil)
|
||||
transcodesAll := RawPlexModel{}
|
||||
err := json.Unmarshal(result, &transcodesAll)
|
||||
if err != nil {
|
||||
fmt.Println("Error unmarshalling num transcodes: ", err)
|
||||
}
|
||||
return &transcodesAll
|
||||
}
|
||||
|
||||
// getServerHistory gets the entire history of plays on the plex server
|
||||
func (pc *PlexClient) getServerHistory() *RawPlexModel {
|
||||
result := pc.sendRequest("/status/sessions/history/all", nil) //Hard code library ID for now TODO: Grab from library/sections call
|
||||
sessionsAll := RawPlexModel{}
|
||||
err := json.Unmarshal(result, &sessionsAll)
|
||||
if err != nil {
|
||||
fmt.Println("Error unmarshalling session server history: ", err)
|
||||
}
|
||||
return &sessionsAll
|
||||
}
|
||||
|
||||
func (pc *PlexClient) gatherAllStats() *plexStats {
|
||||
allStats := plexStats{}
|
||||
|
||||
sessionsData := pc.getActiveSessions()
|
||||
libraryDetails := pc.getNumMovies()
|
||||
tvshowDetails := pc.getNumTV()
|
||||
transcodeDetails := pc.getNumTranscodes()
|
||||
allSessionsData := pc.getServerHistory()
|
||||
|
||||
allStats.currentSessions = float64(sessionsData.MediaContainer.Size)
|
||||
allStats.numMovies = float64(libraryDetails.MediaContainer.Size)
|
||||
allStats.numTV = float64(tvshowDetails.MediaContainer.Size)
|
||||
allStats.numTranscodes = float64(transcodeDetails.MediaContainer.Size)
|
||||
allStats.numAllSessions = float64(allSessionsData.MediaContainer.Size)
|
||||
return &allStats
|
||||
}
|
||||
|
Reference in New Issue
Block a user