49 lines
3.6 KiB
C#
49 lines
3.6 KiB
C#
namespace MoShiro.Backend.Analysis;
|
|
|
|
/// <summary>http 任务(单个 Agent 请求一个 URL)的指标。耗时只统计成功的请求。</summary>
|
|
public static class HttpMetrics
|
|
{
|
|
private static readonly string[] s_req = ["http_request.req"];
|
|
|
|
public static readonly MetricDef Success = new(
|
|
"http.success", AccKind.Ratio, s_req, Ops.HttpSuccess, "HTTP success", "Share of requests that got an answer with an accepted status.", Better.Higher,
|
|
[new MetricExport("http.success", Stat.Pct, Unit.Pct, 99, 90)]);
|
|
|
|
public static readonly MetricDef Dns = Metric.Histogram(
|
|
"http.dns_ms", s_req, Ops.HttpPhaseMs("dns_us"), "DNS time", "Time to resolve the target host name.", Unit.Ms, [Stat.P95], good: 50, poor: 300);
|
|
|
|
public static readonly MetricDef Tcp = Metric.Histogram(
|
|
"http.tcp_ms", s_req, Ops.HttpPhaseMs("tcp_us"), "TCP connect time", "Time to establish the TCP connection (HTTP/1.1 and HTTP/2).", Unit.Ms, [Stat.P95], good: 100, poor: 400);
|
|
|
|
public static readonly MetricDef Ttfb = Metric.Histogram(
|
|
"http.ttfb_ms", s_req, Ops.HttpPhaseMs("ttfb_us"), "Time to first byte", "Time from starting the request until the response headers arrive, including connection setup.", Unit.Ms,
|
|
[Stat.P50, Stat.P95, Stat.P99], good: 300, poor: 1000);
|
|
|
|
public static readonly MetricDef Total = Metric.Histogram(
|
|
"http.total_ms", s_req, Ops.HttpPhaseMs("total_us"), "Total time", "Time until the response body was read.", Unit.Ms, [Stat.P50, Stat.P95, Stat.P99], good: 500, poor: 2000);
|
|
|
|
public static readonly MetricDef FailTimeout = Metric.Counter(
|
|
"http.fail.timeout", s_req, Ops.HttpOutcomeCount(HttpOutcome.Timeout), "HTTP timeouts", "Requests that timed out.", new MetricExport("http.fail.timeout", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailDns = Metric.Counter(
|
|
"http.fail.dns", s_req, Ops.HttpOutcomeCount(HttpOutcome.Dns), "DNS failures", "Requests whose host name did not resolve.", new MetricExport("http.fail.dns", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailReset = Metric.Counter(
|
|
"http.fail.rst", s_req, Ops.HttpOutcomeCount(HttpOutcome.Reset), "HTTP resets", "Requests answered with a reset or refused.", new MetricExport("http.fail.rst", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailTls = Metric.Counter(
|
|
"http.fail.tls", s_req, Ops.HttpOutcomeCount(HttpOutcome.Tls), "TLS failures", "Requests that ended in a TLS error.", new MetricExport("http.fail.tls", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailStatus = Metric.Counter(
|
|
"http.fail.status", s_req, Ops.HttpOutcomeCount(HttpOutcome.BadStatus), "Bad status", "Requests that got an answer with an unaccepted status.", new MetricExport("http.fail.status", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailUnsupported = Metric.Counter(
|
|
"http.fail.unsupported", s_req, Ops.HttpOutcomeCount(HttpOutcome.Unsupported), "Unsupported version", "Requests that could not use the requested HTTP version (for HTTP/3: no QUIC library, or the server does not offer it).", new MetricExport("http.fail.unsupported", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef FailOther = Metric.Counter(
|
|
"http.fail.other", s_req, Ops.HttpOutcomeCount(HttpOutcome.Other), "Other failures", "Requests that failed for a reason not listed separately.", new MetricExport("http.fail.other", Stat.Count, Unit.Count));
|
|
|
|
public static readonly MetricDef Samples = Metric.Counter(
|
|
"n.http", s_req, Ops.RowCount, "http samples", "Number of http requests.", new MetricExport("n.http", Stat.Count, Unit.Count), Better.None);
|
|
}
|