diff --git a/cmd/ursrv/analytics.go b/cmd/ursrv/analytics.go index f103ea6df..d52c6c96c 100644 --- a/cmd/ursrv/analytics.go +++ b/cmd/ursrv/analytics.go @@ -24,10 +24,10 @@ type analyticList []analytic func (l analyticList) Less(a, b int) bool { if l[a].Key == "Others" { - return true + return false } if l[b].Key == "Others" { - return false + return true } return l[b].Count < l[a].Count // inverse } diff --git a/cmd/ursrv/main.go b/cmd/ursrv/main.go index c8ee44000..254dd59ed 100644 --- a/cmd/ursrv/main.go +++ b/cmd/ursrv/main.go @@ -33,20 +33,36 @@ import ( ) var ( - useHTTP = os.Getenv("UR_USE_HTTP") != "" - debug = os.Getenv("UR_DEBUG") != "" - keyFile = getEnvDefault("UR_KEY_FILE", "key.pem") - certFile = getEnvDefault("UR_CRT_FILE", "crt.pem") - dbConn = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable") - listenAddr = getEnvDefault("UR_LISTEN", "0.0.0.0:8443") - geoIPPath = getEnvDefault("UR_GEOIP", "GeoLite2-City.mmdb") - tpl *template.Template - compilerRe = regexp.MustCompile(`\(([A-Za-z0-9()., -]+) \w+-\w+(?:| android| default)\) ([\w@.-]+)`) - progressBarClass = []string{"", "progress-bar-success", "progress-bar-info", "progress-bar-warning", "progress-bar-danger"} - featureOrder = []string{"Various", "Folder", "Device", "Connection", "GUI"} - knownVersions = []string{"v2", "v3"} + useHTTP = os.Getenv("UR_USE_HTTP") != "" + debug = os.Getenv("UR_DEBUG") != "" + keyFile = getEnvDefault("UR_KEY_FILE", "key.pem") + certFile = getEnvDefault("UR_CRT_FILE", "crt.pem") + dbConn = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable") + listenAddr = getEnvDefault("UR_LISTEN", "0.0.0.0:8443") + geoIPPath = getEnvDefault("UR_GEOIP", "GeoLite2-City.mmdb") + tpl *template.Template + compilerRe = regexp.MustCompile(`\(([A-Za-z0-9()., -]+) \w+-\w+(?:| android| default)\) ([\w@.-]+)`) + progressBarClass = []string{"", "progress-bar-success", "progress-bar-info", "progress-bar-warning", "progress-bar-danger"} + featureOrder = []string{"Various", "Folder", "Device", "Connection", "GUI"} + knownVersions = []string{"v2", "v3"} + knownDistributions = []distributionMatch{ + // Maps well known builders to the official distribution method that + // they represent + {regexp.MustCompile("android-.*teamcity@build.syncthing.net"), "Google Play"}, + {regexp.MustCompile("teamcity@build.syncthing.net"), "GitHub"}, + {regexp.MustCompile("deb@build.syncthing.net"), "APT"}, + {regexp.MustCompile("docker@syncthing.net"), "Docker Hub"}, + {regexp.MustCompile("jenkins@build.syncthing.net"), "GitHub"}, + {regexp.MustCompile("snap@build.syncthing.net"), "Snappy"}, + {regexp.MustCompile("."), "Others"}, + } ) +type distributionMatch struct { + matcher *regexp.Regexp + distribution string +} + var funcs = map[string]interface{}{ "commatize": commatize, "number": number, @@ -1001,6 +1017,7 @@ func getReport(db *sql.DB) map[string]interface{} { var uptime []int var compilers []string var builders []string + var distributions []string locations := make(map[location]int) countries := make(map[string]int) @@ -1070,10 +1087,19 @@ func getReport(db *sql.DB) map[string]interface{} { nodes++ versions = append(versions, transformVersion(rep.Version)) platforms = append(platforms, rep.Platform) + if m := compilerRe.FindStringSubmatch(rep.LongVersion); len(m) == 3 { compilers = append(compilers, m[1]) builders = append(builders, m[2]) + loop: + for _, d := range knownDistributions { + if d.matcher.MatchString(rep.LongVersion) { + distributions = append(distributions, d.distribution) + break loop + } + } } + if rep.NumFolders > 0 { numFolders = append(numFolders, rep.NumFolders) } @@ -1366,6 +1392,7 @@ func getReport(db *sql.DB) map[string]interface{} { r["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 5) r["compilers"] = group(byCompiler, analyticsFor(compilers, 2000), 5) r["builders"] = analyticsFor(builders, 12) + r["distributions"] = analyticsFor(distributions, 10) r["featureOrder"] = featureOrder r["locations"] = locations r["contries"] = countryList diff --git a/cmd/ursrv/static/index.html b/cmd/ursrv/static/index.html index 9579a1c58..9b634e2b7 100644 --- a/cmd/ursrv/static/index.html +++ b/cmd/ursrv/static/index.html @@ -506,6 +506,27 @@ found in the LICENSE file. +
+ + + + + + + + + + {{range .distributions}} + + + + + + {{end}} + +
Distribution ChannelDevicesShare
{{.Key}}{{.Count}}{{.Percentage | printf "%.01f"}}%
+
+