mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 06:15:29 +00:00
cmd/stupgrades: Basic process metrics
This commit is contained in:
parent
2f281799c1
commit
2bb5b2244b
@ -19,6 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
_ "github.com/syncthing/syncthing/lib/automaxprocs"
|
_ "github.com/syncthing/syncthing/lib/automaxprocs"
|
||||||
"github.com/syncthing/syncthing/lib/httpcache"
|
"github.com/syncthing/syncthing/lib/httpcache"
|
||||||
"github.com/syncthing/syncthing/lib/upgrade"
|
"github.com/syncthing/syncthing/lib/upgrade"
|
||||||
@ -26,6 +27,7 @@ import (
|
|||||||
|
|
||||||
type cli struct {
|
type cli struct {
|
||||||
Listen string `default:":8080" help:"Listen address"`
|
Listen string `default:":8080" help:"Listen address"`
|
||||||
|
MetricsListen string `default:":8081" help:"Listen address for metrics"`
|
||||||
URL string `short:"u" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=25" help:"GitHub releases url"`
|
URL string `short:"u" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=25" help:"GitHub releases url"`
|
||||||
Forward []string `short:"f" help:"Forwarded pages, format: /path->https://example/com/url"`
|
Forward []string `short:"f" help:"Forwarded pages, format: /path->https://example/com/url"`
|
||||||
CacheTime time.Duration `default:"15m" help:"Cache time"`
|
CacheTime time.Duration `default:"15m" help:"Cache time"`
|
||||||
@ -41,17 +43,37 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func server(params *cli) error {
|
func server(params *cli) error {
|
||||||
http.Handle("/meta.json", httpcache.SinglePath(&githubReleases{url: params.URL}, params.CacheTime))
|
if params.MetricsListen != "" {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.Handle("/metrics", promhttp.Handler())
|
||||||
|
go func() {
|
||||||
|
log.Println("Listening for metrics on", params.MetricsListen)
|
||||||
|
if err := http.ListenAndServe(params.MetricsListen, mux); err != nil {
|
||||||
|
log.Fatalf("Failed to start metrics server: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.Handle("/meta.json", httpcache.SinglePath(&githubReleases{url: params.URL}, params.CacheTime))
|
||||||
|
|
||||||
for _, fwd := range params.Forward {
|
for _, fwd := range params.Forward {
|
||||||
path, url, ok := strings.Cut(fwd, "->")
|
path, url, ok := strings.Cut(fwd, "->")
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid forward: %q", fwd)
|
return fmt.Errorf("invalid forward: %q", fwd)
|
||||||
}
|
}
|
||||||
http.Handle(path, httpcache.SinglePath(&proxy{url: url}, params.CacheTime))
|
log.Println("Forwarding", path, "to", url)
|
||||||
|
mux.Handle(path, httpcache.SinglePath(&proxy{url: url}, params.CacheTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.ListenAndServe(params.Listen, nil)
|
srv := &http.Server{
|
||||||
|
Addr: params.Listen,
|
||||||
|
Handler: mux,
|
||||||
|
ReadTimeout: 5 * time.Second,
|
||||||
|
WriteTimeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
srv.SetKeepAlivesEnabled(false)
|
||||||
|
return srv.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
type githubReleases struct {
|
type githubReleases struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user