2014-04-14 07:13:18 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
2022-02-16 09:18:36 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/topology"
|
2018-10-15 08:19:15 +00:00
|
|
|
"net/http"
|
|
|
|
"path/filepath"
|
2018-10-16 04:44:41 +00:00
|
|
|
|
2018-10-24 06:59:49 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
2018-10-16 04:44:41 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/stats"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2014-04-14 07:13:18 +00:00
|
|
|
)
|
|
|
|
|
2022-02-16 09:18:36 +00:00
|
|
|
func (vs *VolumeServer) healthzHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
|
|
|
|
volumeInfos := vs.store.VolumeInfos()
|
|
|
|
for _, vinfo := range volumeInfos {
|
|
|
|
if len(vinfo.Collection) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if vinfo.ReplicaPlacement.GetCopyCount() > 1 {
|
|
|
|
_, err := topology.GetWritableRemoteReplications(vs.store, vs.grpcDialOption, vinfo.Id, vs.GetMaster)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2014-04-14 07:13:18 +00:00
|
|
|
func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
|
2020-09-20 23:00:01 +00:00
|
|
|
w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
|
2014-04-14 07:13:18 +00:00
|
|
|
m := make(map[string]interface{})
|
2020-06-02 07:10:35 +00:00
|
|
|
m["Version"] = util.Version()
|
2020-02-23 21:27:09 +00:00
|
|
|
var ds []*volume_server_pb.DiskStatus
|
|
|
|
for _, loc := range vs.store.Locations {
|
|
|
|
if dir, e := filepath.Abs(loc.Directory); e == nil {
|
2020-12-14 08:51:57 +00:00
|
|
|
newDiskStatus := stats.NewDiskStatus(dir)
|
2021-02-13 23:42:42 +00:00
|
|
|
newDiskStatus.DiskType = loc.DiskType.String()
|
2020-12-14 08:51:57 +00:00
|
|
|
ds = append(ds, newDiskStatus)
|
2020-02-23 21:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m["DiskStatuses"] = ds
|
2019-12-03 04:49:50 +00:00
|
|
|
m["Volumes"] = vs.store.VolumeInfos()
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusOK, m)
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
|
2020-09-20 23:00:01 +00:00
|
|
|
w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
|
2014-04-14 07:13:18 +00:00
|
|
|
m := make(map[string]interface{})
|
2020-06-02 07:10:35 +00:00
|
|
|
m["Version"] = util.Version()
|
2018-10-16 05:25:28 +00:00
|
|
|
var ds []*volume_server_pb.DiskStatus
|
2014-04-14 07:13:18 +00:00
|
|
|
for _, loc := range vs.store.Locations {
|
|
|
|
if dir, e := filepath.Abs(loc.Directory); e == nil {
|
2020-12-14 08:51:57 +00:00
|
|
|
newDiskStatus := stats.NewDiskStatus(dir)
|
2021-02-13 23:42:42 +00:00
|
|
|
newDiskStatus.DiskType = loc.DiskType.String()
|
2020-12-14 08:51:57 +00:00
|
|
|
ds = append(ds, newDiskStatus)
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-19 17:39:22 +00:00
|
|
|
m["DiskStatuses"] = ds
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusOK, m)
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|