refactor
Signed-off-by: martin <martin.labat92@gmail.com>
This commit is contained in:
parent
4022be77ae
commit
be9d6fa0dc
6 changed files with 17 additions and 50 deletions
|
@ -38,7 +38,7 @@ func Analyze(r *prometheus.Registry) {
|
||||||
|
|
||||||
if err != nil && err2 != nil {
|
if err != nil && err2 != nil {
|
||||||
} else {
|
} else {
|
||||||
Sendbackmessagepreference(res2, res1, r)
|
SendBackMessagePreference(res2, res1, r)
|
||||||
}
|
}
|
||||||
close(serverinfo)
|
close(serverinfo)
|
||||||
close(allusers)
|
close(allusers)
|
||||||
|
@ -103,7 +103,7 @@ func ServerVersion(r *prometheus.Registry) {
|
||||||
log.Println("Can not unmarshal JSON")
|
log.Println("Can not unmarshal JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
Sendbackmessageserverversion(&result, r)
|
SendBackMessageserverVersion(&result, r)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package immich
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"immich-exporter/src/models"
|
"immich-exporter/src/models"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -44,7 +43,6 @@ func Sendbackmessagepreference(result *models.StructServerInfo, result2 *models.
|
||||||
}, []string{"uid", "firstname", "lastname"})
|
}, []string{"uid", "firstname", "lastname"})
|
||||||
|
|
||||||
r.MustRegister(user_info)
|
r.MustRegister(user_info)
|
||||||
|
|
||||||
r.MustRegister(total_usage)
|
r.MustRegister(total_usage)
|
||||||
r.MustRegister(total_videos)
|
r.MustRegister(total_videos)
|
||||||
r.MustRegister(total_photos)
|
r.MustRegister(total_photos)
|
||||||
|
@ -81,8 +79,8 @@ func Sendbackmessageserverversion(result *models.StructServerVersion, r *prometh
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetName(result string, result2 *models.StructAllUsers) models.CustomUser {
|
func GetName(result string, result2 *models.StructAllUsers) models.StructCustomUser {
|
||||||
var myuser models.CustomUser
|
var myuser models.StructCustomUser
|
||||||
for i := 0; i < len(*result2); i++ {
|
for i := 0; i < len(*result2); i++ {
|
||||||
if (*result2)[i].ID == result {
|
if (*result2)[i].ID == result {
|
||||||
|
|
||||||
|
|
|
@ -18,16 +18,13 @@ func main() {
|
||||||
log.Println("password :", models.Getpasswordmasked())
|
log.Println("password :", models.Getpasswordmasked())
|
||||||
log.Println("Started")
|
log.Println("Started")
|
||||||
|
|
||||||
http.HandleFunc("/metrics", test)
|
http.HandleFunc("/metrics", metrics)
|
||||||
http.ListenAndServe(":8090", nil)
|
http.ListenAndServe(":8090", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test(w http.ResponseWriter, r *http.Request) {
|
func metrics(w http.ResponseWriter, r *http.Request) {
|
||||||
registry := prometheus.NewRegistry()
|
registry := prometheus.NewRegistry()
|
||||||
|
|
||||||
immich.Allrequests(registry)
|
immich.Allrequests(registry)
|
||||||
|
|
||||||
// Delegate http serving to Promethues client library, which will call collector.Collect.
|
|
||||||
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ type StructAllUsers []struct {
|
||||||
OauthID string `json:"oauthId"`
|
OauthID string `json:"oauthId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomUser struct {
|
type StructCustomUser struct {
|
||||||
Email string
|
Email string
|
||||||
ID string
|
ID string
|
||||||
FirstName string
|
FirstName string
|
|
@ -1,21 +1,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type StructImmichUser struct {
|
type StructImmich struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
URL string
|
URL string
|
||||||
accessToken string
|
AccessToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
var myuser StructImmichUser
|
var myuser StructImmich
|
||||||
|
|
||||||
func mask(input string) string {
|
|
||||||
hide := ""
|
|
||||||
for i := 0; i < len(input); i++ {
|
|
||||||
hide += "*"
|
|
||||||
}
|
|
||||||
return hide
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getuser() (string, string) {
|
func Getuser() (string, string) {
|
||||||
return myuser.Username, myuser.Password
|
return myuser.Username, myuser.Password
|
||||||
|
@ -35,15 +27,19 @@ func Getpassword() string {
|
||||||
return myuser.Password
|
return myuser.Password
|
||||||
}
|
}
|
||||||
func Getpasswordmasked() string {
|
func Getpasswordmasked() string {
|
||||||
return mask(myuser.Password)
|
hide := ""
|
||||||
|
for i := 0; i < len(myuser.Password); i++ {
|
||||||
|
hide += "*"
|
||||||
|
}
|
||||||
|
return hide
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetAccessToken(accessToken string) {
|
func SetAccessToken(accessToken string) {
|
||||||
myuser.accessToken = accessToken
|
myuser.AccessToken = accessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAccessToken() string {
|
func GetAccessToken() string {
|
||||||
return myuser.accessToken
|
return myuser.AccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetURL() string {
|
func GetURL() string {
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package models
|
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
var (
|
|
||||||
appVersion string
|
|
||||||
version = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Name: "version",
|
|
||||||
Help: "Version information about this binary",
|
|
||||||
ConstLabels: map[string]string{
|
|
||||||
"version": appVersion,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
pubhttpRequestsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Name: "http_requests_total",
|
|
||||||
Help: "Count of all HTTP requests",
|
|
||||||
}, []string{"code", "method"})
|
|
||||||
|
|
||||||
httpRequestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
|
||||||
Name: "http_request_duration_seconds",
|
|
||||||
Help: "Duration of all HTTP requests",
|
|
||||||
}, []string{"code", "handler", "method"})
|
|
||||||
)
|
|
Loading…
Reference in a new issue