2024-11-25 17:46:11 +00:00
|
|
|
package main
|
|
|
|
|
2024-12-01 16:00:52 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2024-12-02 17:04:50 +00:00
|
|
|
"flag"
|
2024-12-01 16:00:52 +00:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-12-02 17:04:50 +00:00
|
|
|
"os"
|
2024-12-01 16:00:52 +00:00
|
|
|
|
2024-12-02 17:04:50 +00:00
|
|
|
"git.faercol.me/monitoring/sys-exporter/config"
|
2024-12-01 16:00:52 +00:00
|
|
|
"git.faercol.me/monitoring/sys-exporter/registry"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
|
2024-12-01 17:12:19 +00:00
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/loadavg"
|
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/meminfo"
|
2024-12-01 16:00:52 +00:00
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/pacman"
|
2024-12-07 16:19:05 +00:00
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/sysinfo"
|
2024-12-01 17:12:19 +00:00
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/systemd"
|
2024-12-01 16:00:52 +00:00
|
|
|
_ "git.faercol.me/monitoring/sys-exporter/collector/uptime"
|
|
|
|
)
|
|
|
|
|
2024-12-02 17:04:50 +00:00
|
|
|
var confFileLocation string
|
|
|
|
|
2024-12-01 16:00:52 +00:00
|
|
|
// type gatherer struct {
|
|
|
|
// reg *prometheus.Registry
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (g *gatherer) Gather() (pcm.MetricFamily, error) {
|
|
|
|
// return g.reg.
|
|
|
|
// }
|
2024-11-25 17:46:11 +00:00
|
|
|
|
|
|
|
func main() {
|
2024-12-02 17:04:50 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
conf, err := config.New(confFileLocation)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to open configuration: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2024-12-02 17:37:19 +00:00
|
|
|
rawL, err := conf.ZapConfig().Build()
|
2024-12-02 17:04:50 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to init logger: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-12-02 17:37:19 +00:00
|
|
|
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?")
|
|
|
|
}
|
2024-12-01 16:00:52 +00:00
|
|
|
|
2024-12-02 17:04:50 +00:00
|
|
|
logger.Info("Starting server")
|
2024-12-02 17:37:19 +00:00
|
|
|
registry.R.Run(context.Background(), conf, logger)
|
2024-12-01 16:00:52 +00:00
|
|
|
|
|
|
|
http.Handle("/metrics", promhttp.HandlerFor(registry.R.PromRegistry(), promhttp.HandlerOpts{}))
|
|
|
|
http.ListenAndServe(":2112", nil)
|
2024-11-25 17:46:11 +00:00
|
|
|
}
|
2024-12-02 17:04:50 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&confFileLocation, "config", config.DefaultConfigFileLocation, "Location of the config file")
|
|
|
|
}
|