sys-exporter/cmd/server/main.go
Melora Hugues 5df32a9b98
All checks were successful
/ go-test (push) Successful in 9m48s
Add sysinfo collector
2024-12-07 17:19:05 +01:00

63 lines
1.6 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"net/http"
"os"
"git.faercol.me/monitoring/sys-exporter/config"
"git.faercol.me/monitoring/sys-exporter/registry"
"github.com/prometheus/client_golang/prometheus/promhttp"
_ "git.faercol.me/monitoring/sys-exporter/collector/loadavg"
_ "git.faercol.me/monitoring/sys-exporter/collector/meminfo"
_ "git.faercol.me/monitoring/sys-exporter/collector/pacman"
_ "git.faercol.me/monitoring/sys-exporter/collector/sysinfo"
_ "git.faercol.me/monitoring/sys-exporter/collector/systemd"
_ "git.faercol.me/monitoring/sys-exporter/collector/uptime"
)
var confFileLocation string
// type gatherer struct {
// reg *prometheus.Registry
// }
// func (g *gatherer) Gather() (pcm.MetricFamily, error) {
// return g.reg.
// }
func main() {
flag.Parse()
conf, err := config.New(confFileLocation)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open configuration: %s\n", err)
os.Exit(1)
}
rawL, err := conf.ZapConfig().Build()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to init logger: %s\n", err)
os.Exit(1)
}
logger := rawL.Sugar()
logger.Infof("Initialized logger to %v level", logger.Level())
logger.Infof("Loading %d collectors", len(conf.Collectors))
if len(conf.Collectors) == 0 {
logger.Warn("No collector present in the config, is this expected?")
}
logger.Info("Starting server")
registry.R.Run(context.Background(), conf, logger)
http.Handle("/metrics", promhttp.HandlerFor(registry.R.PromRegistry(), promhttp.HandlerOpts{}))
http.ListenAndServe(":2112", nil)
}
func init() {
flag.StringVar(&confFileLocation, "config", config.DefaultConfigFileLocation, "Location of the config file")
}