Traffic reporting
katana counts the traffic each user moves through a node and reports the totals to the panel, which bills them. This page is for operators who need to understand those numbers. It explains what katana counts, when it reports, and what happens to the counts when users change, when reporting is turned off and when a node stops.
The short version:
- katana counts, per user, the bytes of each connection’s proxy protocol stream, upload and download separately. For Hysteria 2 it counts the user’s QUIC connection.
- Every
update_periodicseconds (60 by default) it sends one report with a row for every user who moved traffic since the last report. - The counts live in memory. A clean shutdown sends one final report.
The poll cycle
Section titled “The poll cycle”Each node runs one loop. After the node has come up, katana waits update_periodic seconds and then runs one poll cycle, again and again, in this order:
| Step | Request | On failure |
|---|---|---|
| 1. Node info | Fetch the node’s parameters from the panel. An HTTP 304 (not modified) keeps the last node info. | Log a warning and keep the last node info. An answer katana cannot use or refuses, such as one with a port outside 1 to 65535, counts as a failure. |
| 2. Users | Fetch the user list. An HTTP 304 keeps the last user list. | Log a warning and keep the last user list. |
| 3. Rules | Refresh the audit rules, unless disable_get_rule = true. No request: for Xboard / V2board katana builds them from the block routes of the node config it fetched in step 1 and from the local rule list. helium’s node config carries no routes, so a helium node reads the local rule list alone. |
A rule file katana cannot read, or a rule that does not compile, is logged at WARN and left out. |
| 4. Apply | Apply any change to the node, its users and its rules. No request. | Log an error; the next cycle tries again. |
| 5. Traffic report | Send the per-user traffic counted since the last report; on helium, also the client addresses users connected from, with enable_device_limit. |
Log a warning. |
A Hysteria 2 node on Xboard / V2board with [node.hysteria].port set takes its parameters from the configuration file, so step 1 sends no request for it. helium refuses that key: its panel always describes the node.
A failure in one step does not stop the later ones.
The whole cycle for one poll looks like this:
sequenceDiagram
participant T as Timer
participant K as katana node
participant R as Runtime
participant P as Panel
T->>K: tick every update_periodic seconds
K->>P: GET node info
K->>P: GET users
opt disable_get_rule = false
K->>K: build the audit rules, no request
end
K->>R: apply node, users and rules
K->>R: take the traffic counted since the last report
alt disable_upload_traffic = true
K->>K: discard it, send nothing
else reporting on
opt at least one user moved traffic
K->>P: POST traffic report
end
end
Some timing details:
- The first report comes one full
update_periodicafter the node is up. Bringing the node up fetches node info, users and rules, but does not report. - If the node cannot come up, for example because the panel is unreachable or the port is still taken, katana logs
node 1: <reason>; retrying in <N>sand tries again. The wait starts at 1 second and doubles after each failure, up to 60 seconds orupdate_periodic, whichever is shorter. Until the node is up it runs no poll cycles. A node that is stopped before it came up has carried no traffic, so it has nothing to report. See When a node fails to start. - An accepted configuration edit that gives the node a new panel client (a change to
[node.api],enable_mtlsor[node.hysteria]that keeps the node’s identity) or drops the node’s connections (listen_ip, the certificate,disable_sniffing,[node.hysteria]or the route) runs one poll cycle at once, traffic report included. The regular timer is not reset: unless the same edit changesupdate_periodic, the next scheduled cycle comes at its usual time. An edit to[[outbound]]or[dns]runs no poll cycle. - The cycles of one node never overlap. Each request can take up to
[node.api].timeoutseconds, so a cycle against a slow panel can take several times that. - katana does not read the
push_intervalorpull_intervalthat Xboard sends in its node config.update_periodicalone sets the pace.
Settings
Section titled “Settings”Three keys shape traffic reporting. All three belong to a [[node]] entry, so each node can set its own. The full list of node keys is on Configuration file.
| Key | Type | Default | Effect |
|---|---|---|---|
[node.controller].update_periodic |
u64 |
60 |
Seconds between poll cycles, which is also the report interval. 0 is accepted and treated as 1. |
[node.controller].disable_upload_traffic |
bool |
false |
When true, katana sends no traffic reports. See Turning reporting off. |
[node.api].timeout |
u64 |
0 |
HTTP timeout in seconds for every panel request, the traffic report included. 0 means 5 seconds. |
A node that reports every 60 seconds and gives a slow panel 15 seconds to answer:
[[node]]panel_type = "NewV2board"
[node.api]host = "https://panel.example.com"key = "replace-with-the-panel-key"node_id = 1node_type = "V2ray"timeout = 15
[node.controller]update_periodic = 60disable_upload_traffic = falseThe controller section rejects unknown keys, so a misspelt key is an error instead of being ignored: katana refuses to start, and a live reload with the typo is rejected while the running configuration stays in place. katana --test -c /etc/katana/config.toml names the line and column:
configuration error: config parse error: TOML parse error at line 13, column 1A value of the wrong type, such as update_periodic = "60", fails the same way.
All three keys can be changed while katana runs:
update_periodicanddisable_upload_traffictake effect without dropping connections. katana restarts its timer with the new period, and the next cycle reads the new flag.[node.api].timeouttakes effect without dropping connections. katana rebuilds the node’s panel client in place with the new timeout: the node is not replaced, sends no final report and keeps the traffic it has counted. The new client runs one poll cycle at once, as described in The poll cycle.
See Hot reload for the full rules.
What is counted
Section titled “What is counted”katana reports what the Etemenanki runtime counts for each connection a user opens: the bytes of the proxy protocol’s stream as they cross the connection’s transport, upload and download separately.
- Upload is what came from the client, download what went to the client.
- For VMess, VLESS, Trojan, Shadowsocks, AnyTLS, SOCKS and HTTP, the stream is what runs inside TLS, REALITY, WebSocket or gRPC: the payload together with the protocol’s own handshake, headers, framing, padding and authentication tags. TLS and REALITY records, WebSocket frames and gRPC framing are not counted, and on a Vision node neither is Vision’s padding. Each gRPC stream counts as a connection of its own. An AnyTLS connection is one session: every stream in it counts toward its user, together with the authentication, the frames and the padding.
- For sss, it is the sss bytes after the transforms are undone: the request header, the payload and the UDP records. What the transforms add on the wire, or save, is not counted. See sss.
- For Hysteria 2, it is the bytes of the user’s QUIC connection, counted as UDP datagrams.
- A multiplexed connection counts as one connection: its sub-flows are part of its stream.
- A connection that never authenticates counts towards nobody. That includes a connection a REALITY node passes on to its cover site, and an sss stream refused before authentication.
- DNS lookups katana makes to resolve a destination are katana’s own traffic, not the user’s.
Because the protocol’s overhead is included, a panel’s figures are somewhat higher than the payload the user moved, and lower than the byte counts at the network interface, which also see TLS, transport framing and TCP/IP headers.
The per-user speed limit counts payload instead. See Speed limits.
How a report is built
Section titled “How a report is built”At step 5 katana takes the traffic counted since the last report and builds one request:
- One row per user, keyed by the panel’s user ID (
uid). - Open connections are included. Their traffic is counted as it goes, up to about a second before the report.
- Zero rows are skipped. A user who moved no traffic since the last report is not listed.
- No request when there is nothing to report. If no user moved traffic, katana sends no traffic request at all in that cycle. On helium a report that carries only client addresses is still sent.
- Raw bytes. katana sends plain byte counts. Any traffic multiplier, such as Xboard’s node rate, is applied by the panel.
The request body depends on the panel:
katana sends POST <host>/api/v1/server/UniProxy/push, with node_id, node_type and token in the query string. The body maps each user ID to [upload, download]:
{ "1001": [52428800, 1073741824], "1002": [0, 4096] }katana sends POST <host>/api/node/v2/<node_id>/report, with the key in an Authorization: Bearer header. The body carries a report ID, katana’s version, the traffic and the client addresses:
{ "report_id": "6f9619ff-8b86-d011-b42d-00c04fc964ff", "agent_version": "6.0.0", "traffic": [{ "id": 1001, "up": 52428800, "down": 1073741824 }], "ips": [{ "id": 1001, "ips": ["203.0.113.7"] }]}ips is empty unless enable_device_limit is on. helium’s customer IDs are 32-bit and its byte counts unsigned, so katana leaves out a row whose user ID or byte count does not fit, with a warning that names the user ID alone: traffic left out of the report: the uid or a byte count is out of range, or for client addresses client addresses left out of the report: the uid is out of range. helium describes the fields.
A failed report is logged at WARN level with its report ID, for example node 1: report 6f9619ff-8b86-d011-b42d-00c04fc964ff: POST UniProxy push, or on helium …: POST report.
When users leave, change or come back
Section titled “When users leave, change or come back”| Event | What happens to the traffic |
|---|---|
| The user is removed, disabled or expired on the panel | katana refuses the user’s new flows and ends their open connections. The traffic they moved, including the last bytes of those connections, is still reported. |
| The user’s effective speed limit changes (the user’s or the node’s limit) | Nothing changes for reporting. The user’s connections stay open. |
| The credential now belongs to a different user ID | The old user ID is removed and its open connections end. New traffic counts towards the new user ID. |
| A removed user comes back | Their new traffic is reported under their user ID, as before. |
A change drops every connection on the node, for example a new port or transport from the panel, a route edit or an [[outbound]] edit |
The traffic counted so far belongs to the node, not to its connections, so it is kept and reported. |
See Nodes for what else a user-list change does to connections.
Turning reporting off
Section titled “Turning reporting off”With disable_upload_traffic = true, katana still enforces speed limits, but it sends no traffic report: at every cycle it takes the traffic counted since the last one and discards it.
Turning reporting back on, by a hot reload or a restart, reports only the traffic moved from then on.
Shutdown, removal and crashes
Section titled “Shutdown, removal and crashes”The counts exist only in katana’s memory. Nothing is written to disk. What happens to unreported traffic depends on how the node stops:
| How the node stops | Unreported traffic |
|---|---|
SIGTERM (what systemctl stop sends) or SIGINT |
katana finishes any poll cycle in progress, closes the listener and every connection at once, then reports the remaining traffic. |
| The node is removed from the configuration file while katana runs | The same, before the node is gone. |
A node identity key changes: panel_type, [node.api].host, node_id, key, and on Xboard / V2board the node type katana asks the panel for (node_type in lower case, or vless for a V2ray, Vmess or Vless node with enable_vless) |
katana stops the old node as if it had been removed, and starts the new node with nothing counted. The requested type is part of the identity because Xboard / V2board finds a node by its ID and that type, so the same ID asked as vmess and as vless is two panel nodes; traffic carried under one is never counted towards the other. |
Crash, SIGKILL, out-of-memory kill, host power loss |
Lost: the traffic not reported yet, about one update_periodic of it. |
Give katana time to stop: the final report can take up to [node.api].timeout seconds, longer if a poll cycle was still running. A service manager that kills katana sooner loses that traffic. See Deployment for the service settings.
A shorter update_periodic narrows what a crash can lose, at the cost of more panel requests.
Panel-side effects
Section titled “Panel-side effects”These follow from how the panels read the report, not from katana:
- Xboard node rate. Xboard multiplies the reported bytes by the node’s rate before it bills them. katana always sends raw bytes.
- Xboard online users. Xboard sets a node’s online-user figure to the number of rows in the latest push. katana lists only users with traffic in that cycle, so the figure counts the users who moved bytes in the cycle of the last push. In a cycle where katana sends no push, Xboard keeps the previous figure, for up to an hour. katana reports no online users or devices to Xboard.
- Xboard node status. Xboard shows a node as online but without a push when it has fetched its user list recently but received no push for 5 minutes. katana sends no push when no user moved traffic, so an idle node shows that status. It does not mean reporting is broken.
The panel pages cover the rest of each panel’s behaviour: Xboard and V2board and helium.
Common problems
Section titled “Common problems”| Symptom | Likely cause | What to do |
|---|---|---|
| The panel shows no traffic for a node | disable_upload_traffic = true, the reports fail, or the node has not come up yet. |
Check the flag. Look for node <id>: report <id>: … warnings, and for …; retrying in … errors such as node_info failed or initial start failed, in katana’s log. |
report <id>: POST UniProxy push every cycle |
The panel is unreachable, rejects the token, or answers after the timeout. | Check [node.api].host and key, then the panel’s own logs. Raise [node.api].timeout if the panel is slow. |
| Users are billed more than the payload they moved | The protocol’s own overhead is counted, or the Xboard node rate is above 1. | Check the node rate. See What is counted. |
| Users are billed less than the interface counters show | Expected: TLS records, transport framing and TCP/IP headers are not counted. | See What is counted. |
More symptoms and log lines are on Troubleshooting.