1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! KPI sources that are not drivers (spec 3.5 §7.12, §7.11): what the KPI tracker and the
//! experiments read besides the analytics, search-console, email and advertising drivers.
//!
//! | Source | Name | Metrics | Counts come from |
//! |---|---|---|---|
//! | [`BeaconKpi`] | `beacon` | `pageviews`, `pageviews:{path}`, `events:{name}`, `visitors` | The edge's cookieless beacon (`AwpEdge::beacon`) |
//! | [`HostLogs`] | `host_logs` | `requests`, `bytes`, `status:{2xx…5xx}`, `not_found`, `pageviews`, `pageviews:{path}`, `crawlers`, `agents`, `agents:{name}`, `machine_views`, `agents.machine_views` | Host access logs in the Common, Combined or W3C extended format; no address is kept |
//! | [`CommerceKpi`] | `commerce` | `actions`, `actions:{capability}`, `actions:{capability}:{outcome}`, `leads`, `sales` | The edge's action ledger through [`MeteredActionLedger`]; leads and sales from the site's `CommerceOutcomes` |
//! | [`SpendLedgerKpi`] | `spend` | `spend`, `spend.vendor:{vendor}`, `spend.agent:{agent}`, in USD | The runtime's spend ledger through [`MeteredSpendLedger`] |
//! | [`AgentSearchKpi`] | `agents` | `calls`, `calls:{capability}`, `agent_calls`, `agent_calls:{binding}`, `agent_calls:{capability}`, `held`, `agent_discovery`, `agent_discovery:{surface}` | The edge's capability-call and verified-discovery audit records through [`EdgeMeter`]: agent calls and discovery are those of a verified requester, a trust tier above `public` (A-I6) |
//! | [`AeoKpi`] | `aeo` | `aeo.queries`, `aeo.citations`, `aeo.citations:{provider}`, `aeo.top3`, `aeo.citation_rate`, `pages.answer_citations` | [`AeoTracker`]'s questions through `web_search` providers, at Observe |
//!
//! Search-console performance is `adk-drivers`' `SearchMetrics` (`search`), and the wallet's
//! spend, revenue, profit and cost per lead and per sale are [`crate::wallet::WalletKpi`]
//! (`spend`; register one of the two `spend` sources, or rename one with `named`).
//!
//! Every count is a daily total in a `BeaconStore` (`InMemoryBeaconStore`, or a durable
//! store the deployment provides), read over the whole days a window covers: a source answers
//! `None` for a window that covers no whole day. Each source serves one site and refuses
//! another's (A-I22).
//!
//! # Example
//!
//! ```rust
//! use std::sync::Arc;
//! use adk_kernel::charter::KpiSource;
//! use adk_server::awp::InMemoryBeaconStore;
//! use adk_website::measurement::HostLogs;
//! use chrono::{TimeZone, Utc};
//!
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> adk_kernel::Result<()> {
//! let site = uuid::Uuid::new_v4();
//! let logs = HostLogs::new(site, Arc::new(InMemoryBeaconStore::new()));
//! logs.ingest(
//! "203.0.113.9 - - [24/Oct/2026:09:15:02 +0000] \"GET /pricing/?ref=mail HTTP/1.1\" 200 5120 \"-\" \"Mozilla/5.0\"\n\
//! 203.0.113.7 - - [24/Oct/2026:09:16:40 +0000] \"GET /pricing/ HTTP/1.1\" 200 5120 \"-\" \"Mozilla/5.0 (compatible; GPTBot/1.2)\"",
//! )
//! .await?;
//! let (from, to) = (
//! Utc.with_ymd_and_hms(2026, 10, 24, 0, 0, 0).unwrap(),
//! Utc.with_ymd_and_hms(2026, 10, 25, 0, 0, 0).unwrap(),
//! );
//! assert_eq!(logs.read(site, "pageviews:/pricing/", from, to).await?, Some(1.0));
//! assert_eq!(logs.read(site, "agents:gptbot", from, to).await?, Some(1.0));
//! # Ok(())
//! # }
//! ```
use BTreeMap;
use Arc;
use KernelError;
use ;
use ;
use Uuid;
pub use ;
pub use ;
pub use BeaconKpi;
pub use ;
pub use ;
/// Refuses a read for another site than the one a source serves (A-I22).
/// The total of `metric` in `counts` over the whole days `[from, to)` covers.
async
/// Daily counts gathered in memory, then added to a store in one call per day and metric.
, u64>);