public void AddReport(ReportedItem r) { lock (LockObj) { var q = ReportTable._GetOrNew(r.Hostname, () => new Queue <ReportedItem>()); bool changed = true; var last = q.LastOrDefault(); if (last != null) { if (last.Body._IsSame(r.Body)) { changed = false; } } if (changed) { q.Enqueue(r); while (q.Count > CoresConfig.StressMonServer.MaxHistoryPerServer) { q.Dequeue(); } } } }
protected override void InitActionListImpl(CgiActionList noAuth, CgiActionList reqAuth) { try { noAuth.AddAction("/", WebMethodBits.GET | WebMethodBits.HEAD, async(ctx) => { await Task.CompletedTask; var hostname = ctx.QueryString._GetStrFirst("hostname"); var body = ctx.QueryString._GetStrFirst("body"); if (hostname._IsFilled() && body._IsFilled()) { ReportedItem r = new ReportedItem(DateTimeOffset.Now, hostname, ctx.ClientIpAddress.ToString(), body); this.AddReport(r); return(new HttpStringResult("ok")); } return(new HttpStringResult(GenerateReportString())); }); noAuth.AddAction("/reset", WebMethodBits.GET | WebMethodBits.HEAD, async(ctx) => { await Task.CompletedTask; this.Reset(); return(new HttpStringResult(GenerateReportString())); }); noAuth.AddAction("/", WebMethodBits.POST, async(ctx) => { await Task.CompletedTask; var hostname = ctx.QueryString._GetStrFirst("hostname"); if (hostname._IsFilled()) { ReportedItem r = new ReportedItem(DateTimeOffset.Now, hostname, ctx.ClientIpAddress.ToString(), await ctx.Request._RecvStringContentsAsync(CoresConfig.StressMonServer.MaxBodySize, cancel: ctx.Cancel)); this.AddReport(r); return(new HttpStringResult("ok")); } return(new HttpStringResult("error")); }); } catch { this._DisposeSafe(); throw; } }