mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package metrics
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func StartUsageReportLoop() chan struct{} {
|
|
M_Instance_Start.Inc(1)
|
|
|
|
ticker := time.NewTicker(10 * time.Minute)
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
sendUsageStats()
|
|
}
|
|
}
|
|
}
|
|
|
|
func sendUsageStats() {
|
|
log.Trace("Sending anonymous usage stats to stats.grafana.org")
|
|
|
|
metrics := map[string]interface{}{}
|
|
report := map[string]interface{}{
|
|
"version": setting.BuildVersion,
|
|
"metrics": metrics,
|
|
}
|
|
|
|
// statsQuery := m.GetSystemStatsQuery{}
|
|
// if err := bus.Dispatch(&statsQuery); err != nil {
|
|
// log.Error(3, "Failed to get system stats", err)
|
|
// return
|
|
// }
|
|
|
|
UsageStats.Each(func(name string, i interface{}) {
|
|
switch metric := i.(type) {
|
|
case Counter:
|
|
if metric.Count() > 0 {
|
|
metrics[name+".count"] = metric.Count()
|
|
metric.Clear()
|
|
}
|
|
}
|
|
})
|
|
|
|
// metrics["stats.dashboards.count"] = statsQuery.Result.DashboardCount
|
|
// metrics["stats.users.count"] = statsQuery.Result.UserCount
|
|
// metrics["stats.orgs.count"] = statsQuery.Result.OrgCount
|
|
|
|
out, _ := json.Marshal(report)
|
|
data := bytes.NewBuffer(out)
|
|
|
|
client := http.Client{Timeout: time.Duration(5 * time.Second)}
|
|
|
|
go client.Post("http://stats.grafana.org/grafana-usage-report", "application/json", data)
|
|
}
|