github.com/minio/madmin-go/v2@v2.2.1/perf-drive.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 "strconv" 28 ) 29 30 // DriveSpeedTestResult - result of the drive speed test 31 type DriveSpeedTestResult struct { 32 Version string `json:"version"` 33 Endpoint string `json:"endpoint"` 34 DrivePerf []DrivePerf `json:"drivePerf,omitempty"` 35 36 Error string `json:"string,omitempty"` 37 } 38 39 // DrivePerf - result of drive speed test on 1 drive mounted at path 40 type DrivePerf struct { 41 Path string `json:"path"` 42 ReadThroughput uint64 `json:"readThroughput"` 43 WriteThroughput uint64 `json:"writeThroughput"` 44 45 Error string `json:"error,omitempty"` 46 } 47 48 // DriveSpeedTestOpts provide configurable options for drive speedtest 49 type DriveSpeedTestOpts struct { 50 Serial bool // Run speed tests one drive at a time 51 BlockSize uint64 // BlockSize for read/write (default 4MiB) 52 FileSize uint64 // Total fileSize to write and read (default 1GiB) 53 } 54 55 // DriveSpeedtest - perform drive speedtest on the MinIO servers 56 func (adm *AdminClient) DriveSpeedtest(ctx context.Context, opts DriveSpeedTestOpts) (chan DriveSpeedTestResult, error) { 57 queryVals := make(url.Values) 58 if opts.Serial { 59 queryVals.Set("serial", "true") 60 } 61 queryVals.Set("blocksize", strconv.FormatUint(opts.BlockSize, 10)) 62 queryVals.Set("filesize", strconv.FormatUint(opts.FileSize, 10)) 63 resp, err := adm.executeMethod(ctx, 64 http.MethodPost, requestData{ 65 relPath: adminAPIPrefix + "/speedtest/drive", 66 queryValues: queryVals, 67 }) 68 if err != nil { 69 return nil, err 70 } 71 if resp.StatusCode != http.StatusOK { 72 return nil, httpRespToErrorResponse(resp) 73 } 74 ch := make(chan DriveSpeedTestResult) 75 go func() { 76 defer closeResponse(resp) 77 defer close(ch) 78 79 dec := json.NewDecoder(resp.Body) 80 for { 81 var result DriveSpeedTestResult 82 if err := dec.Decode(&result); err != nil { 83 return 84 } 85 select { 86 case ch <- result: 87 case <-ctx.Done(): 88 return 89 } 90 } 91 }() 92 return ch, nil 93 }