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