github.com/minio/madmin-go/v3@v3.0.51/examples/bucket-bandwidth.go (about)

     1  //
     2  //go:build ignore
     3  // +build ignore
     4  
     5  //
     6  // Copyright (c) 2015-2022 MinIO, Inc.
     7  //
     8  // This file is part of MinIO Object Storage stack
     9  //
    10  // This program is free software: you can redistribute it and/or modify
    11  // it under the terms of the GNU Affero General Public License as
    12  // published by the Free Software Foundation, either version 3 of the
    13  // License, or (at your option) any later version.
    14  //
    15  // This program is distributed in the hope that it will be useful,
    16  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  // GNU Affero General Public License for more details.
    19  //
    20  // You should have received a copy of the GNU Affero General Public License
    21  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    22  //
    23  
    24  package main
    25  
    26  import (
    27  	"context"
    28  	"fmt"
    29  	"log"
    30  
    31  	"github.com/minio/madmin-go/v3"
    32  )
    33  
    34  func main() {
    35  	// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
    36  	// dummy values, please replace them with original values.
    37  
    38  	// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
    39  	// New returns an MinIO Admin client object.
    40  	madminClient, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
    41  	if err != nil {
    42  		log.Fatalln(err)
    43  	}
    44  	ctx := context.Background()
    45  	reportCh := madminClient.GetBucketBandwidth(ctx)
    46  
    47  	for i := 0; i < 10; i++ {
    48  		report := <-reportCh
    49  		fmt.Printf("Report: %+v\n", report)
    50  	}
    51  	reportCh = madminClient.GetBucketBandwidth(ctx, "sourceBucket", "sourceBucket2")
    52  	for i := 0; i < 10; i++ {
    53  		report := <-reportCh
    54  		fmt.Printf("Report: %+v\n", report)
    55  	}
    56  }