github.com/minio/madmin-go/v2@v2.2.1/perf-net.go (about) 1 // 2 // Copyright (c) 2015-2022 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 // NetperfNodeResult - stats from each server 31 type NetperfNodeResult struct { 32 Endpoint string `json:"endpoint"` 33 TX uint64 `json:"tx"` 34 RX uint64 `json:"rx"` 35 Error string `json:"error,omitempty"` 36 } 37 38 // NetperfResult - aggregate results from all servers 39 type NetperfResult struct { 40 NodeResults []NetperfNodeResult `json:"nodeResults"` 41 } 42 43 // Netperf - perform netperf on the MinIO servers 44 func (adm *AdminClient) Netperf(ctx context.Context, duration time.Duration) (result NetperfResult, err error) { 45 queryVals := make(url.Values) 46 queryVals.Set("duration", duration.String()) 47 48 resp, err := adm.executeMethod(ctx, 49 http.MethodPost, requestData{ 50 relPath: adminAPIPrefix + "/speedtest/net", 51 queryValues: queryVals, 52 }) 53 if err != nil { 54 return result, err 55 } 56 if resp.StatusCode != http.StatusOK { 57 return result, httpRespToErrorResponse(resp) 58 } 59 err = json.NewDecoder(resp.Body).Decode(&result) 60 return result, err 61 }