mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
Add disk detection for Linux, add new RPC service GetDiskInfoService(), remove dummy HelloService()
This commit is contained in:
58
pkg/server/rpc/diskinfo.go
Normal file
58
pkg/server/rpc/diskinfo.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 rpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
"github.com/minio/minio/pkg/utils/scsi"
|
||||
)
|
||||
|
||||
// GetDiskInfoService disk info service
|
||||
type GetDiskInfoService struct{}
|
||||
|
||||
// GetDiskInfoReply disk info reply for disk info service
|
||||
type GetDiskInfoReply struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Disks []string `json:"disks"`
|
||||
DiskAttributes map[string]scsi.Attributes `json:"disk-attrs"`
|
||||
}
|
||||
|
||||
func setDiskInfoReply(sis *GetDiskInfoReply) error {
|
||||
var err error
|
||||
sis.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
disks, err := scsi.GetDisks()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
sis.DiskAttributes = make(map[string]scsi.Attributes)
|
||||
for k, v := range disks {
|
||||
sis.Disks = append(sis.Disks, k)
|
||||
sis.DiskAttributes[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get method
|
||||
func (s *GetDiskInfoService) Get(r *http.Request, args *Args, reply *GetDiskInfoReply) error {
|
||||
return setDiskInfoReply(reply)
|
||||
}
|
||||
@@ -20,61 +20,10 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// HelloArgs - hello args
|
||||
type HelloArgs struct {
|
||||
Who string
|
||||
}
|
||||
|
||||
// HelloReply - hello reply
|
||||
type HelloReply struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
// HelloService - hello service
|
||||
type HelloService struct{}
|
||||
|
||||
// Say method
|
||||
func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error {
|
||||
reply.Message = "Hello, " + args.Who + "!"
|
||||
return nil
|
||||
}
|
||||
|
||||
// Args basic json RPC params
|
||||
type Args struct {
|
||||
Request string
|
||||
}
|
||||
|
||||
// VersionReply version reply
|
||||
type VersionReply struct {
|
||||
Version string `json:"version"`
|
||||
BuildDate string `json:"build-date"`
|
||||
}
|
||||
|
||||
// VersionService -
|
||||
type VersionService struct{}
|
||||
|
||||
func getVersion() string {
|
||||
return "0.0.1"
|
||||
}
|
||||
func getBuildDate() string {
|
||||
return time.Now().UTC().Format(http.TimeFormat)
|
||||
}
|
||||
|
||||
func setVersionReply(reply *VersionReply) {
|
||||
reply.Version = getVersion()
|
||||
reply.BuildDate = getBuildDate()
|
||||
return
|
||||
}
|
||||
|
||||
// Get method
|
||||
func (v *VersionService) Get(r *http.Request, args *Args, reply *VersionReply) error {
|
||||
setVersionReply(reply)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSysInfoService -
|
||||
type GetSysInfoService struct{}
|
||||
|
||||
@@ -95,7 +44,12 @@ func setSysInfoReply(sis *GetSysInfoReply) error {
|
||||
sis.SysCPUS = runtime.NumCPU()
|
||||
sis.Routines = runtime.NumGoroutine()
|
||||
sis.GOVersion = runtime.Version()
|
||||
sis.Hostname, _ = os.Hostname()
|
||||
|
||||
var err error
|
||||
sis.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
|
||||
var memStats runtime.MemStats
|
||||
runtime.ReadMemStats(&memStats)
|
||||
55
pkg/server/rpc/version.go
Normal file
55
pkg/server/rpc/version.go
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 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 rpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Args basic json RPC params
|
||||
type Args struct {
|
||||
Request string
|
||||
}
|
||||
|
||||
// VersionReply version reply
|
||||
type VersionReply struct {
|
||||
Version string `json:"version"`
|
||||
BuildDate string `json:"build-date"`
|
||||
}
|
||||
|
||||
// VersionService -
|
||||
type VersionService struct{}
|
||||
|
||||
func getVersion() string {
|
||||
return "0.0.1"
|
||||
}
|
||||
func getBuildDate() string {
|
||||
return time.Now().UTC().Format(http.TimeFormat)
|
||||
}
|
||||
|
||||
func setVersionReply(reply *VersionReply) {
|
||||
reply.Version = getVersion()
|
||||
reply.BuildDate = getBuildDate()
|
||||
return
|
||||
}
|
||||
|
||||
// Get method
|
||||
func (v *VersionService) Get(r *http.Request, args *Args, reply *VersionReply) error {
|
||||
setVersionReply(reply)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user