Skip to content

Commit

Permalink
1.0.10 (#30) (#31)
Browse files Browse the repository at this point in the history
* create docker image

* Update docker-image.yml

* better error

* fix maxmind workflow

* fix: duplicate library

* update version
  • Loading branch information
TOomaAh authored Aug 4, 2024
1 parent bb4b800 commit e343724
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"TOomaAh/emby_exporter_go/conf"
"TOomaAh/emby_exporter_go/internal/app"
"TOomaAh/emby_exporter_go/internal/conf"
"TOomaAh/emby_exporter_go/pkg/logger"
"os"
"time"
Expand Down
12 changes: 7 additions & 5 deletions internal/app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"TOomaAh/emby_exporter_go/conf"
"TOomaAh/emby_exporter_go/internal/conf"
"TOomaAh/emby_exporter_go/internal/metrics"
"TOomaAh/emby_exporter_go/pkg/emby"
"TOomaAh/emby_exporter_go/pkg/geoip"
Expand All @@ -24,9 +24,6 @@ func logRequest(handler http.Handler) http.Handler {
}

func Run(config *conf.Config, logger logger.Interface) {
// Waiting signal
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

db, err := geoip.InitGeoIPDatabase(config.Options.GeoIP)
if err != nil {
Expand All @@ -45,7 +42,12 @@ func Run(config *conf.Config, logger logger.Interface) {
os.Exit(0)
}()

embyServer := emby.NewServer(&config.Server, logger)
embyServer := emby.NewServer(&emby.ServerInfo{
Hostname: config.Server.Hostname,
Port: config.Server.Port,
UserID: config.Server.UserID,
Token: config.Server.Token,
}, logger)
errorPing := embyServer.Ping()
if errorPing != nil {
logger.Error("Server is not reachable")
Expand Down
2 changes: 2 additions & 0 deletions conf/conf.go → internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewConfig(path string) (*Config, error) {
os.Exit(-1)
}

fmt.Printf("Configuration : %+v\n", config)

return &config, nil

}
3 changes: 2 additions & 1 deletion internal/metrics/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var (
libraryValue = []string{"name"}
libraryValue = []string{"id", "name"}
)

type LibraryCollector struct {
Expand Down Expand Up @@ -47,6 +47,7 @@ func (c *LibraryCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.library,
prometheus.GaugeValue, float64(librarySize),
l.ItemID,
l.Name,
)
}
Expand Down
27 changes: 16 additions & 11 deletions pkg/emby/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package emby

import (
"TOomaAh/emby_exporter_go/conf"
"TOomaAh/emby_exporter_go/internal/entity"
"TOomaAh/emby_exporter_go/pkg/logger"
"TOomaAh/emby_exporter_go/pkg/request"
Expand Down Expand Up @@ -32,12 +31,18 @@ type Server struct {
Logger logger.Interface
}

func NewServer(s *conf.Server, logger logger.Interface) *Server {
client, err := request.NewClient(s.Hostname+":"+s.Port, s.Token)

if err != nil {
logger.Fatal("Cannot create a new client for Emby Server " + err.Error())
os.Exit(1)
type ServerInfo struct {
Hostname string
Port string
UserID string
Token string
}


func NewServer(s *ServerInfo, logger logger.Interface) *Server {
if s.Hostname == "" {
s.Hostname = "http://localhost"
}

if s.Port == "" {
Expand All @@ -54,8 +59,11 @@ func NewServer(s *conf.Server, logger logger.Interface) *Server {
os.Exit(1)
}

if s.Hostname == "" {
s.Hostname = "localhost"
client, err := request.NewClient(s.Hostname+":"+s.Port, s.Token)

if err != nil {
logger.Fatal("Cannot create a new client for Emby Server " + err.Error())
os.Exit(1)
}

server := &Server{
Expand Down Expand Up @@ -150,9 +158,6 @@ func (s *Server) GetServerInfo() (*entity.SystemInfo, error) {
return nil, err
}

if err != nil {
return nil, err
}
return &systemInfo, nil
}

Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package main

const (
Version = "1.0.9"
Version = "1.0.10"
)

0 comments on commit e343724

Please sign in to comment.