diff --git a/cmd/root.go b/cmd/root.go index c07a227..9a3acc9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -101,8 +101,8 @@ var rootCmd = &cobra.Command{ Config = loaded logging.Init(Config.Logging) - logging.L().Debug("Logging initialized", "level", Config.Logging.Level) - logging.L().Debug("Loaded config", "config", Config) + logging.L().Debug("ElasticPHP-agent Logging initialized", "level", Config.Logging.Level) + logging.L().Debug("ElasticPHP-agent Loaded config", "config", Config) // phpfpm autodiscover if Config.PHPFpm.Enabled && Config.PHPFpm.Autodiscover { @@ -115,16 +115,16 @@ var rootCmd = &cobra.Command{ break } - logging.L().Warn("Autodiscover attempt failed", "attempt", i+1, "error", err) + logging.L().Debug("ElasticPHP-agent PHP-FPM autodiscover attempt failed", "attempt", i+1, "error", err) time.Sleep(time.Duration(Config.PHPFpm.RetryDelay) * time.Second) } if err != nil { - logging.L().Error("Autodiscover failed after retries", "error", err) + logging.L().Error("ElasticPHP-agent PHP-FPM Autodiscover failed after retries", "error", err) } else if len(discovered) == 0 { - logging.L().Error("Autodiscover succeeded but no FPM pools found") + logging.L().Error("ElasticPHP-agent PHP-FPM Autodiscover succeeded but no FPM pools found") } else { - logging.L().Debug("Discovered FPM Processes", "pools", discovered) + logging.L().Debug("ElasticPHP-agent Discovered PHP-FPM Processes", "pools", discovered) for _, d := range discovered { Config.PHPFpm.Pools = append(Config.PHPFpm.Pools, config.FPMPoolConfig{ Socket: d.Socket, diff --git a/cmd/serve.go b/cmd/serve.go index b878f67..018634d 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -11,7 +11,7 @@ var serveCmd = &cobra.Command{ Use: "serve", Short: "Start agent HTTP server with metrics and control endpoints", Run: func(cmd *cobra.Command, args []string) { - logging.L().Info("Starting elasticphp-agent") + logging.L().Info("ElasticPHP-agent Starting") serve.StartPrometheusServer(Config) }, } diff --git a/internal/laravel/info.go b/internal/laravel/info.go index d11e626..75ff8c2 100644 --- a/internal/laravel/info.go +++ b/internal/laravel/info.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "os" "os/exec" "path/filepath" "strings" @@ -110,9 +111,19 @@ func GetAppInfo(site config.LaravelConfig, phpBinary string) (*AppInfo, error) { return info, nil } - logging.L().Debug("Uncached app info. Calling artisan about", "path", site.Path) + logging.L().Debug("ElasticPHP-agent Uncached app info. Calling artisan about", "path", site.Path) cmd := exec.Command(phpBinary, "-d", "error_reporting=E_ALL & ~E_DEPRECATED", "artisan", "about", "--json") + + // disable monitoring on scraping to prevent exhausting monitoring tools + cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, "NIGHTWATCH_ENABLED=false") + cmd.Env = append(cmd.Env, "TELESCOPE_ENABLED=false") + cmd.Env = append(cmd.Env, "NEW_RELIC_ENABLED=false") + cmd.Env = append(cmd.Env, "BUGSNAG_API_KEY=null") + cmd.Env = append(cmd.Env, "SENTRY_LARAVEL_DSN=null") + cmd.Env = append(cmd.Env, "ROLLBAR_TOKEN=null") + cmd.Dir = cacheKey var out bytes.Buffer diff --git a/internal/phpfpm/discover.go b/internal/phpfpm/discover.go index 3278ffa..5b02cb8 100644 --- a/internal/phpfpm/discover.go +++ b/internal/phpfpm/discover.go @@ -51,13 +51,13 @@ func DiscoverFPMProcesses() ([]DiscoveredFPM, error) { exe, err := p.Exe() if err != nil { - logging.L().Debug("Cannot determine binary path", "pid", p.Pid, "error", err) + logging.L().Debug("ElasticPHP-agent Cannot determine binary path", "pid", p.Pid, "error", err) continue } parsed, err := ParseFPMConfig(exe, config) if err != nil { - logging.L().Error("Failed to parse FPM config", "config", config, "error", err) + logging.L().Error("ElasticPHP-agent ElasticPHP-agent Failed to parse FPM config", "config", config, "error", err) continue } @@ -77,7 +77,7 @@ func DiscoverFPMProcesses() ([]DiscoveredFPM, error) { status = parsed.Global["pm.status_path"] } if status == "" { - logging.L().Debug("Skipping pool with no status path", "pool", poolName, "config", config) + logging.L().Debug("ElasticPHP-agent Skipping pool with no status path", "pool", poolName, "config", config) continue } @@ -92,7 +92,7 @@ func DiscoverFPMProcesses() ([]DiscoveredFPM, error) { CliBinary: cliBinary, }) - logging.L().Debug("Discovered php-fpm pool", + logging.L().Debug("ElasticPHP-agent Discovered php-fpm pool", "config", config, "pool", poolName, "socket", socket, @@ -125,7 +125,7 @@ func parseSocket(socket string) string { resolved = candidate break } else { - logging.L().Warn("Failed to connect to socket", "socket", candidate, "error", err) + logging.L().Warn("ElasticPHP-agent Failed to connect to PHP-FPM socket", "socket", candidate, "error", err) } } if resolved != "" { diff --git a/internal/phpfpm/metrics.go b/internal/phpfpm/metrics.go index 34d53f1..6f9739d 100644 --- a/internal/phpfpm/metrics.go +++ b/internal/phpfpm/metrics.go @@ -73,16 +73,16 @@ func GetMetrics(ctx context.Context, cfg *config.Config) (map[string]*Result, er scheme, address, path, err := ParseAddress(poolCfg.StatusSocket, poolCfg.StatusPath) if err != nil { - logging.L().Error("invalid FPM socket address: %v", slog.Any("err", err)) + logging.L().Error("ElasticPHP-agent Invalid FPM socket address: %v", slog.Any("err", err)) continue } dialCtx, cancel := context.WithTimeout(ctx, 3*time.Second) - logging.L().Debug("Dialing FastCGI", "scheme", scheme, "address", address, "status_path", path) + logging.L().Debug("ElasticPHP-agent Dialing FastCGI", "scheme", scheme, "address", address, "status_path", path) client, err := fcgx.DialContext(dialCtx, scheme, address) cancel() if err != nil { - logging.L().Debug("failed to dial FastCGI", "error", err) + logging.L().Debug("ElasticPHP-agent failed to dial FastCGI", "error", err) continue } defer client.Close() @@ -94,11 +94,11 @@ func GetMetrics(ctx context.Context, cfg *config.Config) (map[string]*Result, er "REMOTE_ADDR": "127.0.0.1", "QUERY_STRING": "json&full", } - logging.L().Debug("Sending FCGI request", "env", env) + logging.L().Debug("ElasticPHP-agent Sending FCGI request", "env", env) resp, err := client.Get(ctx, env) if err != nil { - logging.L().Debug("fcgi GET failed", "error", err) + logging.L().Debug("ElasticPHP-agent fcgi GET failed", "error", err) continue } defer resp.Body.Close() @@ -107,7 +107,7 @@ func GetMetrics(ctx context.Context, cfg *config.Config) (map[string]*Result, er err = fcgx.ReadJSON(resp, &pool) if err != nil { - logging.L().Error("failed to parse FPM JSON: %v", slog.Any("err", err)) + logging.L().Error("ElasticPHP-agent failed to parse FPM JSON: %v", slog.Any("err", err)) continue } @@ -147,14 +147,14 @@ func GetMetrics(ctx context.Context, cfg *config.Config) (map[string]*Result, er if err == nil && phpStatus != nil { pool.PhpInfo = *phpStatus } else { - logging.L().Debug("failed to get PHP info", "error", err) + logging.L().Debug("ElasticPHP-agent failed to get PHP info", "error", err) } opcacheStatus, err := GetOpcacheStatus(ctx, poolCfg) if err == nil && opcacheStatus != nil { pool.OpcacheStatus = *opcacheStatus } else { - logging.L().Debug("failed to get Opcache info", "error", err) + logging.L().Debug("ElasticPHP-agent failed to get Opcache info", "error", err) } result.Pools[pool.Name] = pool diff --git a/internal/serve/prometheus.go b/internal/serve/prometheus.go index a8f87fb..056b90b 100644 --- a/internal/serve/prometheus.go +++ b/internal/serve/prometheus.go @@ -543,8 +543,8 @@ func StartPrometheusServer(cfg *config.Config) { Handler: mux, } - logging.L().Debug("Prometheus metrics server listening", slog.Any("addr", cfg.Monitor.ListenAddr)) + logging.L().Debug("ElasticPHP-agent Prometheus metrics server listening", slog.Any("addr", cfg.Monitor.ListenAddr)) if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - logging.L().Error("Failed to start Prometheus server", slog.Any("err", err)) + logging.L().Error("ElasticPHP-agent Failed to start Prometheus server", slog.Any("err", err)) } }