cmd/ursrv: Summarize known distribution channels

That is, whether the binary was downloaded from GitHub, from our APT
repository, etc.
This commit is contained in:
Jakob Borg 2019-05-15 13:42:55 +02:00
parent c02aed0a21
commit e16a65bacb
3 changed files with 62 additions and 14 deletions

View File

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

View File

@ -45,8 +45,24 @@ var (
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

View File

@ -506,6 +506,27 @@ found in the LICENSE file.
</table>
</div>
<div class="col-md-6">
<table class="table table-striped">
<thead>
<tr>
<th>Distribution Channel</th>
<th class="text-right">Devices</th>
<th class="text-right">Share</th>
</tr>
</thead>
<tbody>
{{range .distributions}}
<tr>
<td>{{.Key}}</td>
<td class="text-right">{{.Count}}</td>
<td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
<div class="row">