adding a few more vars, setting collection to 60 secs
This commit is contained in:
24
.dockerignore
Normal file
24
.dockerignore
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
.git
|
||||||
|
.cache
|
||||||
|
.vscode
|
||||||
|
.devcontainer
|
||||||
|
builds
|
||||||
|
config
|
||||||
|
database
|
||||||
|
documents
|
||||||
|
done
|
||||||
|
engine
|
||||||
|
node_modules
|
||||||
|
public/node_modules
|
||||||
|
public/src
|
||||||
|
public/.cache
|
||||||
|
*.bleve
|
||||||
|
.gitattributes
|
||||||
|
.gitignore
|
||||||
|
database.txt
|
||||||
|
go.mod
|
||||||
|
go.sum
|
||||||
|
*.db
|
||||||
|
*.log
|
||||||
|
package.json
|
||||||
|
yarn.lock
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,3 +21,5 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
bin/*
|
||||||
|
.env
|
||||||
|
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Stage 1
|
||||||
|
FROM alpine:latest as build
|
||||||
|
RUN mkdir -p /opt/prometheus-plex-exporter/public/built && \
|
||||||
|
mkdir /opt/prometheus-plex-exporter/config && \
|
||||||
|
adduser -S prom && addgroup -S prom
|
||||||
|
WORKDIR /opt/prometheus-plex-exporter
|
||||||
|
COPY LICENSE README.md /opt/prometheus-plex-exporter/config/
|
||||||
|
COPY bin/prometheus-plex-exporter /opt/prometheus-plex-exporter/prometheus-plex-exporter
|
||||||
|
RUN chmod +x /opt/prometheus-plex-exporter/prometheus-plex-exporter && \
|
||||||
|
chown -R prom:prom /opt/prometheus-plex-exporter/
|
||||||
|
|
||||||
|
# Stage 2
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build / /
|
||||||
|
LABEL Author="deranjer"
|
||||||
|
LABEL name="prometheus-plex-exporter"
|
||||||
|
EXPOSE 9545
|
||||||
|
WORKDIR /opt/prometheus-plex-exporter
|
||||||
|
ENTRYPOINT [ "/opt/prometheus-plex-exporter/prometheus-plex-exporter" ]
|
||||||
|
|
||||||
|
#docker build -t deranjer/goedms:latest .
|
22
Taskfile.yml
Normal file
22
Taskfile.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
dotenv: ['.env']
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
build:
|
||||||
|
cmds:
|
||||||
|
- GOOS=linux GOARCH=amd64 go build -o bin/prometheus-plex-exporter . # The infamous windows .
|
||||||
|
build-docker:
|
||||||
|
cmds:
|
||||||
|
- task: build
|
||||||
|
- docker build -t gitea.derajnet.duckdns.org/deranjer/prometheus-plex-exporter:latest .
|
||||||
|
publish-docker:
|
||||||
|
dotenv: ['.env']
|
||||||
|
cmds:
|
||||||
|
- task: build
|
||||||
|
- task: build-docker
|
||||||
|
- docker login gitea.derajnet.duckdns.org -u deranjer -p $DOCKER_PASS
|
||||||
|
- docker push gitea.derajnet.duckdns.org/deranjer/prometheus-plex-exporter:latest
|
||||||
|
test-env:
|
||||||
|
cmds:
|
||||||
|
- echo docker login -u deranjer -p $DOCKER_PASS
|
6
main.go
6
main.go
@@ -72,15 +72,19 @@ func main() {
|
|||||||
prometheus.MustRegister(plexActiveSessions)
|
prometheus.MustRegister(plexActiveSessions)
|
||||||
prometheus.MustRegister(plexNumMovies)
|
prometheus.MustRegister(plexNumMovies)
|
||||||
prometheus.MustRegister(plexNumTVShows)
|
prometheus.MustRegister(plexNumTVShows)
|
||||||
|
prometheus.MustRegister(plexTranscodeSessions)
|
||||||
|
prometheus.MustRegister(plexAllSessions)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 60)
|
||||||
fmt.Println("Collecting info...")
|
fmt.Println("Collecting info...")
|
||||||
stats := pc.gatherAllStats()
|
stats := pc.gatherAllStats()
|
||||||
plexActiveSessions.Set(stats.currentSessions)
|
plexActiveSessions.Set(stats.currentSessions)
|
||||||
plexNumMovies.Set(stats.numMovies)
|
plexNumMovies.Set(stats.numMovies)
|
||||||
plexNumTVShows.Set(stats.numTV)
|
plexNumTVShows.Set(stats.numTV)
|
||||||
|
plexTranscodeSessions.Set(stats.numTranscodes)
|
||||||
|
plexAllSessions.Set(stats.numAllSessions)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@@ -13,6 +13,8 @@ type plexStats struct {
|
|||||||
currentSessions float64
|
currentSessions float64
|
||||||
numMovies float64
|
numMovies float64
|
||||||
numTV float64
|
numTV float64
|
||||||
|
numTranscodes float64
|
||||||
|
numAllSessions float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlexClient struct {
|
type PlexClient struct {
|
||||||
@@ -76,7 +78,7 @@ func (pc *PlexClient) getNumMovies() *ActiveSessions {
|
|||||||
libraryAll := ActiveSessions{}
|
libraryAll := ActiveSessions{}
|
||||||
err := json.Unmarshal(result, &libraryAll)
|
err := json.Unmarshal(result, &libraryAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error unmarshalling current active sessions: ", err)
|
fmt.Println("Error unmarshalling num movies: ", err)
|
||||||
}
|
}
|
||||||
return &libraryAll
|
return &libraryAll
|
||||||
}
|
}
|
||||||
@@ -86,20 +88,45 @@ func (pc *PlexClient) getNumTV() *ActiveSessions {
|
|||||||
libraryAll := ActiveSessions{}
|
libraryAll := ActiveSessions{}
|
||||||
err := json.Unmarshal(result, &libraryAll)
|
err := json.Unmarshal(result, &libraryAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error unmarshalling current active sessions: ", err)
|
fmt.Println("Error unmarshalling num tv: ", err)
|
||||||
}
|
}
|
||||||
return &libraryAll
|
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 {
|
func (pc *PlexClient) gatherAllStats() *plexStats {
|
||||||
allStats := plexStats{}
|
allStats := plexStats{}
|
||||||
|
|
||||||
sessionsData := pc.getActiveSessions()
|
sessionsData := pc.getActiveSessions()
|
||||||
libraryDetails := pc.getNumMovies()
|
libraryDetails := pc.getNumMovies()
|
||||||
tvshowDetails := pc.getNumTV()
|
tvshowDetails := pc.getNumTV()
|
||||||
|
transcodeDetails := pc.getNumTranscodes()
|
||||||
|
allSessionsData := pc.getServerHistory()
|
||||||
|
|
||||||
allStats.currentSessions = float64(sessionsData.MediaContainer.Size)
|
allStats.currentSessions = float64(sessionsData.MediaContainer.Size)
|
||||||
allStats.numMovies = float64(libraryDetails.MediaContainer.Size)
|
allStats.numMovies = float64(libraryDetails.MediaContainer.Size)
|
||||||
allStats.numTV = float64(tvshowDetails.MediaContainer.Size)
|
allStats.numTV = float64(tvshowDetails.MediaContainer.Size)
|
||||||
|
allStats.numTranscodes = float64(transcodeDetails.MediaContainer.Size)
|
||||||
|
allStats.numAllSessions = float64(allSessionsData.MediaContainer.Size)
|
||||||
return &allStats
|
return &allStats
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
type RawPlexModel struct {
|
||||||
|
MediaContainer struct {
|
||||||
|
Size int `json:"size"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ActiveSessions struct {
|
type ActiveSessions struct {
|
||||||
MediaContainer struct {
|
MediaContainer struct {
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
|
@@ -12,3 +12,11 @@ var plexNumMovies = prometheus.NewGauge(prometheus.GaugeOpts{
|
|||||||
var plexNumTVShows = prometheus.NewGauge(prometheus.GaugeOpts{
|
var plexNumTVShows = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "plex_num_tv_shows", Help: "Number of TV Shows in the plex database",
|
Name: "plex_num_tv_shows", Help: "Number of TV Shows in the plex database",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var plexTranscodeSessions = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Name: "plex_num_transcodes", Help: "Number of current transcodes occuring in plex",
|
||||||
|
})
|
||||||
|
|
||||||
|
var plexAllSessions = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Name: "plex_num_all_sessions", Help: "Number of all sessions history for server",
|
||||||
|
})
|
||||||
|
Reference in New Issue
Block a user