volume_server_handlers_admin.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/topology"
  4. "net/http"
  5. "path/filepath"
  6. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  7. "github.com/chrislusf/seaweedfs/weed/stats"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func (vs *VolumeServer) healthzHandler(w http.ResponseWriter, r *http.Request) {
  11. w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
  12. volumeInfos := vs.store.VolumeInfos()
  13. for _, vinfo := range volumeInfos {
  14. if len(vinfo.Collection) == 0 {
  15. continue
  16. }
  17. if vinfo.ReplicaPlacement.GetCopyCount() > 1 {
  18. _, err := topology.GetWritableRemoteReplications(vs.store, vs.grpcDialOption, vinfo.Id, vs.GetMaster)
  19. if err != nil {
  20. w.WriteHeader(http.StatusServiceUnavailable)
  21. return
  22. }
  23. }
  24. }
  25. w.WriteHeader(http.StatusOK)
  26. }
  27. func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
  28. w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
  29. m := make(map[string]interface{})
  30. m["Version"] = util.Version()
  31. var ds []*volume_server_pb.DiskStatus
  32. for _, loc := range vs.store.Locations {
  33. if dir, e := filepath.Abs(loc.Directory); e == nil {
  34. newDiskStatus := stats.NewDiskStatus(dir)
  35. newDiskStatus.DiskType = loc.DiskType.String()
  36. ds = append(ds, newDiskStatus)
  37. }
  38. }
  39. m["DiskStatuses"] = ds
  40. m["Volumes"] = vs.store.VolumeInfos()
  41. writeJsonQuiet(w, r, http.StatusOK, m)
  42. }
  43. func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  44. w.Header().Set("Server", "SeaweedFS Volume "+util.VERSION)
  45. m := make(map[string]interface{})
  46. m["Version"] = util.Version()
  47. var ds []*volume_server_pb.DiskStatus
  48. for _, loc := range vs.store.Locations {
  49. if dir, e := filepath.Abs(loc.Directory); e == nil {
  50. newDiskStatus := stats.NewDiskStatus(dir)
  51. newDiskStatus.DiskType = loc.DiskType.String()
  52. ds = append(ds, newDiskStatus)
  53. }
  54. }
  55. m["DiskStatuses"] = ds
  56. writeJsonQuiet(w, r, http.StatusOK, m)
  57. }