Proxy Traffic

September 3, 2026 · View on GitHub

简体中文 · English

A DankMaterialShell bar widget that monitors the real-time throughput and cumulative traffic of your local proxy via nftables counters.

Features

  • Bar pill — live proxy download/upload speed (↓1.2 MB/s ↑45 KB/s)
  • Popout panel — click the pill for a set of cards: live rates, cumulative traffic, history, destinations, redirect
  • Modular popout cards — each card (speed / cumulative / history / destinations / redirect) can be shown or hidden independently and reordered in settings
  • History card — today's traffic persisted across restarts, with a per-day line chart (proxy line 🔵, direct line 🟢) of the last N days (3/7/14/30/90), and a hover tooltip on each day showing that day's proxy/direct up & down
  • Today card — live proxy (Proxy) and direct (Direct) cumulative totals for today (up+down combined), colored blue/green
  • Persistence — both cumulative totals and the per-day history survive restarts (persisted to the plugin state), even though nftables counters reset to zero on boot
  • Proxy-only — only counts traffic flowing through the local proxy port
  • Redirect breakdown (xray) — optional per-outbound proxy vs direct byte totals (and the cumulative/history chart) read from xray's StatsService (/debug/vars)
  • Configurable display: toggle download rate / upload rate / cumulative traffic / port on the bar
  • Adjustable refresh interval (1–5 s)
  • Bilingual UI (zh/en)
  • Works with horizontal and vertical bars

Installation

Clone (or copy) this directory into the DMS plugins folder:

git clone https://github.com/Lemon-mon-254/dms-proxy-traffic.git ~/.config/DankMaterialShell/plugins/ProxyTraffic

Then in DMS: Settings → Plugins → Scan for Plugins, enable Proxy Traffic, add it to your DankBar layout and restart the shell:

dms restart

Quick start

Run the one-command installer. It installs nft if missing, creates the nftables counters for your proxy port, makes them persistent across reboots, and grants passwordless read access:

cd ~/.config/DankMaterialShell/plugins/ProxyTraffic
sudo ./setup-nftables.sh install

Use PROXY_PORT if your proxy listens on a non-default port:

PROXY_PORT=2547 sudo ./setup-nftables.sh install

Common proxy ports: Clash 7890 · v2ray/xray 10808 · sing-box 1080.

install performs the following (each also available individually):

  • detects/installs nft (nftables)
  • creates the rule file /etc/nftables.d/proxy-traffic.nft for your port
  • applies the counters immediately
  • enables a systemd service (nft-proxy-traffic.service) so counters reload on boot
  • writes /etc/sudoers.d/proxy-nft so the widget reads counters without prompting

Note: re-running install (or create) resets the counters to zero. Set the plugin's Proxy port to the same value you used here.

Configuration

SettingDefaultDescription
Proxy port7890Local proxy listen port (must match the port used to create nftables rules; common: Clash 7890 · v2ray/xray 10808 · sing-box 1080)
Refresh interval2sSampling frequency
Show download rateon↓ speed on the bar
Show upload rateon↑ speed on the bar
Show cumulativeoffShows total proxy traffic on the bar
Show portoffAppends :port
DestinationsoffPopout shows target domains & processes (proxy access log required)
Redirect (xray)offPopout shows proxy vs direct byte totals per xray outbound
Use xray for cumulativeoffCumulative total uses xray (/debug/vars) instead of nftables, so it keeps counting across reboots. Only applies on xray/v2rayN
Bar cumulative = proxy onlyoffWhen the bar shows cumulative traffic, show only the proxy amount. Needs Use xray for cumulative
Speed cardonPopout card with live down/up speeds
Cumulative cardonPopout card with cumulative down/up traffic
History cardonPopout card with today's traffic and its line chart
Chart days7How many days of history the line chart shows (3/7/14/30/90)
OrderReorder the popout cards (up/down buttons per card)
xray API port2551xray API inbound port, used for the redirect view

Important: the Proxy port in settings should match the port used when running setup-nftables.sh install, otherwise counters will not match.

Redirect breakdown (xray only, optional)

When enabled, the popout shows how much traffic left through each xray outbound (proxy vs direct), read from xray's built-in expvar endpoint:

http://127.0.0.1:<xray-api-port>/debug/vars   # -> .stats.outbound.{proxy,direct}.{downlink,uplink}
  • Requires xray/v2rayN to have outbound traffic stats enabled (policy.system.statsOutboundUplink/Downlink, enabled by default in v2rayN) and an API inbound (default 2551).
  • No nftables rules needed for this view; it supplements (not replaces) the nftables counter.
  • If the port is unreachable, the popout shows a "xray stats unavailable" hint instead of failing.
  • Besides the redirect card, xray also powers the Today card and the history line chart (proxy vs direct per day). These two always use xray for the proxy/direct split, so for a meaningful chart point the proxy API must be reachable.

Managing rules

sudo ./setup-nftables.sh show          # inspect current counters & service status
sudo ./setup-nftables.sh create        # re-create/apply counters (resets totals)
sudo ./setup-nftables.sh delete        # remove runtime counters (cumulative reset)
sudo ./setup-nftables.sh uninstall     # remove counters + service (+ optionally sudoers)

The counters are persistent (a systemd service reloads them on boot), so the plugin shows historical cumulative traffic since the table was created, across reboots.

How it works

The bundled proxy-traffic-split script reads the nftables counters and emits one JSON line:

{"up": 118045, "down": 454352, "persistent": true}
  • up — bytes sent to the local proxy port (application → proxy)
  • down — bytes received from the local proxy port (proxy → application)

The QML widget diffs consecutive samples to derive live rates, matching the difference between samples over the elapsed time.

Screenshot

ProxyTraffic overview

ProxyTraffic popout

Requirements

  • DankMaterialShell >= 1.4.0
  • nft (nftables), sudo
  • A local proxy listening on the configured port (e.g. v2ray/xray/sing-box/clash)
  • Optional (redirect view only): curl + jq, and an xray/v2rayN proxy

License

MIT