mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-03 12:13:09 -06:00
Add more fields, actually send data somewhere
This commit is contained in:
parent
c60422191e
commit
845363253a
|
|
@ -71,6 +71,11 @@ global:
|
||||||
# Whether this instance sends anonymous usage stats
|
# Whether this instance sends anonymous usage stats
|
||||||
report_stats: false
|
report_stats: false
|
||||||
|
|
||||||
|
# The endpoint to report the anonymized homeserver usage statistics to.
|
||||||
|
# Defaults to https://matrix.org/report-usage-stats/push
|
||||||
|
#
|
||||||
|
#report_stats_endpoint: https://example.com/report-usage-stats/push
|
||||||
|
|
||||||
# Server notices allows server admins to send messages to all users.
|
# Server notices allows server admins to send messages to all users.
|
||||||
server_notices:
|
server_notices:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,9 @@ type Global struct {
|
||||||
|
|
||||||
// ReportStats configures anonymous usage stats of the server
|
// ReportStats configures anonymous usage stats of the server
|
||||||
ReportStats bool `yaml:"report_stats"`
|
ReportStats bool `yaml:"report_stats"`
|
||||||
|
|
||||||
|
// ReportStatsEndpoint configuration
|
||||||
|
ReportStatsEndpoint string `yaml:"report_stats_endpoint"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Global) Defaults(generate bool) {
|
func (c *Global) Defaults(generate bool) {
|
||||||
|
|
@ -74,6 +77,7 @@ func (c *Global) Defaults(generate bool) {
|
||||||
}
|
}
|
||||||
c.KeyValidityPeriod = time.Hour * 24 * 7
|
c.KeyValidityPeriod = time.Hour * 24 * 7
|
||||||
c.ReportStats = false
|
c.ReportStats = false
|
||||||
|
c.ReportStatsEndpoint = "https://matrix.org/report-usage-stats/push"
|
||||||
|
|
||||||
c.JetStream.Defaults(generate)
|
c.JetStream.Defaults(generate)
|
||||||
c.Metrics.Defaults(generate)
|
c.Metrics.Defaults(generate)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
"math"
|
||||||
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -136,6 +137,7 @@ type phoneHomeStats struct {
|
||||||
cfg *config.Dendrite
|
cfg *config.Dendrite
|
||||||
db storage.Database
|
db storage.Database
|
||||||
isMonolith bool
|
isMonolith bool
|
||||||
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
type timestampToRUUsage struct {
|
type timestampToRUUsage struct {
|
||||||
|
|
@ -152,10 +154,13 @@ func startPhoneHomeCollector(startTime time.Time, cfg *config.Dendrite, syncDB s
|
||||||
db: syncDB,
|
db: syncDB,
|
||||||
userAPI: userAPI,
|
userAPI: userAPI,
|
||||||
isMonolith: isMonolith,
|
isMonolith: isMonolith,
|
||||||
|
client: &http.Client{
|
||||||
|
Timeout: time.Second * 30,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// start initial run after 5min
|
// start initial run after 5min
|
||||||
time.AfterFunc(time.Second*10, func() {
|
time.AfterFunc(time.Second*1, func() {
|
||||||
p.collect()
|
p.collect()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -173,11 +178,15 @@ func startPhoneHomeCollector(startTime time.Time, cfg *config.Dendrite, syncDB s
|
||||||
func (p *phoneHomeStats) collect() {
|
func (p *phoneHomeStats) collect() {
|
||||||
p.stats = make(map[string]interface{})
|
p.stats = make(map[string]interface{})
|
||||||
// general information
|
// general information
|
||||||
p.stats["servername"] = p.serverName
|
p.stats["homeserver"] = p.serverName
|
||||||
p.stats["monolith"] = p.isMonolith
|
p.stats["monolith"] = p.isMonolith
|
||||||
p.stats["version"] = internal.VersionString()
|
p.stats["version"] = internal.VersionString()
|
||||||
p.stats["timestamp"] = time.Now().Unix()
|
p.stats["timestamp"] = time.Now().Unix()
|
||||||
p.stats["go_version"] = runtime.Version()
|
p.stats["go_version"] = runtime.Version()
|
||||||
|
p.stats["go_arch"] = runtime.GOARCH
|
||||||
|
p.stats["go_os"] = runtime.GOOS
|
||||||
|
p.stats["num_cpu"] = runtime.NumCPU()
|
||||||
|
p.stats["num_go_routine"] = runtime.NumGoroutine()
|
||||||
p.stats["uptime_seconds"] = math.Floor(time.Now().Sub(p.startTime).Seconds())
|
p.stats["uptime_seconds"] = math.Floor(time.Now().Sub(p.startTime).Seconds())
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute*1)
|
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute*1)
|
||||||
|
|
@ -321,5 +330,18 @@ func (p *phoneHomeStats) collect() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Collected data: %s", output.String())
|
logrus.Infof("Reporting stats to %s: %s", p.cfg.Global.ReportStatsEndpoint, output.String())
|
||||||
|
|
||||||
|
request, err := http.NewRequest("POST", p.cfg.Global.ReportStatsEndpoint, &output)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Error("unable to create phone home stats request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
request.Header.Set("User-Agent", "Dendrite/"+internal.VersionString())
|
||||||
|
|
||||||
|
_, err = p.client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Error("unable to send phone home stats")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue