github.com/minio/madmin-go/v3@v3.0.51/perf-site-replication.go (about)

     1  //
     2  // Copyright (c) 2015-2023 MinIO, Inc.
     3  //
     4  // This file is part of MinIO Object Storage stack
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as
     8  // published by the Free Software Foundation, either version 3 of the
     9  // License, or (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package madmin
    21  
    22  import (
    23  	"context"
    24  	"encoding/json"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  )
    29  
    30  // SiteNetPerfNodeResult  - stats from each server
    31  type SiteNetPerfNodeResult struct {
    32  	Endpoint        string        `json:"endpoint"`
    33  	TX              uint64        `json:"tx"` // transfer rate in bytes
    34  	TXTotalDuration time.Duration `json:"txTotalDuration"`
    35  	RX              uint64        `json:"rx"` // received rate in bytes
    36  	RXTotalDuration time.Duration `json:"rxTotalDuration"`
    37  	TotalConn       uint64        `json:"totalConn"`
    38  	Error           string        `json:"error,omitempty"`
    39  }
    40  
    41  // SiteNetPerfResult  - aggregate results from all servers
    42  type SiteNetPerfResult struct {
    43  	NodeResults []SiteNetPerfNodeResult `json:"nodeResults"`
    44  }
    45  
    46  // SiteReplicationPerf - perform site-replication on the MinIO servers
    47  func (adm *AdminClient) SiteReplicationPerf(ctx context.Context, duration time.Duration) (result SiteNetPerfResult, err error) {
    48  	queryVals := make(url.Values)
    49  	queryVals.Set("duration", duration.String())
    50  
    51  	resp, err := adm.executeMethod(ctx,
    52  		http.MethodPost, requestData{
    53  			relPath:     adminAPIPrefix + "/speedtest/site",
    54  			queryValues: queryVals,
    55  		})
    56  	if err != nil {
    57  		return result, err
    58  	}
    59  	defer closeResponse(resp)
    60  	if resp.StatusCode != http.StatusOK {
    61  		return result, httpRespToErrorResponse(resp)
    62  	}
    63  	err = json.NewDecoder(resp.Body).Decode(&result)
    64  	return result, err
    65  }