Throttle spammy events
This commit is contained in:
1 parent
03bb19522d
commit
80627f3d13
2 files changed
+31
-21
No files matched your search
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Nothing worth mentioning yet.
|
||||||
|
|
||||||
## [0.41.21] - 2025-09-28
|
## [0.41.21] - 2025-09-28
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ function LoggerLoop()
|
|||||||
buffer.AppendFile(logsFile)
|
buffer.AppendFile(logsFile)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
m.eventThrottleTimer = CreateObject("roTimespan")
|
||||||
|
|
||||||
appMemoryMonitor = CreateObject("roAppMemoryMonitor")
|
appMemoryMonitor = CreateObject("roAppMemoryMonitor")
|
||||||
if appMemoryMonitor <> invalid and FindMemberFunction(appMemoryMonitor, "EnableMemoryWarningEvent") <> invalid
|
if appMemoryMonitor <> invalid and FindMemberFunction(appMemoryMonitor, "EnableMemoryWarningEvent") <> invalid
|
||||||
appMemoryMonitor.SetMessagePort(port)
|
appMemoryMonitor.SetMessagePort(port)
|
||||||
@@ -115,27 +117,13 @@ function OnLineSysLog(event as object, dateTime as object, logsFile as string, b
|
|||||||
|
|
||||||
fingerprint = `SysLog${info.Status}${info.LogType}${info.HttpCode}${info.Method}`
|
fingerprint = `SysLog${info.Status}${info.LogType}${info.HttpCode}${info.Method}`
|
||||||
|
|
||||||
if m.sysLogEventTimer = invalid
|
if ThrottleEvent("SysLogError", fingerprint, 60)
|
||||||
m.sysLogEventTimer = CreateObject("roTimespan")
|
|
||||||
m.sysLogFingerprint = fingerprint
|
|
||||||
LogTelemetryEvent({
|
|
||||||
level: "error"
|
|
||||||
message: line
|
|
||||||
fingerprint: [fingerprint]
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' Only log one syslog error per minute (or if the fingerprint changes) to avoid spamming
|
|
||||||
if m.sysLogEventTimer.TotalSeconds() < 60 and m.sysLogFingerprint = fingerprint
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
m.sysLogEventTimer.Mark()
|
|
||||||
m.sysLogFingerprint = fingerprint
|
|
||||||
|
|
||||||
LogTelemetryEvent({
|
LogTelemetryEvent({
|
||||||
level: "error"
|
level: "error"
|
||||||
message: line
|
message: line + `\nCurrentTime: ${m.eventThrottleTimer.TotalSeconds()}`
|
||||||
fingerprint: [fingerprint]
|
fingerprint: [fingerprint]
|
||||||
})
|
})
|
||||||
end function
|
end function
|
||||||
@@ -147,9 +135,14 @@ function OnLineLogMonitorMemoryWarning(event as object, dateTime as object, logs
|
|||||||
print line
|
print line
|
||||||
buffer.FromAsciiString(line + `\n`)
|
buffer.FromAsciiString(line + `\n`)
|
||||||
buffer.AppendFile(logsFile)
|
buffer.AppendFile(logsFile)
|
||||||
|
|
||||||
|
if ThrottleEvent("AppMonitorMemoryWarning", message, 60)
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
LogTelemetryEvent({
|
LogTelemetryEvent({
|
||||||
level: "warning"
|
level: "warning"
|
||||||
message: line
|
message: line + `\nCurrentTime: ${m.eventThrottleTimer.TotalSeconds()}`
|
||||||
fingerprint: [message]
|
fingerprint: [message]
|
||||||
})
|
})
|
||||||
end function
|
end function
|
||||||
@@ -160,24 +153,37 @@ function OnLineLogDeviceInfoMemoryWarning(event as object, dateTime as object, l
|
|||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' roDeviceInfoEvent can be a bit spammy, so only log if the memory level has changed
|
if ThrottleEvent("DeviceInfoMemoryWarning", info.generalMemoryLevel, 60)
|
||||||
if info.generalMemoryLevel = m.lastDeviceInfoMemoryLevel
|
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
m.lastDeviceInfoMemoryLevel = info.generalMemoryLevel
|
|
||||||
|
|
||||||
message = "[WARN][DeviceInfoMemory] " + ToString(info)
|
message = "[WARN][DeviceInfoMemory] " + ToString(info)
|
||||||
line = FormatTime(dateTime) + message
|
line = FormatTime(dateTime) + message
|
||||||
print line
|
print line
|
||||||
buffer.FromAsciiString(line + `\n`)
|
buffer.FromAsciiString(line + `\n`)
|
||||||
buffer.AppendFile(logsFile)
|
buffer.AppendFile(logsFile)
|
||||||
|
|
||||||
LogTelemetryEvent({
|
LogTelemetryEvent({
|
||||||
level: "warning"
|
level: "warning"
|
||||||
message: line
|
message: line + `\nCurrentTime: ${m.eventThrottleTimer.TotalSeconds()}`
|
||||||
fingerprint: [message]
|
fingerprint: [message]
|
||||||
})
|
})
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
' Returns true if the event should be throttled
|
||||||
|
function ThrottleEvent(key as string, fingerprint as string, throttleSeconds as integer) as boolean
|
||||||
|
lastSentTime = ValidInt(m[key])
|
||||||
|
currentTime = m.eventThrottleTimer.TotalSeconds()
|
||||||
|
|
||||||
|
if ((currentTime - lastSentTime) < throttleSeconds) and (m[key + "Fingerprint"] = fingerprint)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
m[key] = currentTime
|
||||||
|
m[key + "Fingerprint"] = fingerprint
|
||||||
|
return false
|
||||||
|
end function
|
||||||
|
|
||||||
' Note: although the timestamp should be captured in the caller, not the logger,
|
' Note: although the timestamp should be captured in the caller, not the logger,
|
||||||
' it is done here to avoid adding overhead to the caller thread.
|
' it is done here to avoid adding overhead to the caller thread.
|
||||||
function FormatTime(dateTime as object) as string
|
function FormatTime(dateTime as object) as string
|
||||||
|
|||||||
Reference in new issue
Block a user