feat: switch monitor client to Docker-first runtime
- remove install.sh-based deployment path - add multi-stage Dockerfile for HarborForge.Monitor - support HF_MONITER_* env vars and keep HF_MONITOR_* compatibility - add rootfs-aware host metric collection for Docker deployment
This commit is contained in:
@@ -55,7 +55,11 @@ func BuildPayload(ctx context.Context, cfg config.Config) (Payload, error) {
|
||||
payload.MemPct = round1(vm.UsedPercent)
|
||||
}
|
||||
|
||||
diskUsage, err := disk.UsageWithContext(ctx, "/")
|
||||
diskPath := cfg.RootFS
|
||||
if diskPath == "" {
|
||||
diskPath = "/"
|
||||
}
|
||||
diskUsage, err := disk.UsageWithContext(ctx, diskPath)
|
||||
if err == nil {
|
||||
payload.DiskPct = round1(diskUsage.UsedPercent)
|
||||
}
|
||||
@@ -75,7 +79,7 @@ func BuildPayload(ctx context.Context, cfg config.Config) (Payload, error) {
|
||||
payload.UptimeSeconds = hostInfo.Uptime
|
||||
}
|
||||
|
||||
nginxInstalled, nginxSites, err := detectNginx()
|
||||
nginxInstalled, nginxSites, err := detectNginx(cfg.RootFS)
|
||||
if err == nil {
|
||||
payload.NginxInstalled = nginxInstalled
|
||||
payload.NginxSites = nginxSites
|
||||
@@ -109,12 +113,20 @@ func Send(ctx context.Context, client *http.Client, cfg config.Config, payload P
|
||||
return nil
|
||||
}
|
||||
|
||||
func detectNginx() (bool, []string, error) {
|
||||
func detectNginx(rootFS string) (bool, []string, error) {
|
||||
installed := false
|
||||
if _, err := exec.LookPath("nginx"); err == nil {
|
||||
installed = true
|
||||
if rootFS == "" {
|
||||
if _, err := exec.LookPath("nginx"); err == nil {
|
||||
installed = true
|
||||
}
|
||||
}
|
||||
for _, path := range []string{"/etc/nginx/nginx.conf", "/usr/local/etc/nginx/nginx.conf", "/opt/homebrew/etc/nginx/nginx.conf"} {
|
||||
for _, path := range []string{
|
||||
rootPath(rootFS, "/etc/nginx/nginx.conf"),
|
||||
rootPath(rootFS, "/usr/local/etc/nginx/nginx.conf"),
|
||||
rootPath(rootFS, "/opt/homebrew/etc/nginx/nginx.conf"),
|
||||
rootPath(rootFS, "/usr/sbin/nginx"),
|
||||
rootPath(rootFS, "/usr/bin/nginx"),
|
||||
} {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
installed = true
|
||||
break
|
||||
@@ -124,7 +136,7 @@ func detectNginx() (bool, []string, error) {
|
||||
return false, []string{}, nil
|
||||
}
|
||||
|
||||
dir := "/etc/nginx/sites-enabled"
|
||||
dir := rootPath(rootFS, "/etc/nginx/sites-enabled")
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -155,3 +167,10 @@ func round1(v float64) float64 {
|
||||
func round2(v float64) float64 {
|
||||
return float64(int(v*100+0.5)) / 100
|
||||
}
|
||||
|
||||
func rootPath(rootFS, path string) string {
|
||||
if rootFS == "" || rootFS == "/" {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(rootFS, strings.TrimPrefix(path, "/"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user