|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package command |
|
|
|
|
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os/signal" |
|
|
|
"path/filepath" |
|
|
|
@ -13,6 +14,7 @@ import ( |
|
|
|
statsCollect "github.com/seaweedfs/seaweedfs/weed/stats" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util/grace" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util/version" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/worker" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/types" |
|
|
|
@ -24,6 +26,7 @@ import ( |
|
|
|
// TODO: Implement additional task packages (add to default capabilities when ready):
|
|
|
|
// _ "github.com/seaweedfs/seaweedfs/weed/worker/tasks/remote" - for uploading volumes to remote/cloud storage
|
|
|
|
// _ "github.com/seaweedfs/seaweedfs/weed/worker/tasks/replication" - for fixing replication issues and maintaining data consistency
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp" |
|
|
|
) |
|
|
|
|
|
|
|
var cmdWorker = &Command{ |
|
|
|
@ -57,6 +60,8 @@ var ( |
|
|
|
workerMetricsIp = cmdWorker.Flag.String("metricsIp", "0.0.0.0", "Prometheus metrics listen IP") |
|
|
|
workerDebug = cmdWorker.Flag.Bool("debug", false, "serves runtime profiling data via pprof on the port specified by -debug.port") |
|
|
|
workerDebugPort = cmdWorker.Flag.Int("debug.port", 6060, "http port for debugging") |
|
|
|
|
|
|
|
workerServerHeader = "SeaweedFS Worker " + version.VERSION |
|
|
|
) |
|
|
|
|
|
|
|
func init() { |
|
|
|
@ -257,8 +262,33 @@ type WorkerStatus struct { |
|
|
|
TasksFailed int `json:"tasks_failed"` |
|
|
|
} |
|
|
|
|
|
|
|
// startWorkerMetricsServer starts the HTTP metrics server for the worker
|
|
|
|
func startWorkerMetricsServer(ip string, port int, _ *worker.Worker) { |
|
|
|
// Use the standard SeaweedFS metrics server for consistency with other components
|
|
|
|
statsCollect.StartMetricsServer(ip, port) |
|
|
|
func workerHealthHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Server", workerServerHeader) |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
} |
|
|
|
|
|
|
|
func workerReadyHandler(workerInstance *worker.Worker) http.HandlerFunc { |
|
|
|
return func(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Server", workerServerHeader) |
|
|
|
|
|
|
|
admin := workerInstance.GetAdmin() |
|
|
|
if admin == nil || !admin.IsConnected() { |
|
|
|
w.WriteHeader(http.StatusServiceUnavailable) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func startWorkerMetricsServer(ip string, port int, w *worker.Worker) { |
|
|
|
mux := http.NewServeMux() |
|
|
|
mux.HandleFunc("/health", workerHealthHandler) |
|
|
|
mux.HandleFunc("/ready", workerReadyHandler(w)) |
|
|
|
mux.Handle("/metrics", promhttp.HandlerFor(statsCollect.Gather, promhttp.HandlerOpts{})) |
|
|
|
|
|
|
|
glog.V(0).Infof("Starting worker metrics server at %s", statsCollect.JoinHostPort(ip, port)) |
|
|
|
if err := http.ListenAndServe(statsCollect.JoinHostPort(ip, port), mux); err != nil { |
|
|
|
glog.Errorf("Worker metrics server failed to start: %v", err) |
|
|
|
} |
|
|
|
} |