You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

4 years ago
4 years ago
  1. package weed_server
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/topology"
  4. "net/http"
  5. "path/filepath"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  7. "github.com/seaweedfs/seaweedfs/weed/stats"
  8. "github.com/seaweedfs/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. }