|
|
@ -41,6 +41,7 @@ import ( |
|
|
|
"github.com/minio/minio/cmd/logger" |
|
|
|
"github.com/minio/minio/cmd/logger" |
|
|
|
"github.com/minio/minio/cmd/logger/message/log" |
|
|
|
"github.com/minio/minio/cmd/logger/message/log" |
|
|
|
"github.com/minio/minio/pkg/auth" |
|
|
|
"github.com/minio/minio/pkg/auth" |
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/bandwidth" |
|
|
|
"github.com/minio/minio/pkg/handlers" |
|
|
|
"github.com/minio/minio/pkg/handlers" |
|
|
|
iampolicy "github.com/minio/minio/pkg/iam/policy" |
|
|
|
iampolicy "github.com/minio/minio/pkg/iam/policy" |
|
|
|
"github.com/minio/minio/pkg/madmin" |
|
|
|
"github.com/minio/minio/pkg/madmin" |
|
|
@ -1428,6 +1429,8 @@ func (a adminAPIHandlers) HealthInfoHandler(w http.ResponseWriter, r *http.Reque |
|
|
|
func (a adminAPIHandlers) BandwidthMonitorHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
func (a adminAPIHandlers) BandwidthMonitorHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
ctx := newContext(r, w, "BandwidthMonitor") |
|
|
|
ctx := newContext(r, w, "BandwidthMonitor") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer logger.AuditLog(w, r, "BandwidthMonitor", mustGetClaimsFromToken(r)) |
|
|
|
|
|
|
|
|
|
|
|
// Validate request signature.
|
|
|
|
// Validate request signature.
|
|
|
|
_, adminAPIErr := checkAdminRequestAuthType(ctx, r, iampolicy.BandwidthMonitorAction, "") |
|
|
|
_, adminAPIErr := checkAdminRequestAuthType(ctx, r, iampolicy.BandwidthMonitorAction, "") |
|
|
|
if adminAPIErr != ErrNone { |
|
|
|
if adminAPIErr != ErrNone { |
|
|
@ -1436,15 +1439,41 @@ func (a adminAPIHandlers) BandwidthMonitorHandler(w http.ResponseWriter, r *http |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setEventStreamHeaders(w) |
|
|
|
setEventStreamHeaders(w) |
|
|
|
|
|
|
|
reportCh := make(chan bandwidth.Report, 1) |
|
|
|
|
|
|
|
keepAliveTicker := time.NewTicker(500 * time.Millisecond) |
|
|
|
|
|
|
|
defer keepAliveTicker.Stop() |
|
|
|
bucketsRequestedString := r.URL.Query().Get("buckets") |
|
|
|
bucketsRequestedString := r.URL.Query().Get("buckets") |
|
|
|
bucketsRequested := strings.Split(bucketsRequestedString, ",") |
|
|
|
bucketsRequested := strings.Split(bucketsRequestedString, ",") |
|
|
|
consolidatedReport := globalNotificationSys.GetBandwidthReports(ctx, bucketsRequested...) |
|
|
|
go func() { |
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
reportCh <- globalNotificationSys.GetBandwidthReports(ctx, bucketsRequested...) |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
time.Sleep(2 * time.Second) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case report := <-reportCh: |
|
|
|
enc := json.NewEncoder(w) |
|
|
|
enc := json.NewEncoder(w) |
|
|
|
err := enc.Encode(consolidatedReport) |
|
|
|
err := enc.Encode(report) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInternalError), r.URL) |
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInternalError), r.URL) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
|
|
|
|
case <-keepAliveTicker.C: |
|
|
|
|
|
|
|
if _, err := w.Write([]byte(" ")); err != nil { |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
w.(http.Flusher).Flush() |
|
|
|
w.(http.Flusher).Flush() |
|
|
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ServerInfoHandler - GET /minio/admin/v3/info
|
|
|
|
// ServerInfoHandler - GET /minio/admin/v3/info
|
|
|
|