mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-18 22:20:56 +08:00
The egress governor is now a current governor that SetProfile swaps: new requests use the new one, requests in flight finish on the old one, and one package-level ticker logs the counters of the current governor. WebFetch, the http custom tools and the enrich probe resolve it per request, and the agent prompt block reads the current profile. The noise_profile setting (off, quiet, balanced, aggressive) is applied at startup and wins over ARTEX_NOISE_PROFILE, which stays the fallback; PUT /api/settings validates, stores and applies it without rebuilding agents, and GET /api/settings/noise returns the per-host counters without resetting them. System settings gets a Target noise card.
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
"github.com/Autumn-27/artex/egress"
|
|
)
|
|
|
|
// startupNoiseProfile is the noise profile to apply at startup: the stored
|
|
// noise_profile setting when there is a valid one, else ARTEX_NOISE_PROFILE.
|
|
func startupNoiseProfile(pg *db.DB) egress.Profile {
|
|
v, ok, err := pg.GetSetting(settingNoiseProfile)
|
|
if err != nil {
|
|
log.Printf("[egress] read %s setting: %v; using ARTEX_NOISE_PROFILE", settingNoiseProfile, err)
|
|
}
|
|
if ok {
|
|
if p, valid := egress.ProfileByName(v); valid {
|
|
return p
|
|
}
|
|
log.Printf("[egress] stored %s=%q is not off, quiet, balanced or aggressive; using ARTEX_NOISE_PROFILE", settingNoiseProfile, v)
|
|
}
|
|
return egress.ProfileFromEnv()
|
|
}
|
|
|
|
// noiseStatus returns the current noise profile and the per-host counters of
|
|
// its governor, read without starting a new minute.
|
|
func (s *Server) noiseStatus(w http.ResponseWriter, r *http.Request) {
|
|
g := egress.Current()
|
|
writeJSON(w, 200, map[string]any{"profile": g.Profile().Name, "hosts": g.Snapshot()})
|
|
}
|