mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
feat: add new telemetry server (#254)
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
48
telemetry/telemetry.go
Normal file
48
telemetry/telemetry.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Package telemetry provides telemetry information for SFTPGo, such as:
|
||||
// - health information (for health checks)
|
||||
// - metrics
|
||||
// - profiling information
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/drakkan/sftpgo/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
logSender = "telemetry"
|
||||
metricsPath = "/metrics"
|
||||
pprofBasePath = "/debug"
|
||||
)
|
||||
|
||||
var (
|
||||
router *chi.Mux
|
||||
)
|
||||
|
||||
// Conf telemetry server configuration.
|
||||
type Conf struct {
|
||||
// The port used for serving HTTP requests. 0 disable the HTTP server. Default: 8080
|
||||
BindPort int `json:"bind_port" mapstructure:"bind_port"`
|
||||
// The address to listen on. A blank value means listen on all available network interfaces. Default: "127.0.0.1"
|
||||
BindAddress string `json:"bind_address" mapstructure:"bind_address"`
|
||||
}
|
||||
|
||||
// Initialize configures and starts the telemetry server.
|
||||
func (c Conf) Initialize(enableProfiler bool) error {
|
||||
logger.Debug(logSender, "", "initializing telemetry server with config %+v", c)
|
||||
initializeRouter(enableProfiler)
|
||||
httpServer := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", c.BindAddress, c.BindPort),
|
||||
Handler: router,
|
||||
ReadTimeout: 60 * time.Second,
|
||||
WriteTimeout: 60 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
MaxHeaderBytes: 1 << 16, // 64KB
|
||||
}
|
||||
return httpServer.ListenAndServe()
|
||||
}
|
||||
Reference in New Issue
Block a user