diff --git a/src/immich/data.go b/src/immich/data.go index 2fba021..1f71431 100644 --- a/src/immich/data.go +++ b/src/immich/data.go @@ -14,6 +14,7 @@ import ( func Allrequests(r *prometheus.Registry) { serverversion(r) + Analyze(r) } @@ -21,7 +22,6 @@ func Analyze(r *prometheus.Registry) { allusers, err := GetAllUsers() users, err2 := users() if err != nil && err2 != nil { - } else { Sendbackmessagepreference(users, allusers, r) } @@ -53,7 +53,7 @@ func GetAllUsers() (*models.AllUsers, error) { log.Println("Can not unmarshal JSON") } - return &result, err + return &result, nil } } diff --git a/src/immich/sendbackmessage.go b/src/immich/sendbackmessage.go index 44b6e13..b8d5271 100644 --- a/src/immich/sendbackmessage.go +++ b/src/immich/sendbackmessage.go @@ -1,7 +1,6 @@ package immich import ( - "fmt" "immich-exporter/src/models" "strconv" @@ -26,32 +25,49 @@ func Sendbackmessagepreference(result *models.Users, result2 *models.AllUsers, r Name: "immich_app_number_users", Help: "The total number of users", }) + user_info := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "immich_user_info", + Help: "All infos about users", + }, []string{"videos", "photos", "uid", "usage", "firstname", "lastname"}) + + user_usage := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "immich_user_usage", + Help: "The usage of the user", + }, []string{"uid", "firstname", "lastname"}) + user_photos := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "immich_user_photos", + Help: "The number of photo of the user", + }, []string{"uid", "firstname", "lastname"}) + user_videos := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "immich_user_videos", + Help: "The number of videos of the user", + }, []string{"uid", "firstname", "lastname"}) + + r.MustRegister(user_info) r.MustRegister(total_usage) r.MustRegister(total_videos) r.MustRegister(total_photos) r.MustRegister(total_users) + r.MustRegister(user_usage) + r.MustRegister(user_videos) + r.MustRegister(user_photos) total_photos.Add(float64((*result).Photos)) total_videos.Add(float64((*result).Videos)) total_usage.Add(float64((*result).UsageRaw)) total_users.Add(float64(len((*result).UsageByUser))) - immich_user_videos := "# HELP immich_app_user_videos The number of videos of the user\n# TYPE immich_app_user_videos gauge\n" - immich_user_photos := "# HELP immich_app_user_photos The number of photo of the user\n# TYPE immich_app_user_photos gauge\n" - immich_user_usageRaw := "# HELP immich_app_user_usage The usage of the user\n# TYPE immich_app_user_usage gauge\n" - immich_user_info := "# HELP immich_user_info All info for torrents\n# TYPE immich_user_info gauge\n" for i := 0; i < len((*result).UsageByUser); i++ { var myuser = GetName((*result).UsageByUser[i].UserID, result2) - immich_user_info = immich_user_info + `immich_user_info{videos="` + strconv.Itoa((*result).UsageByUser[i].Videos) + `",photos="` + strconv.Itoa((*result).UsageByUser[i].Photos) + `",uid="` + (*result).UsageByUser[i].UserID + `",usage="` + strconv.Itoa(int((*result).UsageByUser[i].UsageRaw)) + `",firstname="` + myuser.FirstName + `",lastname="` + myuser.LastName + `"} 1.0` + "\n" - immich_user_usageRaw = immich_user_usageRaw + `immich_user_usage{uid="` + (*result).UsageByUser[i].UserID + `",firstname="` + myuser.FirstName + `",lastname="` + myuser.LastName + `",} ` + strconv.Itoa(int((*result).UsageByUser[i].UsageRaw)) + "\n" - immich_user_photos = immich_user_photos + `immich_user_photos{uid="` + (*result).UsageByUser[i].UserID + `",firstname="` + myuser.FirstName + `",lastname="` + myuser.LastName + `",} ` + strconv.Itoa((*result).UsageByUser[i].Photos) + "\n" - immich_user_videos = immich_user_videos + `immich_user_videos{uid="` + (*result).UsageByUser[i].UserID + `",firstname="` + myuser.FirstName + `",lastname="` + myuser.LastName + `",} ` + strconv.Itoa((*result).UsageByUser[i].Videos) + "\n" + user_info.With(prometheus.Labels{"videos": strconv.Itoa((*result).UsageByUser[i].Videos), "photos": strconv.Itoa((*result).UsageByUser[i].Photos), "uid": (*result).UsageByUser[i].UserID, "usage": strconv.Itoa(int((*result).UsageByUser[i].UsageRaw)), "firstname": myuser.FirstName, "lastname": myuser.LastName}).Inc() + user_photos.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "firstname": myuser.FirstName, "lastname": myuser.LastName}).Set(float64((*result).UsageByUser[i].Photos)) + user_usage.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "firstname": myuser.FirstName, "lastname": myuser.LastName}).Set(float64((*result).UsageByUser[i].UsageRaw)) + user_videos.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "firstname": myuser.FirstName, "lastname": myuser.LastName}).Set(float64((*result).UsageByUser[i].Videos)) } } func Sendbackmessageserverversion(result *models.ServerVersion, r *prometheus.Registry) { - fmt.Println("test") version := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "version", diff --git a/src/main.go b/src/main.go index 675228e..447df93 100644 --- a/src/main.go +++ b/src/main.go @@ -17,9 +17,6 @@ func main() { log.Println("username :", models.GetUsername()) log.Println("password :", models.Getpasswordmasked()) log.Println("Started") - r := prometheus.NewRegistry() - - immich.Allrequests(r) http.HandleFunc("/metrics", test) http.ListenAndServe(":8090", nil) diff --git a/src/models/test.go b/src/models/test.go index dc6321d..2a51d60 100644 --- a/src/models/test.go +++ b/src/models/test.go @@ -2,8 +2,6 @@ package models import "github.com/prometheus/client_golang/prometheus" -var r = prometheus.NewRegistry() - var ( appVersion string version = prometheus.NewGauge(prometheus.GaugeOpts{