2023-11-13 12:04:27 +09:00
|
|
|
//go:build client
|
2023-11-13 11:35:52 +09:00
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
|
|
|
|
"repositories.action2quare.com/ayo/houston/client"
|
|
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
|
_ "net/http/pprof"
|
|
|
|
|
"os"
|
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
|
|
"github.com/prometheus/common/promlog"
|
|
|
|
|
"github.com/prometheus/common/promlog/flag"
|
|
|
|
|
|
|
|
|
|
"github.com/alecthomas/kingpin/v2"
|
|
|
|
|
"github.com/prometheus/common/version"
|
|
|
|
|
"github.com/prometheus/exporter-toolkit/web"
|
|
|
|
|
"github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
runtime.GOMAXPROCS(1)
|
|
|
|
|
|
|
|
|
|
flagx.Parse()
|
|
|
|
|
|
|
|
|
|
hc, err := client.NewClient(true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9100")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
promlogConfig := &promlog.Config{}
|
|
|
|
|
flag.AddFlags(kingpin.CommandLine, promlogConfig)
|
|
|
|
|
kingpin.Version(version.Print("node_exporter"))
|
|
|
|
|
kingpin.CommandLine.UsageWriter(os.Stdout)
|
|
|
|
|
kingpin.HelpFlag.Short('h')
|
|
|
|
|
kingpin.Parse()
|
|
|
|
|
logger := promlog.New(promlogConfig)
|
|
|
|
|
|
|
|
|
|
http.Handle("/metrics", client.NewHandlerForNodeExporter(true, 2, logger))
|
|
|
|
|
|
|
|
|
|
server := &http.Server{}
|
|
|
|
|
go web.ListenAndServe(server, toolkitFlags, logger)
|
|
|
|
|
|
|
|
|
|
hc.Start()
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
|
server.Shutdown(ctx)
|
|
|
|
|
cancel()
|
|
|
|
|
}
|