Pure helper for annotating UniFi DPI stats with human-readable category and application names.
Lifted out of UnifiApi.Network.DPI so it can be used without an
HTTP client (the original wrapped it in the same module despite
being a pure data transform). The legacy
UnifiApi.Network.DPI.with_names/2 is preserved as a thin delegation
for v0.4.x to avoid a breaking change for callers who imported it
from that module; switch your alias to UnifiApi.DPI.Names when you
bump the dep — the function will be dropped from Network.DPI in
v0.5.0.
Quick start
# Once per session — these don't change often, cache them:
{:ok, categories} = UnifiApi.Network.Resources.list_dpi_categories(client)
{:ok, applications} = UnifiApi.Network.Resources.list_dpi_applications(client)
# Then on every poll:
{:ok, dpi} = UnifiApi.Network.DPI.by_site(authed, "default")
named =
UnifiApi.DPI.Names.with_names(dpi,
categories: categories,
applications: applications
)
# Top 10 apps by tx_bytes
named
|> Enum.flat_map(& &1["by_app"])
|> Enum.sort_by(& &1["tx_bytes"], :desc)
|> Enum.take(10)
|> Enum.map(&{&1["application_name"], &1["tx_bytes"]})Options
:categories— list of%{"id" => int, "name" => str}fromResources.list_dpi_categories/1. Required.:applications— list of%{"id" => int, "name" => str}fromResources.list_dpi_applications/1. Required.
Summary
Functions
Annotates DPI stats with human-readable category and application names.
Functions
Annotates DPI stats with human-readable category and application names.
Adds "category_name" to each by_cat entry and "category_name" +
"application_name" to each by_app entry. Original numeric IDs
and counters are preserved. Unknown IDs map to nil.