github.com/minio/madmin-go@v1.7.5/examples/bucket-bandwidth.go (about)

     1  //
     2  // MinIO Object Storage (c) 2021 MinIO, Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //      http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package main
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"log"
    23  
    24  	"github.com/minio/madmin-go"
    25  )
    26  
    27  func main() {
    28  	// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
    29  	// dummy values, please replace them with original values.
    30  
    31  	// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
    32  	// New returns an MinIO Admin client object.
    33  	madminClient, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
    34  	if err != nil {
    35  		log.Fatalln(err)
    36  	}
    37  	ctx := context.Background()
    38  	reportCh := madminClient.GetBucketBandwidth(ctx)
    39  
    40  	for i := 0; i < 10; i++ {
    41  		report := <-reportCh
    42  		fmt.Printf("Report: %+v\n", report)
    43  	}
    44  	reportCh = madminClient.GetBucketBandwidth(ctx, "sourceBucket", "sourceBucket2")
    45  	for i := 0; i < 10; i++ {
    46  		report := <-reportCh
    47  		fmt.Printf("Report: %+v\n", report)
    48  	}
    49  }