mirror of
https://git.friendi.ca/friendica/friendica-exporter.git
synced 2025-06-07 09:54:26 +02:00
Initial Release
This commit is contained in:
commit
76ec4ba39f
31 changed files with 3023 additions and 0 deletions
79
main.go
Normal file
79
main.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"friendica-exporter/internal/client"
|
||||
"friendica-exporter/internal/config"
|
||||
"friendica-exporter/internal/metrics"
|
||||
"friendica-exporter/serverinfo"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version contains the version as set during build.
|
||||
Version = ""
|
||||
|
||||
// GitCommit contains the git commit hash set during the build.
|
||||
GitCommit = ""
|
||||
|
||||
log = &logrus.Logger{
|
||||
Out: os.Stderr,
|
||||
Formatter: &logrus.TextFormatter{
|
||||
DisableTimestamp: true,
|
||||
},
|
||||
Hooks: make(logrus.LevelHooks),
|
||||
Level: logrus.InfoLevel,
|
||||
ExitFunc: os.Exit,
|
||||
ReportCaller: false,
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := config.Get()
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading configuration: %s", err)
|
||||
}
|
||||
|
||||
if cfg.RunMode == config.RunModeHelp {
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.RunMode == config.RunModeVersion {
|
||||
fmt.Println(Version)
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("friendica-exporter %s", Version)
|
||||
userAgent := fmt.Sprintf("friendica-exporter/%s", Version)
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
log.Fatalf("Error validating configuration: %s", err)
|
||||
}
|
||||
|
||||
log.Infof("Friendica server: %s Authentication using token.", cfg.ServerURL)
|
||||
|
||||
statsUrl := serverinfo.StatsURL(cfg.ServerURL, cfg.StatsToken)
|
||||
|
||||
if cfg.TLSSkipVerify {
|
||||
log.Warn("HTTPS certificate verification is disabled.")
|
||||
}
|
||||
|
||||
statsClient := client.New(statsUrl, cfg.Timeout, userAgent, cfg.TLSSkipVerify)
|
||||
if err := metrics.RegisterCollector(log, statsClient); err != nil {
|
||||
log.Fatalf("Failed to register collector: %s", err)
|
||||
}
|
||||
|
||||
if err := metrics.RegisterStatsMetrics(Version, GitCommit); err != nil {
|
||||
log.Fatalf("Failed to register info metrics: %s", err)
|
||||
}
|
||||
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
http.Handle("/", http.RedirectHandler("/metrics", http.StatusFound))
|
||||
|
||||
log.Infof("Listen on %s...", cfg.ListenAddr)
|
||||
log.Fatal(http.ListenAndServe(cfg.ListenAddr, nil))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue