MCPcopy Create free account
hub / github.com/MertJSX/folderhost / StartMonitoring

Method StartMonitoring

utils/service_utils/ram_management.go:152–196  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

150}
151
152func (sm *ServiceManager) StartMonitoring(name string) {
153 sm.Mu.RLock()
154 service, exists := sm.Services[name]
155 sm.Mu.RUnlock()
156
157 if !exists {
158 return
159 }
160
161 limiter := &SoftLimiter{
162 PID: service.PID,
163 SoftLimit: int64(float64(service.Config.RAMBytes) * 0.8),
164 HardLimit: service.Config.RAMBytes,
165 }
166
167 go func() {
168 ticker := time.NewTicker(10 * time.Second)
169 defer ticker.Stop()
170
171 for range ticker.C {
172 service.mu.RLock()
173 if service.Status != "running" {
174 service.mu.RUnlock()
175 return
176 }
177 service.mu.RUnlock()
178
179 usage, err := getProcessTreeRAM(limiter.PID)
180 if err != nil {
181 log.Printf("Error checking RAM usage of service: %s", name)
182 continue
183 }
184
185 if usage > limiter.HardLimit {
186 log.Printf("Stopping Service: %s RAM Limit Exceeded! Usage: %s / Limit: %s",
187 name,
188 utils.ConvertBytesToString(usage),
189 service.Config.RAM)
190
191 go sm.StopService(name)
192 return
193 }
194 }
195 }()
196}

Callers 1

StartServiceMethod · 0.95

Calls 3

StopServiceMethod · 0.95
ConvertBytesToStringFunction · 0.92
getProcessTreeRAMFunction · 0.85

Tested by

no test coverage detected