From ab7073d63d28bb8321c2f547cd43f215052a0b5f Mon Sep 17 00:00:00 2001 From: aharper343 Date: Tue, 23 Dec 2025 22:57:57 -0500 Subject: [PATCH] Added support for regions and sub-regions --- pkg/promunifi/countries.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/promunifi/countries.go b/pkg/promunifi/countries.go index c5ae517b..3e9ec612 100644 --- a/pkg/promunifi/countries.go +++ b/pkg/promunifi/countries.go @@ -15,6 +15,10 @@ func descCountryTraffic(ns string) *ucountrytraffic { labels := []string{ "code", "name", + "region", + "sub_region", + "site_name", + "source", } return &ucountrytraffic{ @@ -29,11 +33,19 @@ func (u *promUnifi) exportCountryTraffic(r report, v any) { u.LogErrorf("invalid type given to CountryTraffic: %T", v) return } - name, ok := countrycodes.Alpha2ToName(s.Country) - if !ok { - name = "Unknown" + country, ok := countrycodes.GetByAlpha2(s.Country) + name := "Unknown" + region := "Unknown" + subRegion := "Unknown" + if ok { + name = country.Name + region = country.Region + subRegion = country.SubRegion } - labels := []string{s.Country, name} + if s.Country == "GB" || s.Country == "UK" { + name = "United Kingdom" // Because the name is so long otherwise + } + labels := []string{s.Country, name, region, subRegion, s.TrafficSite.SiteName, s.TrafficSite.SourceName} r.send([]*metric{ {u.CountryTraffic.RxBytes, counter, s.BytesReceived, labels}, {u.CountryTraffic.TxBytes, counter, s.BytesTransmitted, labels},