2024-10-31 20:42:28 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"recycled.cloud/app-exporter/apps"
|
|
|
|
)
|
|
|
|
|
2024-11-01 19:34:36 +01:00
|
|
|
// var so it can be overridden at build time
|
|
|
|
var VERSION = "dev"
|
2024-10-31 20:42:28 +01:00
|
|
|
|
|
|
|
const LISTEN_ADDR = ":9404"
|
|
|
|
const INTERVAL = 24 * time.Hour
|
|
|
|
|
|
|
|
var version_flag = flag.Bool("version", false, "Shows the program version")
|
|
|
|
var logfile = flag.String("logfile", "-", "Where to write the logs")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *version_flag {
|
|
|
|
fmt.Printf("%v\n", VERSION)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *logfile != "-" {
|
|
|
|
f, err := os.OpenFile(*logfile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0664)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Could not open logfile: %v\n", err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
|
|
|
|
log.Printf("app-exporter version %v\n", VERSION)
|
|
|
|
|
|
|
|
m := apps.NewMetrics(reg)
|
|
|
|
|
|
|
|
go RecordMetrics(*m)
|
|
|
|
|
|
|
|
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
|
|
|
|
|
|
|
|
log.Printf("Listening on %v ...\n", LISTEN_ADDR)
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(LISTEN_ADDR, nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func RecordMetrics(m apps.Metrics) {
|
2024-11-15 16:47:30 +01:00
|
|
|
// export the app-exporter version
|
2024-11-20 10:25:30 +01:00
|
|
|
m.Version.With(prometheus.Labels{"version": VERSION}).Set(1)
|
2024-11-15 16:47:30 +01:00
|
|
|
|
2024-10-31 20:42:28 +01:00
|
|
|
for {
|
|
|
|
m.Reset()
|
|
|
|
|
|
|
|
apps.Cubebackup(m)
|
|
|
|
apps.Forgejo(m)
|
|
|
|
apps.ForgejoRunner(m)
|
|
|
|
apps.Grafana(m)
|
2024-11-15 14:20:05 +01:00
|
|
|
apps.Minio(m)
|
2024-10-31 20:42:28 +01:00
|
|
|
apps.Nextcloud(m)
|
|
|
|
apps.Odoo(m)
|
|
|
|
apps.Postgres(m)
|
|
|
|
apps.Vaultwarden(m)
|
|
|
|
|
|
|
|
log.Printf("> Waiting %v\n", INTERVAL)
|
|
|
|
time.Sleep(INTERVAL)
|
|
|
|
}
|
|
|
|
}
|