Added support for regions and sub-regions

This commit is contained in:
aharper343
2025-12-23 22:57:57 -05:00
parent 22dfc25801
commit ab7073d63d

View File

@@ -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},