adguard-exporter/main.go
Jason Ross 066fbc22c1
ci(GitHub): update tooling and dependancies (#3)
* doc(readme): replace links from ebrianne to csfreak

ebrianne's repo is no longer available

* ci(GitHub): replace master with main

* ci(GitHub): update release workflow versions

* Update go.mod

* build(docker): change dockerfile to go 1.21

* doc(readme): add attribution

* package(main): rename

* package(main): rename

* package(adguard): rename

* build(depenancies): update go dependancies

* ci(github): remove deprecated versions

* ci(github): upgrade actions

* ci(github): typo

* ci(github): adjust build and remove docker actions

* doc(readme): update links

* doc(readme): update links
2023-09-15 11:26:38 -05:00

54 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/csfreak/adguard-exporter/config"
"github.com/csfreak/adguard-exporter/internal/adguard"
"github.com/csfreak/adguard-exporter/internal/metrics"
"github.com/csfreak/adguard-exporter/internal/server"
)
const (
name = "adguard-exporter"
)
var (
s *server.Server
)
func main() {
conf := config.Load()
metrics.Init()
initAdguardClient(conf.AdguardProtocol, conf.AdguardHostname, conf.AdguardUsername, conf.AdguardPassword, conf.AdguardPort, conf.Interval, conf.LogLimit, conf.RDnsEnabled)
initHttpServer(conf.ServerPort)
handleExitSignal()
}
func initAdguardClient(protocol, hostname, username, password, port string, interval time.Duration, logLimit string, rdnsenabled bool) {
client := adguard.NewClient(protocol, hostname, username, password, port, interval, logLimit, rdnsenabled)
go client.Scrape()
}
func initHttpServer(port string) {
s = server.NewServer(port)
go s.ListenAndServe()
}
func handleExitSignal() {
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
<-stop
s.Stop()
fmt.Println(fmt.Sprintf("\n%s HTTP server stopped", name))
}