info: Show info of all cluster servers (#2149)
This commit is contained in:
committed by
Harshavardhana
parent
7f65ad4957
commit
320e29e03f
+78
-38
@@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
@@ -94,23 +95,46 @@ type ServerInfo struct {
|
||||
type infoMessage struct {
|
||||
Status string `json:"status"`
|
||||
Service bool `json:"service"`
|
||||
Addr string `json:"address"`
|
||||
Err string `json:"error"`
|
||||
*ServerInfo
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u infoMessage) String() (msg string) {
|
||||
defer func() {
|
||||
msg = console.Colorize("Info", msg)
|
||||
msg += "\n"
|
||||
}()
|
||||
|
||||
dot := "●"
|
||||
|
||||
// When service is offline
|
||||
if !u.Service {
|
||||
msg = "The server is offline."
|
||||
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), u.Addr)
|
||||
msg += fmt.Sprintf(" Uptime : Server is %s", console.Colorize("InfoFail", "offline"))
|
||||
return
|
||||
}
|
||||
msg += fmt.Sprintf(" Version : %s\n", u.ServerInfo.Properties.Version)
|
||||
msg += fmt.Sprintf(" Uptime : %s\n", timeDurationToHumanizedDuration(u.ServerInfo.Properties.Uptime))
|
||||
msg += fmt.Sprintf(" Region : %s\n", u.ServerInfo.Properties.Region)
|
||||
|
||||
// Print error if any and exit
|
||||
if u.Err != "" {
|
||||
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), u.Addr)
|
||||
msg += fmt.Sprintf(" Uptime : Server is %s\n", console.Colorize("InfoFail", "offline"))
|
||||
msg += fmt.Sprintf(" Error : %s", u.Err)
|
||||
return
|
||||
}
|
||||
|
||||
// Print server title
|
||||
msg += fmt.Sprintf("%s %s\n", console.Colorize("Info", dot), u.Addr)
|
||||
|
||||
// Print server information
|
||||
|
||||
// Uptime
|
||||
msg += fmt.Sprintf(" Uptime : %s since %s\n", console.Colorize("Info", "online"), humanize.Time(time.Now().UTC().Add(-u.ServerInfo.Properties.Uptime)))
|
||||
// Version
|
||||
msg += fmt.Sprintf(" Version : %s\n", u.ServerInfo.Properties.Version)
|
||||
// Region
|
||||
msg += fmt.Sprintf(" Region : %s\n", u.ServerInfo.Properties.Region)
|
||||
// ARNs
|
||||
sqsARNs := ""
|
||||
for _, v := range u.ServerInfo.Properties.SQSARN {
|
||||
sqsARNs += fmt.Sprintf("%s ", v)
|
||||
@@ -119,12 +143,11 @@ func (u infoMessage) String() (msg string) {
|
||||
sqsARNs = "<none>"
|
||||
}
|
||||
msg += fmt.Sprintf(" SQS ARNs : %s\n", sqsARNs)
|
||||
|
||||
// Incoming/outgoing
|
||||
msg += fmt.Sprintf(" Network : Incoming %s, Outgoing %s\n",
|
||||
humanize.IBytes(u.ServerInfo.ConnStats.TotalInputBytes),
|
||||
humanize.IBytes(u.ServerInfo.ConnStats.TotalOutputBytes))
|
||||
|
||||
// Online service, get backend information
|
||||
// Get storage information
|
||||
msg += fmt.Sprintf(" Storage : Total %s, Free %s",
|
||||
humanize.IBytes(uint64(u.StorageInfo.Total)),
|
||||
humanize.IBytes(uint64(u.StorageInfo.Free)),
|
||||
@@ -132,6 +155,7 @@ func (u infoMessage) String() (msg string) {
|
||||
if v, ok := u.ServerInfo.StorageInfo.Backend.(xlBackend); ok {
|
||||
msg += fmt.Sprintf(", Online Disks: %d, Offline Disks: %d", v.OnlineDisks, v.OfflineDisks)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -156,6 +180,7 @@ func mainAdminInfo(ctx *cli.Context) error {
|
||||
checkAdminInfoSyntax(ctx)
|
||||
|
||||
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
@@ -165,53 +190,68 @@ func mainAdminInfo(ctx *cli.Context) error {
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Cannot get a configured admin connection.")
|
||||
|
||||
// Fetch the server info of the specified Minio server
|
||||
serverInfo, e := client.ServerInfo()
|
||||
// Fetch info of all servers (cluster or single server)
|
||||
serversInfo, e := client.ServerInfo()
|
||||
|
||||
// Check the availability of the server: online or offline. A server is considered
|
||||
// offline if we can't get any response or we get a bad format response
|
||||
var serviceOffline bool
|
||||
switch v := e.(type) {
|
||||
switch e.(type) {
|
||||
case *json.SyntaxError:
|
||||
serviceOffline = true
|
||||
case *url.Error:
|
||||
if v.Timeout() {
|
||||
serviceOffline = true
|
||||
}
|
||||
serviceOffline = true
|
||||
}
|
||||
|
||||
if serviceOffline {
|
||||
printMsg(infoMessage{Service: false})
|
||||
printMsg(infoMessage{Addr: aliasedURL, Service: false})
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the error is not nil and not unrecognizable, just print it and exit
|
||||
fatalIf(probe.NewError(e), "Cannot get service status.")
|
||||
|
||||
// Construct the backend status
|
||||
storageInfo := backendStatus{
|
||||
Total: serverInfo.StorageInfo.Total,
|
||||
Free: serverInfo.StorageInfo.Free,
|
||||
}
|
||||
if serverInfo.StorageInfo.Backend.Type == madmin.Erasure {
|
||||
storageInfo.Backend = xlBackend{
|
||||
Type: erasureType,
|
||||
OnlineDisks: serverInfo.StorageInfo.Backend.OnlineDisks,
|
||||
OfflineDisks: serverInfo.StorageInfo.Backend.OfflineDisks,
|
||||
for _, serverInfo := range serversInfo {
|
||||
// Print the error if exists and jump to the next server
|
||||
if serverInfo.Error != "" {
|
||||
printMsg(infoMessage{
|
||||
Service: true,
|
||||
Addr: serverInfo.Addr,
|
||||
Err: serverInfo.Error,
|
||||
})
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
storageInfo.Backend = fsBackend{
|
||||
Type: fsType,
|
||||
}
|
||||
}
|
||||
|
||||
printMsg(infoMessage{
|
||||
Service: true,
|
||||
ServerInfo: &ServerInfo{
|
||||
StorageInfo: storageInfo,
|
||||
ConnStats: serverInfo.ConnStats,
|
||||
Properties: serverInfo.Properties,
|
||||
},
|
||||
})
|
||||
// Construct the backend status
|
||||
storageInfo := backendStatus{
|
||||
Total: serverInfo.Data.StorageInfo.Total,
|
||||
Free: serverInfo.Data.StorageInfo.Free,
|
||||
}
|
||||
|
||||
if serverInfo.Data.StorageInfo.Backend.Type == madmin.Erasure {
|
||||
storageInfo.Backend = xlBackend{
|
||||
Type: erasureType,
|
||||
OnlineDisks: serverInfo.Data.StorageInfo.Backend.OnlineDisks,
|
||||
OfflineDisks: serverInfo.Data.StorageInfo.Backend.OfflineDisks,
|
||||
}
|
||||
} else {
|
||||
storageInfo.Backend = fsBackend{
|
||||
Type: fsType,
|
||||
}
|
||||
}
|
||||
|
||||
printMsg(infoMessage{
|
||||
Service: true,
|
||||
Addr: serverInfo.Addr,
|
||||
Err: serverInfo.Error,
|
||||
ServerInfo: &ServerInfo{
|
||||
StorageInfo: storageInfo,
|
||||
ConnStats: serverInfo.Data.ConnStats,
|
||||
Properties: serverInfo.Data.Properties,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+45
-20
@@ -122,7 +122,30 @@ If successful restarts the running minio service, for distributed setup restarts
|
||||
|
||||
```
|
||||
|
||||
## 3. Lock operations
|
||||
## 3. Info operations
|
||||
|
||||
<a name="ServerInfo"></a>
|
||||
### ServerInfo() ([]ServerInfo, error)
|
||||
Fetch all information for all cluster nodes, such as uptime, region, network statistics, etc..
|
||||
|
||||
|
||||
__Example__
|
||||
|
||||
```go
|
||||
|
||||
serversInfo, err := madmClnt.ServerInfo()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
for _, peerInfo := range serversInfo {
|
||||
log.Printf("Node: %s, Info: %v\n", peerInfo.Addr, peerInfo.Data)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## 4. Lock operations
|
||||
|
||||
<a name="ListLocks"></a>
|
||||
### ListLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error)
|
||||
@@ -154,7 +177,7 @@ __Example__
|
||||
|
||||
```
|
||||
|
||||
## 4. Heal operations
|
||||
## 5. Heal operations
|
||||
|
||||
<a name="ListObjectsHeal"></a>
|
||||
### ListObjectsHeal(bucket, prefix string, recursive bool, doneCh <-chan struct{}) (<-chan ObjectInfo, error)
|
||||
@@ -360,7 +383,7 @@ If upload is successfully healed returns nil, otherwise returns error indicating
|
||||
log.Println("Heal-upload result: ", healResult)
|
||||
```
|
||||
|
||||
## 5. Config operations
|
||||
## 6. Config operations
|
||||
|
||||
<a name="GetConfig"></a>
|
||||
### GetConfig() ([]byte, error)
|
||||
@@ -384,23 +407,6 @@ __Example__
|
||||
log.Println("config received successfully: ", string(buf.Bytes()))
|
||||
```
|
||||
|
||||
## 6. Misc operations
|
||||
|
||||
<a name="SetCredentials"></a>
|
||||
|
||||
### SetCredentials() error
|
||||
Set new credentials of a Minio setup.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("New credentials successfully set.")
|
||||
|
||||
```
|
||||
|
||||
<a name="SetConfig"></a>
|
||||
### SetConfig(config io.Reader) (SetConfigResult, error)
|
||||
@@ -435,3 +441,22 @@ __Example__
|
||||
}
|
||||
log.Println("SetConfig: ", string(buf.Bytes()))
|
||||
```
|
||||
|
||||
## 7. Misc operations
|
||||
|
||||
<a name="SetCredentials"></a>
|
||||
|
||||
### SetCredentials() error
|
||||
Set new credentials of a Minio setup.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("New credentials successfully set.")
|
||||
|
||||
```
|
||||
|
||||
|
||||
+18
-11
@@ -74,17 +74,24 @@ type ServerConnStats struct {
|
||||
TotalOutputBytes uint64 `json:"received"`
|
||||
}
|
||||
|
||||
// ServerInfo holds the whole server information that will be
|
||||
// returned by ServerInfo API.
|
||||
type ServerInfo struct {
|
||||
// ServerInfoData holds storage, connections and other
|
||||
// information of a given server
|
||||
type ServerInfoData struct {
|
||||
StorageInfo StorageInfo `json:"storage"`
|
||||
ConnStats ServerConnStats `json:"network"`
|
||||
Properties ServerProperties `json:"server"`
|
||||
}
|
||||
|
||||
// ServerInfo holds server information result of one node
|
||||
type ServerInfo struct {
|
||||
Error string `json:"error"`
|
||||
Addr string `json:"addr"`
|
||||
Data *ServerInfoData `json:"data"`
|
||||
}
|
||||
|
||||
// ServerInfo - Connect to a minio server and call Server Info Management API
|
||||
// to fetch server's information represented by ServerInfo structure
|
||||
func (adm *AdminClient) ServerInfo() (ServerInfo, error) {
|
||||
func (adm *AdminClient) ServerInfo() ([]ServerInfo, error) {
|
||||
// Prepare web service request
|
||||
reqData := requestData{}
|
||||
reqData.queryValues = make(url.Values)
|
||||
@@ -94,26 +101,26 @@ func (adm *AdminClient) ServerInfo() (ServerInfo, error) {
|
||||
resp, err := adm.executeMethod("GET", reqData)
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return ServerInfo{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Check response http status code
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return ServerInfo{}, httpRespToErrorResponse(resp)
|
||||
return nil, httpRespToErrorResponse(resp)
|
||||
}
|
||||
|
||||
// Unmarshal the server's json response
|
||||
var info ServerInfo
|
||||
var serversInfo []ServerInfo
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return ServerInfo{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBytes, &info)
|
||||
err = json.Unmarshal(respBytes, &serversInfo)
|
||||
if err != nil {
|
||||
return ServerInfo{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
return serversInfo, nil
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -86,10 +86,10 @@
|
||||
"revisionTime": "2017-04-26T18:23:05Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "v1OEKlUTmnwiQ2RxIFfDhz77Uu0=",
|
||||
"checksumSHA1": "wCZlVPjuBU/D1ogLL63YdO/havo=",
|
||||
"path": "github.com/minio/minio/pkg/madmin",
|
||||
"revision": "3032f0f505437c2f631e304cd64a7c1ed7a3479a",
|
||||
"revisionTime": "2017-04-15T18:40:01Z"
|
||||
"revision": "9d98bf1c0fb83ccfcf368dec52b2d19b9195b8d4",
|
||||
"revisionTime": "2017-05-19T14:30:00Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio/pkg/probe",
|
||||
|
||||
Reference in New Issue
Block a user