Compare commits
No commits in common. "main" and "0.1.0" have entirely different histories.
5 changed files with 10 additions and 64 deletions
14
buffer.go
14
buffer.go
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
type MetricsBuffer struct {
|
||||
RepoName string
|
||||
ArchiveCount float64
|
||||
LastArchiveTime float64
|
||||
LastModified float64
|
||||
TotalChunks float64
|
||||
TotalCsize float64
|
||||
TotalSize float64
|
||||
TotalUniqueChunks float64
|
||||
UniqueCsize float64
|
||||
UniqueSize float64
|
||||
}
|
1
info.go
1
info.go
|
@ -34,7 +34,6 @@ func (info *Info) LastmodUnix() float64 {
|
|||
func GetInfo(path string) (*Info, error) {
|
||||
cmd := exec.Command("borg", "info", "--json", path)
|
||||
cmd.Env = append(cmd.Env, "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes")
|
||||
cmd.Env = append(cmd.Env, "BORG_RELOCATED_REPO_ACCESS_IS_OK=yes")
|
||||
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
|
|
1
list.go
1
list.go
|
@ -28,7 +28,6 @@ func (list *List) LastArchiveUnix() float64 {
|
|||
func GetList(path string) (*List, error) {
|
||||
cmd := exec.Command("borg", "list", "--json", path)
|
||||
cmd.Env = append(cmd.Env, "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes")
|
||||
cmd.Env = append(cmd.Env, "BORG_RELOCATED_REPO_ACCESS_IS_OK=yes")
|
||||
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
|
|
25
main.go
25
main.go
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
const VERSION = "1.0.0"
|
||||
const VERSION = "0.1.0"
|
||||
|
||||
const LISTEN_ADDR = ":9403"
|
||||
const INTERVAL = 30 * time.Minute
|
||||
|
@ -62,7 +62,6 @@ func RecordMetrics(m Metrics) {
|
|||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
buffer := []MetricsBuffer{}
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
|
||||
log.Printf(">> Ignoring %v\n", entry.Name())
|
||||
|
@ -85,21 +84,17 @@ func RecordMetrics(m Metrics) {
|
|||
stats := info.Cache.Stats
|
||||
|
||||
log.Printf("> Got info for: %v\n", path)
|
||||
buffer = append(buffer, MetricsBuffer{
|
||||
RepoName: entry.Name(),
|
||||
ArchiveCount: float64(len(list.Archives)),
|
||||
LastArchiveTime: list.LastArchiveUnix(),
|
||||
LastModified: info.LastmodUnix(),
|
||||
TotalChunks: stats.Total_chunks,
|
||||
TotalCsize: stats.Total_csize,
|
||||
TotalSize: stats.Total_size,
|
||||
TotalUniqueChunks: stats.Total_unique_chunks,
|
||||
UniqueCsize: stats.Unique_csize,
|
||||
UniqueSize: stats.Unique_size,
|
||||
})
|
||||
m.ArchiveCount.With(prometheus.Labels{"repo_name": entry.Name()}).Set(float64(len(list.Archives)))
|
||||
m.LastArchiveTime.With(prometheus.Labels{"repo_name": entry.Name()}).Set(list.LastArchiveUnix())
|
||||
m.LastModified.With(prometheus.Labels{"repo_name": entry.Name()}).Set(info.LastmodUnix())
|
||||
m.TotalChunks.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Total_chunks)
|
||||
m.TotalCsize.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Total_csize)
|
||||
m.TotalSize.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Total_size)
|
||||
m.TotalUniqueChunks.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Total_unique_chunks)
|
||||
m.UniqueCsize.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Unique_csize)
|
||||
m.UniqueSize.With(prometheus.Labels{"repo_name": entry.Name()}).Set(stats.Unique_size)
|
||||
}
|
||||
|
||||
m.Update(buffer)
|
||||
log.Printf("> Waiting %v\n", INTERVAL)
|
||||
time.Sleep(INTERVAL)
|
||||
}
|
||||
|
|
33
metrics.go
33
metrics.go
|
@ -41,36 +41,3 @@ func NewMetrics(reg prometheus.Registerer) *Metrics {
|
|||
|
||||
return metrics
|
||||
}
|
||||
|
||||
// Reset all metrics
|
||||
//
|
||||
// This should be called on every loop iteration.
|
||||
func (m *Metrics) Reset() {
|
||||
m.ArchiveCount.Reset()
|
||||
m.LastArchiveTime.Reset()
|
||||
m.LastModified.Reset()
|
||||
m.TotalChunks.Reset()
|
||||
m.TotalCsize.Reset()
|
||||
m.TotalSize.Reset()
|
||||
m.TotalUniqueChunks.Reset()
|
||||
m.UniqueCsize.Reset()
|
||||
m.UniqueSize.Reset()
|
||||
}
|
||||
|
||||
// Update these metrics with the given buffer.
|
||||
//
|
||||
// Resets the metrics beforehand. Expected to be called on every loop iteration.
|
||||
func (m *Metrics) Update(buffer []MetricsBuffer) {
|
||||
m.Reset()
|
||||
for _, buf := range buffer {
|
||||
m.ArchiveCount.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.ArchiveCount)
|
||||
m.LastArchiveTime.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.LastArchiveTime)
|
||||
m.LastModified.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.LastModified)
|
||||
m.TotalChunks.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.TotalChunks)
|
||||
m.TotalCsize.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.TotalCsize)
|
||||
m.TotalSize.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.TotalSize)
|
||||
m.TotalUniqueChunks.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.TotalUniqueChunks)
|
||||
m.UniqueCsize.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.UniqueCsize)
|
||||
m.UniqueSize.With(prometheus.Labels{"repo_name": buf.RepoName}).Set(buf.UniqueSize)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue