Compare commits
No commits in common. "6fb59dd7beeb4a753cd9f9737e28992dabc46d96" and "8fb9f9d7f6082ca96ec2d120ede57dd9714c648f" have entirely different histories.
6fb59dd7be
...
8fb9f9d7f6
10 changed files with 67 additions and 178 deletions
34
.github/workflows/docker.yml
vendored
34
.github/workflows/docker.yml
vendored
|
@ -1,19 +1,11 @@
|
||||||
name: Publish Release
|
name: Publish Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tags:
|
tags:
|
||||||
description: "version"
|
description: "version"
|
||||||
required: false
|
required: true
|
||||||
type: string
|
type: string
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- created
|
|
||||||
push:
|
|
||||||
branches: ["main"]
|
|
||||||
pull_request:
|
|
||||||
branches: ["main"]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_docker_release:
|
build_docker_release:
|
||||||
|
@ -25,16 +17,6 @@ jobs:
|
||||||
ref: "main"
|
ref: "main"
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Release tag
|
|
||||||
id: releasetag
|
|
||||||
run: |
|
|
||||||
if [ -z "${{ inputs.tag }}" ]; then
|
|
||||||
latest_release_tag=$(curl -s "https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases/latest" | jq -r .tag_name)
|
|
||||||
echo "release_tag=${latest_release_tag}" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "release_tag=${{ inputs.tag }}" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
|
@ -42,37 +24,35 @@ jobs:
|
||||||
images: |
|
images: |
|
||||||
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=latest,enable=true
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
|
||||||
type=sha
|
type=sha
|
||||||
type=raw,value=${{ steps.releasetag.outputs.release_tag }},enable=true
|
type=raw,value=${{ inputs.tags }}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
|
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GH_TOKEN }}
|
password: ${{ secrets.GH_TOKEN }}
|
||||||
if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
|
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
platforms: linux/arm/v7,linux/amd64,linux/arm64
|
platforms: linux/arm/v7,linux/amd64,linux/arm64
|
||||||
push: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -15,6 +15,6 @@ require (
|
||||||
github.com/prometheus/client_model v0.5.0 // indirect
|
github.com/prometheus/client_model v0.5.0 // indirect
|
||||||
github.com/prometheus/common v0.45.0 // indirect
|
github.com/prometheus/common v0.45.0 // indirect
|
||||||
github.com/prometheus/procfs v0.12.0 // indirect
|
github.com/prometheus/procfs v0.12.0 // indirect
|
||||||
golang.org/x/sys v0.14.0 // indirect
|
golang.org/x/sys v0.13.0 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
5
go.sum
5
go.sum
|
@ -8,7 +8,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
||||||
|
@ -29,8 +28,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"type": "grafana",
|
"type": "grafana",
|
||||||
"id": "grafana",
|
"id": "grafana",
|
||||||
"name": "Grafana",
|
"name": "Grafana",
|
||||||
"version": "10.2.0"
|
"version": "10.1.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "panel",
|
"type": "panel",
|
||||||
|
@ -137,7 +137,7 @@
|
||||||
},
|
},
|
||||||
"textMode": "auto"
|
"textMode": "auto"
|
||||||
},
|
},
|
||||||
"pluginVersion": "10.2.0",
|
"pluginVersion": "10.1.5",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"datasource": {
|
"datasource": {
|
||||||
|
@ -206,7 +206,7 @@
|
||||||
},
|
},
|
||||||
"textMode": "auto"
|
"textMode": "auto"
|
||||||
},
|
},
|
||||||
"pluginVersion": "10.2.0",
|
"pluginVersion": "10.1.5",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"datasource": {
|
"datasource": {
|
||||||
|
@ -275,7 +275,7 @@
|
||||||
},
|
},
|
||||||
"textMode": "auto"
|
"textMode": "auto"
|
||||||
},
|
},
|
||||||
"pluginVersion": "10.2.0",
|
"pluginVersion": "10.1.5",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"datasource": {
|
"datasource": {
|
||||||
|
@ -344,7 +344,7 @@
|
||||||
},
|
},
|
||||||
"textMode": "auto"
|
"textMode": "auto"
|
||||||
},
|
},
|
||||||
"pluginVersion": "10.2.0",
|
"pluginVersion": "10.1.5",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"datasource": {
|
"datasource": {
|
||||||
|
@ -521,7 +521,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"pluginVersion": "10.2.0",
|
"pluginVersion": "10.1.5",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"datasource": {
|
"datasource": {
|
||||||
|
@ -552,7 +552,6 @@
|
||||||
"mode": "palette-classic"
|
"mode": "palette-classic"
|
||||||
},
|
},
|
||||||
"custom": {
|
"custom": {
|
||||||
"axisBorderShow": false,
|
|
||||||
"axisCenteredZero": false,
|
"axisCenteredZero": false,
|
||||||
"axisColorMode": "text",
|
"axisColorMode": "text",
|
||||||
"axisLabel": "",
|
"axisLabel": "",
|
||||||
|
@ -633,7 +632,7 @@
|
||||||
"exemplar": false,
|
"exemplar": false,
|
||||||
"expr": "immich_user_usage",
|
"expr": "immich_user_usage",
|
||||||
"instant": false,
|
"instant": false,
|
||||||
"legendFormat": "{{name}}",
|
"legendFormat": "{{firstname}} {{lastname}}",
|
||||||
"range": true,
|
"range": true,
|
||||||
"refId": "A"
|
"refId": "A"
|
||||||
}
|
}
|
||||||
|
@ -652,7 +651,6 @@
|
||||||
"mode": "palette-classic"
|
"mode": "palette-classic"
|
||||||
},
|
},
|
||||||
"custom": {
|
"custom": {
|
||||||
"axisBorderShow": false,
|
|
||||||
"axisCenteredZero": false,
|
"axisCenteredZero": false,
|
||||||
"axisColorMode": "text",
|
"axisColorMode": "text",
|
||||||
"axisLabel": "",
|
"axisLabel": "",
|
||||||
|
@ -867,7 +865,7 @@
|
||||||
"exemplar": false,
|
"exemplar": false,
|
||||||
"expr": "immich_user_usage",
|
"expr": "immich_user_usage",
|
||||||
"instant": true,
|
"instant": true,
|
||||||
"legendFormat": "{{name}}",
|
"legendFormat": "{{firstname}} {{lastname}}",
|
||||||
"range": false,
|
"range": false,
|
||||||
"refId": "A"
|
"refId": "A"
|
||||||
}
|
}
|
||||||
|
@ -876,8 +874,9 @@
|
||||||
"type": "piechart"
|
"type": "piechart"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"refresh": "auto",
|
"refresh": "5m",
|
||||||
"schemaVersion": 38,
|
"schemaVersion": 38,
|
||||||
|
"style": "dark",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"templating": {
|
"templating": {
|
||||||
"list": []
|
"list": []
|
||||||
|
@ -890,6 +889,6 @@
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"title": "Immich Go",
|
"title": "Immich Go",
|
||||||
"uid": "9QXCv3AVk",
|
"uid": "9QXCv3AVk",
|
||||||
"version": 5,
|
"version": 4,
|
||||||
"weekStart": ""
|
"weekStart": ""
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "immich-exporter",
|
"name": "immich-exporter",
|
||||||
"version": "1.2.0",
|
"version": "1.0.1",
|
||||||
"description": "exporter for immich",
|
"description": "exporter for immich",
|
||||||
"main": "src/main.go",
|
"main": "src/main.go",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build" : "go build -o ./immich-exporter.out ./src && ./immich-exporter.out",
|
"build" : "go build -o ./immich-exporter.out ./src && ./immich-exporter.out -e",
|
||||||
"build:env" : "go build -o ./immich-exporter.out ./src && ./immich-exporter.out -e",
|
"build:env" : "go build -o ./immich-exporter.out ./src && ./immich-exporter.out -e",
|
||||||
"dev" : "go run ./src",
|
"dev" : "go run ./src",
|
||||||
"dev:env" : "go run ./src -e",
|
"dev:env" : "go run ./src -e",
|
||||||
|
|
|
@ -32,30 +32,23 @@ func Allrequests(r *prometheus.Registry) {
|
||||||
func Analyze(r *prometheus.Registry) {
|
func Analyze(r *prometheus.Registry) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
alljobsstatus := make(chan func() (*models.StructAllJobsStatus, error))
|
|
||||||
allusers := make(chan func() (*models.StructAllUsers, error))
|
allusers := make(chan func() (*models.StructAllUsers, error))
|
||||||
serverinfo := make(chan func() (*models.StructServerInfo, error))
|
serverinfo := make(chan func() (*models.StructServerInfo, error))
|
||||||
defer func() {
|
|
||||||
close(serverinfo)
|
|
||||||
close(allusers)
|
|
||||||
close(alljobsstatus)
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Add(1)
|
|
||||||
go GetAllJobsStatus(alljobsstatus)
|
|
||||||
res1, err := (<-alljobsstatus)()
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go GetAllUsers(allusers)
|
go GetAllUsers(allusers)
|
||||||
res2, err2 := (<-allusers)()
|
res1, err := (<-allusers)()
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go ServerInfo(serverinfo)
|
go ServerInfo(serverinfo)
|
||||||
|
|
||||||
res3, err3 := (<-serverinfo)()
|
res2, err2 := (<-serverinfo)()
|
||||||
|
|
||||||
if err != nil && err2 != nil && err3 != nil {
|
if err != nil && err2 != nil {
|
||||||
} else {
|
} else {
|
||||||
prom.SendBackMessagePreference(res3, res2, res1, r)
|
prom.SendBackMessagePreference(res2, res1, r)
|
||||||
}
|
}
|
||||||
|
close(serverinfo)
|
||||||
|
close(allusers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllUsers(c chan func() (*models.StructAllUsers, error)) {
|
func GetAllUsers(c chan func() (*models.StructAllUsers, error)) {
|
||||||
|
@ -104,7 +97,7 @@ func ServerVersion(r *prometheus.Registry) {
|
||||||
|
|
||||||
func ServerInfo(c chan func() (*models.StructServerInfo, error)) {
|
func ServerInfo(c chan func() (*models.StructServerInfo, error)) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
resp, err := Apirequest("/api/server-info/statistics", "GET")
|
resp, err := Apirequest("/api/server-info/stats", "GET")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
if models.GetPromptError() == true {
|
if models.GetPromptError() == true {
|
||||||
|
@ -125,29 +118,6 @@ func ServerInfo(c chan func() (*models.StructServerInfo, error)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllJobsStatus(c chan func() (*models.StructAllJobsStatus, error)) {
|
|
||||||
defer wg.Done()
|
|
||||||
resp, err := Apirequest("/api/jobs", "GET")
|
|
||||||
if err == nil {
|
|
||||||
|
|
||||||
if models.GetPromptError() == true {
|
|
||||||
models.SetPromptError(false)
|
|
||||||
}
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
} else {
|
|
||||||
|
|
||||||
result := new(models.StructAllJobsStatus)
|
|
||||||
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to go struct pointer
|
|
||||||
log.Println(unmarshalError)
|
|
||||||
}
|
|
||||||
c <- (func() (*models.StructAllJobsStatus, error) { return result, nil })
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Apirequest(uri string, method string) (*http.Response, error) {
|
func Apirequest(uri string, method string) (*http.Response, error) {
|
||||||
|
|
||||||
req, err := http.NewRequest(method, models.Getbaseurl()+uri, nil)
|
req, err := http.NewRequest(method, models.Getbaseurl()+uri, nil)
|
||||||
|
@ -174,12 +144,6 @@ func Apirequest(uri string, method string) (*http.Response, error) {
|
||||||
models.SetPromptError(false)
|
models.SetPromptError(false)
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
case http.StatusNotFound:
|
|
||||||
err := fmt.Errorf("%d", resp.StatusCode)
|
|
||||||
|
|
||||||
log.Fatal("Error code ", resp.StatusCode, " for ", models.Getbaseurl()+uri)
|
|
||||||
|
|
||||||
return resp, err
|
|
||||||
case http.StatusUnauthorized, http.StatusForbidden:
|
case http.StatusUnauthorized, http.StatusForbidden:
|
||||||
err := fmt.Errorf("%d", resp.StatusCode)
|
err := fmt.Errorf("%d", resp.StatusCode)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,9 @@ func main() {
|
||||||
log.Info("Started")
|
log.Info("Started")
|
||||||
http.HandleFunc("/metrics", metrics)
|
http.HandleFunc("/metrics", metrics)
|
||||||
addr := ":" + strconv.Itoa(models.GetPort())
|
addr := ":" + strconv.Itoa(models.GetPort())
|
||||||
log.Info("Listening on port ", models.GetPort())
|
if models.GetPort() != DEFAULTPORT {
|
||||||
|
log.Info("Listening on port", models.GetPort())
|
||||||
|
}
|
||||||
http.ListenAndServe(addr, nil)
|
http.ListenAndServe(addr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ func metrics(w http.ResponseWriter, r *http.Request) {
|
||||||
immich.Allrequests(registry)
|
immich.Allrequests(registry)
|
||||||
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func projectinfo() {
|
func projectinfo() {
|
||||||
|
|
|
@ -6,7 +6,8 @@ type StructLogin struct {
|
||||||
AccessToken string `json:"accessToken"`
|
AccessToken string `json:"accessToken"`
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
UserEmail string `json:"userEmail"`
|
UserEmail string `json:"userEmail"`
|
||||||
Name string `json:"name"`
|
FirstName string `json:"firstName"`
|
||||||
|
LastName string `json:"lastName"`
|
||||||
IsAdmin bool `json:"isAdmin"`
|
IsAdmin bool `json:"isAdmin"`
|
||||||
ShouldChangePassword bool `json:"shouldChangePassword"`
|
ShouldChangePassword bool `json:"shouldChangePassword"`
|
||||||
}
|
}
|
||||||
|
@ -17,7 +18,8 @@ type StructServerInfo struct {
|
||||||
Usage int64 `json:"usage"`
|
Usage int64 `json:"usage"`
|
||||||
UsageByUser []struct {
|
UsageByUser []struct {
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
UserName string `json:"userName"`
|
UserFirstName string `json:"userFirstName"`
|
||||||
|
UserLastName string `json:"userLastName"`
|
||||||
Photos int `json:"photos"`
|
Photos int `json:"photos"`
|
||||||
Videos int `json:"videos"`
|
Videos int `json:"videos"`
|
||||||
Usage int `json:"usage"`
|
Usage int `json:"usage"`
|
||||||
|
@ -43,7 +45,8 @@ type StructServerVersion struct {
|
||||||
type StructAllUsers []struct {
|
type StructAllUsers []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
FirstName string `json:"firstName"`
|
||||||
|
LastName string `json:"lastName"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
ProfileImagePath string `json:"profileImagePath"`
|
ProfileImagePath string `json:"profileImagePath"`
|
||||||
ShouldChangePassword bool `json:"shouldChangePassword"`
|
ShouldChangePassword bool `json:"shouldChangePassword"`
|
||||||
|
@ -55,36 +58,7 @@ type StructAllUsers []struct {
|
||||||
type StructCustomUser struct {
|
type StructCustomUser struct {
|
||||||
Email string
|
Email string
|
||||||
ID string
|
ID string
|
||||||
Name string
|
FirstName string
|
||||||
|
LastName string
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type StructJobStatus struct {
|
|
||||||
JobCounts struct {
|
|
||||||
Active int `json:"active"`
|
|
||||||
Completed int `json:"completed"`
|
|
||||||
Failed int `json:"failed"`
|
|
||||||
Delayed int `json:"delayed"`
|
|
||||||
Waiting int `json:"waiting"`
|
|
||||||
Paused int `json:"paused"`
|
|
||||||
} `json:"jobCounts"`
|
|
||||||
QueueStatus struct {
|
|
||||||
IsActive bool `json:"isActive"`
|
|
||||||
IsPaused bool `json:"isPaused"`
|
|
||||||
} `json:"queueStatus"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructAllJobsStatus struct {
|
|
||||||
ThumbnailGeneration StructJobStatus `json:"thumbnailGeneration"`
|
|
||||||
MetadataExtraction StructJobStatus `json:"metadataExtraction"`
|
|
||||||
VideoConversion StructJobStatus `json:"videoConversion"`
|
|
||||||
ObjectTagging StructJobStatus `json:"objectTagging"`
|
|
||||||
RecognizeFaces StructJobStatus `json:"recognizeFaces"`
|
|
||||||
ClipEncoding StructJobStatus `json:"clipEncoding"`
|
|
||||||
BackgroundTask StructJobStatus `json:"backgroundTask"`
|
|
||||||
StorageTemplateMigration StructJobStatus `json:"storageTemplateMigration"`
|
|
||||||
Migration StructJobStatus `json:"migration"`
|
|
||||||
Search StructJobStatus `json:"search"`
|
|
||||||
Sidecar StructJobStatus `json:"sidecar"`
|
|
||||||
Library StructJobStatus `json:"library"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,12 +14,7 @@ type Gauge []struct {
|
||||||
value float64
|
value float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendBackMessagePreference(
|
func SendBackMessagePreference(result *models.StructServerInfo, result2 *models.StructAllUsers, r *prometheus.Registry) {
|
||||||
result *models.StructServerInfo,
|
|
||||||
result2 *models.StructAllUsers,
|
|
||||||
result3 *models.StructAllJobsStatus,
|
|
||||||
r *prometheus.Registry,
|
|
||||||
) {
|
|
||||||
|
|
||||||
gauges := Gauge{
|
gauges := Gauge{
|
||||||
{"total photos", "The total number of photos", float64((*result).Photos)},
|
{"total photos", "The total number of photos", float64((*result).Photos)},
|
||||||
|
@ -33,61 +28,34 @@ func SendBackMessagePreference(
|
||||||
user_info := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
user_info := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "immich_user_info",
|
Name: "immich_user_info",
|
||||||
Help: "All infos about users",
|
Help: "All infos about users",
|
||||||
}, []string{"videos", "photos", "uid", "usage", "name"})
|
}, []string{"videos", "photos", "uid", "usage", "firstname", "lastname"})
|
||||||
|
|
||||||
user_usage := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
user_usage := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "immich_user_usage",
|
Name: "immich_user_usage",
|
||||||
Help: "The usage of the user",
|
Help: "The usage of the user",
|
||||||
}, []string{"uid", "name"})
|
}, []string{"uid", "firstname", "lastname"})
|
||||||
user_photos := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
user_photos := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "immich_user_photos",
|
Name: "immich_user_photos",
|
||||||
Help: "The number of photo of the user",
|
Help: "The number of photo of the user",
|
||||||
}, []string{"uid", "name"})
|
}, []string{"uid", "firstname", "lastname"})
|
||||||
user_videos := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
user_videos := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "immich_user_videos",
|
Name: "immich_user_videos",
|
||||||
Help: "The number of videos of the user",
|
Help: "The number of videos of the user",
|
||||||
}, []string{"uid", "name"})
|
}, []string{"uid", "firstname", "lastname"})
|
||||||
|
|
||||||
job_count := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
||||||
Name: "immich_job_count",
|
|
||||||
Help: "The item count in the job",
|
|
||||||
}, []string{"status", "job_name"})
|
|
||||||
|
|
||||||
r.MustRegister(user_info)
|
r.MustRegister(user_info)
|
||||||
r.MustRegister(user_usage)
|
r.MustRegister(user_usage)
|
||||||
r.MustRegister(user_videos)
|
r.MustRegister(user_videos)
|
||||||
r.MustRegister(user_photos)
|
r.MustRegister(user_photos)
|
||||||
r.MustRegister(job_count)
|
|
||||||
|
|
||||||
for i := 0; i < len((*result).UsageByUser); i++ {
|
for i := 0; i < len((*result).UsageByUser); i++ {
|
||||||
var myuser = GetName((*result).UsageByUser[i].UserID, result2)
|
var myuser = GetName((*result).UsageByUser[i].UserID, result2)
|
||||||
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].Usage)), "name": myuser.Name}).Inc()
|
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].Usage)), "firstname": myuser.FirstName, "lastname": myuser.LastName}).Inc()
|
||||||
user_photos.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "name": myuser.Name}).Set(float64((*result).UsageByUser[i].Photos))
|
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, "name": myuser.Name}).Set(float64((*result).UsageByUser[i].Usage))
|
user_usage.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "firstname": myuser.FirstName, "lastname": myuser.LastName}).Set(float64((*result).UsageByUser[i].Usage))
|
||||||
user_videos.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "name": myuser.Name}).Set(float64((*result).UsageByUser[i].Videos))
|
user_videos.With(prometheus.Labels{"uid": (*result).UsageByUser[i].UserID, "firstname": myuser.FirstName, "lastname": myuser.LastName}).Set(float64((*result).UsageByUser[i].Videos))
|
||||||
}
|
}
|
||||||
|
|
||||||
setJobStatusCounts(job_count, "background_task", &result3.BackgroundTask)
|
|
||||||
setJobStatusCounts(job_count, "clip_encoding", &result3.ClipEncoding)
|
|
||||||
setJobStatusCounts(job_count, "library", &result3.Library)
|
|
||||||
setJobStatusCounts(job_count, "metadata_extraction", &result3.MetadataExtraction)
|
|
||||||
setJobStatusCounts(job_count, "migration", &result3.Migration)
|
|
||||||
setJobStatusCounts(job_count, "object_tagging", &result3.ObjectTagging)
|
|
||||||
setJobStatusCounts(job_count, "recognize_faces", &result3.RecognizeFaces)
|
|
||||||
setJobStatusCounts(job_count, "search", &result3.Search)
|
|
||||||
setJobStatusCounts(job_count, "sidecar", &result3.Sidecar)
|
|
||||||
setJobStatusCounts(job_count, "storage_template_migration", &result3.StorageTemplateMigration)
|
|
||||||
setJobStatusCounts(job_count, "thumbnail_generation", &result3.ThumbnailGeneration)
|
|
||||||
setJobStatusCounts(job_count, "video_conversion", &result3.VideoConversion)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setJobStatusCounts(job_count *prometheus.GaugeVec, jobName string, result *models.StructJobStatus) {
|
|
||||||
job_count.With(prometheus.Labels{"status": "active", "job_name": jobName}).Set(float64(result.JobCounts.Active))
|
|
||||||
job_count.With(prometheus.Labels{"status": "completed", "job_name": jobName}).Set(float64(result.JobCounts.Completed))
|
|
||||||
job_count.With(prometheus.Labels{"status": "failed", "job_name": jobName}).Set(float64(result.JobCounts.Failed))
|
|
||||||
job_count.With(prometheus.Labels{"status": "delayed", "job_name": jobName}).Set(float64(result.JobCounts.Delayed))
|
|
||||||
job_count.With(prometheus.Labels{"status": "waiting", "job_name": jobName}).Set(float64(result.JobCounts.Waiting))
|
|
||||||
job_count.With(prometheus.Labels{"status": "paused", "job_name": jobName}).Set(float64(result.JobCounts.Paused))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendBackMessageserverVersion(result *models.StructServerVersion, r *prometheus.Registry) {
|
func SendBackMessageserverVersion(result *models.StructServerVersion, r *prometheus.Registry) {
|
||||||
|
@ -110,7 +78,8 @@ func GetName(result string, result2 *models.StructAllUsers) models.StructCustomU
|
||||||
if (*result2)[i].ID == result {
|
if (*result2)[i].ID == result {
|
||||||
|
|
||||||
myuser.ID = (*result2)[i].ID
|
myuser.ID = (*result2)[i].ID
|
||||||
myuser.Name = (*result2)[i].Name
|
myuser.FirstName = (*result2)[i].FirstName
|
||||||
|
myuser.LastName = (*result2)[i].LastName
|
||||||
myuser.Email = (*result2)[i].Email
|
myuser.Email = (*result2)[i].Email
|
||||||
myuser.IsAdmin = (*result2)[i].IsAdmin
|
myuser.IsAdmin = (*result2)[i].IsAdmin
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,15 @@ import (
|
||||||
|
|
||||||
func TestGetName(t *testing.T) {
|
func TestGetName(t *testing.T) {
|
||||||
result2 := &models.StructAllUsers{
|
result2 := &models.StructAllUsers{
|
||||||
{ID: "1", Name: "John", Email: "john@example.com", IsAdmin: true},
|
{ID: "1", FirstName: "John", LastName: "Doe", Email: "john@example.com", IsAdmin: true},
|
||||||
{ID: "2", Name: "Jane", Email: "jane@example.com", IsAdmin: false},
|
{ID: "2", FirstName: "Jane", LastName: "Smith", Email: "jane@example.com", IsAdmin: false},
|
||||||
}
|
}
|
||||||
|
|
||||||
result := "1"
|
result := "1"
|
||||||
expected := models.StructCustomUser{
|
expected := models.StructCustomUser{
|
||||||
ID: "1",
|
ID: "1",
|
||||||
Name: "John",
|
FirstName: "John",
|
||||||
|
LastName: "Doe",
|
||||||
Email: "john@example.com",
|
Email: "john@example.com",
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue