v0.25.5
This commit is contained in:
1 parent
1dea7f55c8
commit
c819f0a335
151 files changed
+7610
-4264
No files matched your search
@@ -31,6 +31,7 @@ pub struct Sample {
|
||||
pub request_bytes: u64,
|
||||
pub response_bytes: u64,
|
||||
pub cache: &'static str,
|
||||
pub source: &'static str,
|
||||
pub user_agent: Option<String>,
|
||||
pub country: Option<String>,
|
||||
}
|
||||
@@ -98,8 +99,11 @@ struct Counters {
|
||||
response_bytes: u64,
|
||||
countries: TopTable,
|
||||
user_agents: TopTable,
|
||||
user_agent_families: TopTable,
|
||||
client_ips: TopTable,
|
||||
methods: TopTable,
|
||||
method_families: TopTable,
|
||||
sources: TopTable,
|
||||
statuses: TopTable,
|
||||
routes: TopTable,
|
||||
paths: TopTable,
|
||||
@@ -113,6 +117,8 @@ impl Counters {
|
||||
self.request_bytes = self.request_bytes.saturating_add(sample.request_bytes);
|
||||
self.response_bytes = self.response_bytes.saturating_add(sample.response_bytes);
|
||||
self.methods.add(&sample.method, 1);
|
||||
self.method_families.add(method_family(&sample.method), 1);
|
||||
self.sources.add(sample.source, 1);
|
||||
self.statuses.add(&format!("{}xx", sample.status / 100), 1);
|
||||
self.routes.add(sample.route.as_deref().unwrap_or("(main)"), 1);
|
||||
self.paths.add(&sample.path, 1);
|
||||
@@ -122,6 +128,7 @@ impl Counters {
|
||||
}
|
||||
if let Some(user_agent) = sample.user_agent.as_deref() {
|
||||
self.user_agents.add(user_agent, 1);
|
||||
self.user_agent_families.add(user_agent_family(user_agent), 1);
|
||||
}
|
||||
if let Some(client_ip) = sample.client_ip.as_deref() {
|
||||
self.client_ips.add(client_ip, 1);
|
||||
@@ -135,8 +142,11 @@ impl Counters {
|
||||
self.response_bytes = self.response_bytes.saturating_add(other.response_bytes);
|
||||
self.countries.merge(&other.countries);
|
||||
self.user_agents.merge(&other.user_agents);
|
||||
self.user_agent_families.merge(&other.user_agent_families);
|
||||
self.client_ips.merge(&other.client_ips);
|
||||
self.methods.merge(&other.methods);
|
||||
self.method_families.merge(&other.method_families);
|
||||
self.sources.merge(&other.sources);
|
||||
self.statuses.merge(&other.statuses);
|
||||
self.routes.merge(&other.routes);
|
||||
self.paths.merge(&other.paths);
|
||||
@@ -152,8 +162,11 @@ impl Counters {
|
||||
mean_duration_ms: (self.requests > 0).then(|| self.duration_ms as f64 / self.requests as f64),
|
||||
countries: self.countries.view(),
|
||||
user_agents: self.user_agents.view(),
|
||||
user_agent_families: self.user_agent_families.view(),
|
||||
client_ips: self.client_ips.view(),
|
||||
methods: self.methods.view(),
|
||||
method_families: self.method_families.view(),
|
||||
sources: self.sources.view(),
|
||||
statuses: self.statuses.view(),
|
||||
routes: self.routes.view(),
|
||||
paths: self.paths.view(),
|
||||
@@ -172,8 +185,11 @@ pub struct CountersView {
|
||||
pub mean_duration_ms: Option<f64>,
|
||||
pub countries: Vec<TopEntry>,
|
||||
pub user_agents: Vec<TopEntry>,
|
||||
pub user_agent_families: Vec<TopEntry>,
|
||||
pub client_ips: Vec<TopEntry>,
|
||||
pub methods: Vec<TopEntry>,
|
||||
pub method_families: Vec<TopEntry>,
|
||||
pub sources: Vec<TopEntry>,
|
||||
pub statuses: Vec<TopEntry>,
|
||||
pub routes: Vec<TopEntry>,
|
||||
pub paths: Vec<TopEntry>,
|
||||
@@ -275,6 +291,52 @@ impl Analytics {
|
||||
}
|
||||
}
|
||||
|
||||
fn method_family(method: &str) -> &'static str {
|
||||
match method {
|
||||
"GET" => "GET",
|
||||
"HEAD" => "HEAD",
|
||||
"POST" => "POST",
|
||||
"PUT" => "PUT",
|
||||
"PATCH" => "PATCH",
|
||||
"DELETE" => "DELETE",
|
||||
"OPTIONS" => "OPTIONS",
|
||||
"CONNECT" => "CONNECT",
|
||||
"TRACE" => "TRACE",
|
||||
_ => "OTHER",
|
||||
}
|
||||
}
|
||||
|
||||
fn user_agent_family(value: &str) -> &'static str {
|
||||
let lower = value.to_ascii_lowercase();
|
||||
if lower.contains("bot") || lower.contains("spider") || lower.contains("crawler") || lower.contains("slurp") {
|
||||
"bot"
|
||||
} else if lower.contains("curl/") {
|
||||
"curl"
|
||||
} else if lower.contains("wget/") {
|
||||
"wget"
|
||||
} else if lower.contains("python-requests") || lower.contains("python/") || lower.contains("aiohttp/") {
|
||||
"python"
|
||||
} else if lower.contains("go-http-client") {
|
||||
"go"
|
||||
} else if lower.contains("java/") || lower.contains("okhttp/") {
|
||||
"java"
|
||||
} else if lower.contains("postmanruntime/") {
|
||||
"postman"
|
||||
} else if lower.contains("edg/") || lower.contains("edge/") {
|
||||
"edge"
|
||||
} else if lower.contains("opr/") || lower.contains("opera") {
|
||||
"opera"
|
||||
} else if lower.contains("chrome/") || lower.contains("crios/") {
|
||||
"chrome"
|
||||
} else if lower.contains("firefox/") || lower.contains("fxios/") {
|
||||
"firefox"
|
||||
} else if lower.contains("safari/") {
|
||||
"safari"
|
||||
} else {
|
||||
"other"
|
||||
}
|
||||
}
|
||||
|
||||
fn truncate(value: &str, max_bytes: usize) -> String {
|
||||
if value.len() <= max_bytes {
|
||||
return value.to_owned();
|
||||
|
||||
Reference in new issue
Block a user