|
|
@ -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() { |
|
|
|
enc := json.NewEncoder(w) |
|
|
|
for { |
|
|
|
err := enc.Encode(consolidatedReport) |
|
|
|
reportCh <- globalNotificationSys.GetBandwidthReports(ctx, bucketsRequested...) |
|
|
|
if err != nil { |
|
|
|
select { |
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInternalError), r.URL) |
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
time.Sleep(2 * time.Second) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case report := <-reportCh: |
|
|
|
|
|
|
|
enc := json.NewEncoder(w) |
|
|
|
|
|
|
|
err := enc.Encode(report) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
w.(http.Flusher).Flush() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ServerInfoHandler - GET /minio/admin/v3/info
|
|
|
|
// ServerInfoHandler - GET /minio/admin/v3/info
|
|
|
|