2017-02-15 13:45:45 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2017 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package madmin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2018-12-31 12:46:44 -05:00
|
|
|
"net/url"
|
2017-02-15 13:45:45 -05:00
|
|
|
"time"
|
2018-12-31 12:46:44 -05:00
|
|
|
|
2019-01-09 22:04:19 -05:00
|
|
|
"github.com/minio/minio/pkg/cpu"
|
2018-12-31 12:46:44 -05:00
|
|
|
"github.com/minio/minio/pkg/disk"
|
2019-01-09 22:04:19 -05:00
|
|
|
"github.com/minio/minio/pkg/mem"
|
2017-02-15 13:45:45 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// BackendType - represents different backend types.
|
|
|
|
type BackendType int
|
|
|
|
|
|
|
|
// Enum for different backend types.
|
|
|
|
const (
|
|
|
|
Unknown BackendType = iota
|
|
|
|
// Filesystem backend.
|
|
|
|
FS
|
|
|
|
// Multi disk Erasure (single, distributed) backend.
|
|
|
|
Erasure
|
|
|
|
|
|
|
|
// Add your own backend.
|
|
|
|
)
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// DriveInfo - represents each drive info, describing
|
|
|
|
// status, uuid and endpoint.
|
|
|
|
type DriveInfo HealDriveInfo
|
|
|
|
|
2017-02-15 13:45:45 -05:00
|
|
|
// StorageInfo - represents total capacity of underlying storage.
|
|
|
|
type StorageInfo struct {
|
2018-05-23 20:30:25 -04:00
|
|
|
Used uint64 // Total used spaced per tenant.
|
2018-05-23 06:11:29 -04:00
|
|
|
|
2017-02-15 13:45:45 -05:00
|
|
|
// Backend type.
|
|
|
|
Backend struct {
|
|
|
|
// Represents various backend types, currently on FS and Erasure.
|
|
|
|
Type BackendType
|
|
|
|
|
|
|
|
// Following fields are only meaningful if BackendType is Erasure.
|
2018-01-11 21:22:52 -05:00
|
|
|
OnlineDisks int // Online disks during server startup.
|
|
|
|
OfflineDisks int // Offline disks during server startup.
|
2018-02-15 20:45:57 -05:00
|
|
|
StandardSCData int // Data disks for currently configured Standard storage class.
|
2018-01-11 21:22:52 -05:00
|
|
|
StandardSCParity int // Parity disks for currently configured Standard storage class.
|
2018-02-15 20:45:57 -05:00
|
|
|
RRSCData int // Data disks for currently configured Reduced Redundancy storage class.
|
2018-01-11 21:22:52 -05:00
|
|
|
RRSCParity int // Parity disks for currently configured Reduced Redundancy storage class.
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
// List of all disk status, this is only meaningful if BackendType is Erasure.
|
|
|
|
Sets [][]DriveInfo
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerProperties holds some of the server's information such as uptime,
|
|
|
|
// version, region, ..
|
|
|
|
type ServerProperties struct {
|
|
|
|
Uptime time.Duration `json:"uptime"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
CommitID string `json:"commitID"`
|
|
|
|
Region string `json:"region"`
|
|
|
|
SQSARN []string `json:"sqsARN"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerConnStats holds network information
|
|
|
|
type ServerConnStats struct {
|
|
|
|
TotalInputBytes uint64 `json:"transferred"`
|
|
|
|
TotalOutputBytes uint64 `json:"received"`
|
|
|
|
}
|
|
|
|
|
2017-12-22 20:47:30 -05:00
|
|
|
// ServerHTTPMethodStats holds total number of HTTP operations from/to the server,
|
|
|
|
// including the average duration the call was spent.
|
|
|
|
type ServerHTTPMethodStats struct {
|
|
|
|
Count uint64 `json:"count"`
|
|
|
|
AvgDuration string `json:"avgDuration"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerHTTPStats holds all type of http operations performed to/from the server
|
|
|
|
// including their average execution time.
|
|
|
|
type ServerHTTPStats struct {
|
|
|
|
TotalHEADStats ServerHTTPMethodStats `json:"totalHEADs"`
|
|
|
|
SuccessHEADStats ServerHTTPMethodStats `json:"successHEADs"`
|
|
|
|
TotalGETStats ServerHTTPMethodStats `json:"totalGETs"`
|
|
|
|
SuccessGETStats ServerHTTPMethodStats `json:"successGETs"`
|
|
|
|
TotalPUTStats ServerHTTPMethodStats `json:"totalPUTs"`
|
|
|
|
SuccessPUTStats ServerHTTPMethodStats `json:"successPUTs"`
|
|
|
|
TotalPOSTStats ServerHTTPMethodStats `json:"totalPOSTs"`
|
|
|
|
SuccessPOSTStats ServerHTTPMethodStats `json:"successPOSTs"`
|
|
|
|
TotalDELETEStats ServerHTTPMethodStats `json:"totalDELETEs"`
|
|
|
|
SuccessDELETEStats ServerHTTPMethodStats `json:"successDELETEs"`
|
|
|
|
}
|
|
|
|
|
2017-04-21 10:15:53 -04:00
|
|
|
// ServerInfoData holds storage, connections and other
|
|
|
|
// information of a given server
|
|
|
|
type ServerInfoData struct {
|
2017-02-15 13:45:45 -05:00
|
|
|
StorageInfo StorageInfo `json:"storage"`
|
|
|
|
ConnStats ServerConnStats `json:"network"`
|
2017-12-22 20:47:30 -05:00
|
|
|
HTTPStats ServerHTTPStats `json:"http"`
|
2017-02-15 13:45:45 -05:00
|
|
|
Properties ServerProperties `json:"server"`
|
|
|
|
}
|
|
|
|
|
2017-04-21 10:15:53 -04:00
|
|
|
// ServerInfo holds server information result of one node
|
|
|
|
type ServerInfo struct {
|
2017-05-15 10:28:47 -04:00
|
|
|
Error string `json:"error"`
|
2017-04-21 10:15:53 -04:00
|
|
|
Addr string `json:"addr"`
|
|
|
|
Data *ServerInfoData `json:"data"`
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:45:45 -05:00
|
|
|
// ServerInfo - Connect to a minio server and call Server Info Management API
|
|
|
|
// to fetch server's information represented by ServerInfo structure
|
2017-04-21 10:15:53 -04:00
|
|
|
func (adm *AdminClient) ServerInfo() ([]ServerInfo, error) {
|
2018-01-22 17:54:55 -05:00
|
|
|
resp, err := adm.executeMethod("GET", requestData{relPath: "/v1/info"})
|
2017-02-15 13:45:45 -05:00
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
2017-04-21 10:15:53 -04:00
|
|
|
return nil, err
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check response http status code
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2017-04-21 10:15:53 -04:00
|
|
|
return nil, httpRespToErrorResponse(resp)
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal the server's json response
|
2017-04-21 10:15:53 -04:00
|
|
|
var serversInfo []ServerInfo
|
2017-02-15 13:45:45 -05:00
|
|
|
|
|
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2017-04-21 10:15:53 -04:00
|
|
|
return nil, err
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:15:53 -04:00
|
|
|
err = json.Unmarshal(respBytes, &serversInfo)
|
2017-02-15 13:45:45 -05:00
|
|
|
if err != nil {
|
2017-04-21 10:15:53 -04:00
|
|
|
return nil, err
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:15:53 -04:00
|
|
|
return serversInfo, nil
|
2017-02-15 13:45:45 -05:00
|
|
|
}
|
2018-12-31 12:46:44 -05:00
|
|
|
|
|
|
|
// ServerDrivesPerfInfo holds informantion about address and write speed of
|
|
|
|
// all drives in a single server node
|
|
|
|
type ServerDrivesPerfInfo struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
Perf []disk.Performance `json:"perf"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerDrivesPerfInfo - Returns drive's read and write performance information
|
|
|
|
func (adm *AdminClient) ServerDrivesPerfInfo() ([]ServerDrivesPerfInfo, error) {
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("perfType", string("drive"))
|
|
|
|
resp, err := adm.executeMethod("GET", requestData{
|
|
|
|
relPath: "/v1/performance",
|
|
|
|
queryValues: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check response http status code
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return nil, httpRespToErrorResponse(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal the server's json response
|
|
|
|
var info []ServerDrivesPerfInfo
|
|
|
|
|
|
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(respBytes, &info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|
2019-01-09 22:04:19 -05:00
|
|
|
|
|
|
|
// ServerCPULoadInfo holds information about address and cpu load of
|
|
|
|
// a single server node
|
|
|
|
type ServerCPULoadInfo struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
Load []cpu.Load `json:"load"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerCPULoadInfo - Returns cpu utilization information
|
|
|
|
func (adm *AdminClient) ServerCPULoadInfo() ([]ServerCPULoadInfo, error) {
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("perfType", string("cpu"))
|
|
|
|
resp, err := adm.executeMethod("GET", requestData{
|
|
|
|
relPath: "/v1/performance",
|
|
|
|
queryValues: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check response http status code
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return nil, httpRespToErrorResponse(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal the server's json response
|
|
|
|
var info []ServerCPULoadInfo
|
|
|
|
|
|
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(respBytes, &info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerMemUsageInfo holds information about address and memory utilization of
|
|
|
|
// a single server node
|
|
|
|
type ServerMemUsageInfo struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
Usage []mem.Usage `json:"usage"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServerMemUsageInfo - Returns mem utilization information
|
|
|
|
func (adm *AdminClient) ServerMemUsageInfo() ([]ServerMemUsageInfo, error) {
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("perfType", string("mem"))
|
|
|
|
resp, err := adm.executeMethod("GET", requestData{
|
|
|
|
relPath: "/v1/performance",
|
|
|
|
queryValues: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check response http status code
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return nil, httpRespToErrorResponse(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal the server's json response
|
|
|
|
var info []ServerMemUsageInfo
|
|
|
|
|
|
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(respBytes, &info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|