This commit is contained in:
crusader 2018-06-14 16:24:05 +09:00
parent 07c068fa89
commit a8fb0b328d
3 changed files with 35 additions and 28 deletions

View File

@ -4,7 +4,7 @@
"apiKey": "52abd6fd57e511e7ac52080027658d13" "apiKey": "52abd6fd57e511e7ac52080027658d13"
}, },
"central": { "central": {
"address": "192.168.1.50:19091", "address": "192.168.1.101:19100",
"connector": { "connector": {
"reconnectInterval": 5, "reconnectInterval": 5,
"reconnectTryTime": 10, "reconnectTryTime": 10,
@ -17,6 +17,5 @@
} }
}, },
"probe": { "probe": {
"key": "730a120349dd11e890a40242ac120004"
} }
} }

View File

@ -1,6 +1,8 @@
package info package info
import ( import (
"bytes"
"compress/gzip"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"log" "log"
@ -11,10 +13,7 @@ import (
ocmi "git.loafle.net/overflow/commons-go/model/infra" ocmi "git.loafle.net/overflow/commons-go/model/infra"
ocmm "git.loafle.net/overflow/commons-go/model/meta" ocmm "git.loafle.net/overflow/commons-go/model/meta"
ocmn "git.loafle.net/overflow/commons-go/model/noauthprobe" ocmn "git.loafle.net/overflow/commons-go/model/noauthprobe"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
) )
func GetRegistHeader(apiKey string) (string, error) { func GetRegistHeader(apiKey string) (string, error) {
@ -32,16 +31,29 @@ func GetRegistHeader(apiKey string) (string, error) {
if buf, err = json.Marshal(infraHost); nil != err { if buf, err = json.Marshal(infraHost); nil != err {
return "", err return "", err
} }
nap.InfraHostMeta = string(buf) nap.InfraHostMeta = string(buf)
if buf, err = json.Marshal(nap); nil != err { if buf, err = json.Marshal(nap); nil != err {
return "", err return "", err
} }
log.Printf("nap: %s", string(buf)) var b bytes.Buffer
gz := gzip.NewWriter(&b)
if _, err := gz.Write(buf); err != nil {
return "", err
}
if err := gz.Flush(); err != nil {
return "", err
}
if err := gz.Close(); err != nil {
return "", err
}
enc := base64.StdEncoding.EncodeToString(buf) gBuf := b.Bytes()
log.Printf("RegistHeader length: %d", len(gBuf))
enc := base64.StdEncoding.EncodeToString(gBuf)
return enc, nil return enc, nil
} }
@ -66,29 +78,25 @@ func getInfraHost() (*ocmi.InfraHost, error) {
func getInfraHostMachine() (*ocmi.InfraHostMachine, error) { func getInfraHostMachine() (*ocmi.InfraHostMachine, error) {
meta := make(map[string]interface{}) meta := make(map[string]interface{})
if i, err := cpu.Info(); nil == err { // if i, err := cpu.Info(); nil == err {
meta["CPU"] = i // meta["CPU"] = i
} // }
if i, err := mem.SwapMemory(); nil == err { // if i, err := mem.SwapMemory(); nil == err {
meta["Memory_Swap"] = i // meta["Memory_Swap"] = i
} // }
if i, err := mem.VirtualMemory(); nil == err { // if i, err := mem.VirtualMemory(); nil == err {
meta["Memory_Virtual"] = i // meta["Memory_Virtual"] = i
} // }
if i, err := mem.VirtualMemory(); nil == err { // if i, err := disk.Partitions(true); nil == err {
meta["Memory_Virtual"] = i // meta["Partitions"] = i
} // }
if i, err := disk.Partitions(true); nil == err { // if i, err := disk.Usage("/"); nil == err {
meta["Partitions"] = i // meta["Disk_Usage"] = i
} // }
if i, err := disk.Usage("/"); nil == err {
meta["Disk_Usage"] = i
}
buf, err := json.Marshal(meta) buf, err := json.Marshal(meta)
if nil != err { if nil != err {

View File

@ -28,7 +28,7 @@ func New() (csc.Connector, error) {
if config.Dev { if config.Dev {
u := url.URL{ u := url.URL{
Scheme: "ws", Scheme: "ws",
Host: fmt.Sprintf("%s:%d", strings.Split(_config.Central.Address, ":")[0], 19095), Host: fmt.Sprintf("%s:%d", strings.Split(_config.Central.Address, ":")[0], 19110),
} }
u.Path = path.Join(u.Path, occp.HTTPEntry_Data) u.Path = path.Join(u.Path, occp.HTTPEntry_Data)
connector.URL = u.String() connector.URL = u.String()