sys-exporter/cmd/server/main.go

55 lines
1.3 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/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)
}
logger, err := conf.ZapConfig().Build()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to init logger: %s\n", err)
os.Exit(1)
}
logger.Info("Starting server")
registry.R.Run(context.Background())
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")
}