2023-07-03 00:16:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/hansmi/paperhooks/pkg/client"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type storagePathClient interface {
|
2023-07-27 00:14:04 +02:00
|
|
|
ListAllStoragePaths(context.Context, client.ListStoragePathsOptions, func(context.Context, client.StoragePath) error) error
|
2023-07-03 00:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type storagePathCollector struct {
|
|
|
|
cl storagePathClient
|
|
|
|
|
|
|
|
infoDesc *prometheus.Desc
|
|
|
|
docCountDesc *prometheus.Desc
|
|
|
|
}
|
|
|
|
|
|
|
|
func newStoragePathCollector(cl storagePathClient) *storagePathCollector {
|
|
|
|
return &storagePathCollector{
|
|
|
|
cl: cl,
|
|
|
|
|
|
|
|
infoDesc: prometheus.NewDesc("paperless_storage_path_info",
|
|
|
|
"Static information about a storage path.",
|
|
|
|
[]string{"id", "name", "slug"}, nil),
|
|
|
|
docCountDesc: prometheus.NewDesc("paperless_storage_path_document_count",
|
|
|
|
"Number of documents associated with a storage path.",
|
|
|
|
[]string{"id"}, nil),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *storagePathCollector) describe(ch chan<- *prometheus.Desc) {
|
|
|
|
ch <- c.infoDesc
|
|
|
|
ch <- c.docCountDesc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *storagePathCollector) collect(ctx context.Context, ch chan<- prometheus.Metric) error {
|
2023-07-27 00:14:04 +02:00
|
|
|
var opts client.ListStoragePathsOptions
|
|
|
|
|
2023-07-03 00:16:08 +02:00
|
|
|
opts.Ordering.Field = "name"
|
|
|
|
|
|
|
|
return c.cl.ListAllStoragePaths(ctx, opts, func(_ context.Context, sp client.StoragePath) error {
|
|
|
|
id := strconv.FormatInt(sp.ID, 10)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.infoDesc, prometheus.GaugeValue, 1,
|
|
|
|
id,
|
|
|
|
sp.Name,
|
|
|
|
sp.Slug,
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.docCountDesc, prometheus.GaugeValue,
|
|
|
|
float64(sp.DocumentCount), id)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|