Server Log Summary and Minute Anomalies
Problem statement
Analyze decoded server-log candidates. Each valid row is [timestampMillis, level, latencyMillis, statusCode]. Skip any row whose field count is not four or whose timestamp, latency, or status is not an integer.
Return output lines in this order:
LEVEL name=countfor present levels in lexicographic order.AVG_LATENCY=x.xxover all valid rows.STATUS code=countfor present codes in numeric order.- For every minute bucket in numeric order whose percentage of status codes at least 500 is at least
errorRatePercentor whose average latency is at leastlatencyThreshold:ANOMALY minute=m errorRate=x.xx avgLatency=y.yy.
Return an empty array when no row is valid.
Function
analyzeLogs(records: String[][], latencyThreshold: int, errorRatePercent: int) → String[]Examples
Example 1
records = [["0","INFO","100","200"],["30000","ERROR","300","500"]]latencyThreshold = 250errorRatePercent = 50return = ["LEVEL ERROR=1","LEVEL INFO=1","AVG_LATENCY=200.00","STATUS 200=1","STATUS 500=1","ANOMALY minute=0 errorRate=50.00 avgLatency=200.00"]The minute reaches the error-rate threshold exactly.
Example 2
records = [["bad","INFO","10","200"],["1","INFO"]]latencyThreshold = 100errorRatePercent = 50return = []Both rows are malformed and skipped.
Constraints
0 <= records.length <= 10^5.- Valid timestamps and latencies are nonnegative; status codes are positive.
- Thresholds are nonnegative.