-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathprov_localhost.go
More file actions
66 lines (58 loc) · 1.48 KB
/
prov_localhost.go
File metadata and controls
66 lines (58 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
// Copyright 2017-2021 SIGNAL18 CLOUD SAS
// Authors: Guillaume Lefranc <guillaume@signal18.io>
// Stephane Varoqui <svaroqui@gmail.com>
// This source code is licensed under the GNU General Public License, version 3.
package cluster
import (
"bytes"
"net"
"os"
"runtime"
"strconv"
)
func readPidFromFile(pidfile string) (string, error) {
d, err := os.ReadFile(pidfile)
if err != nil {
return "", err
}
return string(bytes.TrimSpace(d)), nil
}
func (cluster *Cluster) LocalhostGetNodes() ([]Agent, error) {
var info runtime.MemStats
runtime.ReadMemStats(&info)
name, err := os.Hostname()
if err != nil {
name = "127.0.0.1"
}
agents := []Agent{}
/* m.Alloc = rtm.Alloc
m.TotalAlloc = rtm.TotalAlloc
m.Sys = rtm.Sys
m.Mallocs = rtm.Mallocs
m.Frees = rtm.Frees
*/
var agent Agent
agent.Id = "1"
agent.OsName = cluster.Conf.GoOS
agent.OsKernel = cluster.Conf.GoArch
agent.CpuCores = int64(runtime.NumCPU())
agent.CpuFreq = 0
agent.MemBytes = int64(info.Sys)
agent.HostName = name
agents = append(agents, agent)
return agents, nil
}
func (cluster *Cluster) LocalhostGetFreePort() (string, error) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
return "", err
}
listener, err := net.ListenTCP("tcp", addr)
if err != nil {
return "", err
}
port := strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)
defer listener.Close()
return port, nil
}