mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	feat(internal metrics): added some total stats to metrics reporting, closes #5865
This commit is contained in:
		@@ -24,10 +24,10 @@ func NewGauge(meta *MetricMeta) Gauge {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RegGauge(meta *MetricMeta) Gauge {
 | 
			
		||||
	g := NewGauge(meta)
 | 
			
		||||
	MetricStats.Register(g)
 | 
			
		||||
	return g
 | 
			
		||||
func RegGauge(name string, tagStrings ...string) Gauge {
 | 
			
		||||
	tr := NewGauge(NewMetricMeta(name, tagStrings))
 | 
			
		||||
	MetricStats.Register(tr)
 | 
			
		||||
	return tr
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GaugeSnapshot is a read-only copy of another Gauge.
 | 
			
		||||
 
 | 
			
		||||
@@ -63,6 +63,8 @@ func (this *GraphitePublisher) Publish(metrics []Metric) {
 | 
			
		||||
		switch metric := m.(type) {
 | 
			
		||||
		case Counter:
 | 
			
		||||
			this.addCount(buf, metricName+".count", metric.Count(), now)
 | 
			
		||||
		case Gauge:
 | 
			
		||||
			this.addCount(buf, metricName, metric.Value(), now)
 | 
			
		||||
		case Timer:
 | 
			
		||||
			percentiles := metric.Percentiles([]float64{0.25, 0.75, 0.90, 0.99})
 | 
			
		||||
			this.addCount(buf, metricName+".count", metric.Count(), now)
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,12 @@ var (
 | 
			
		||||
	// Timers
 | 
			
		||||
	M_DataSource_ProxyReq_Timer Timer
 | 
			
		||||
	M_Alerting_Exeuction_Time   Timer
 | 
			
		||||
 | 
			
		||||
	// StatTotals
 | 
			
		||||
	M_StatTotal_Dashboards Gauge
 | 
			
		||||
	M_StatTotal_Users      Gauge
 | 
			
		||||
	M_StatTotal_Orgs       Gauge
 | 
			
		||||
	M_StatTotal_Playlists  Gauge
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func initMetricVars(settings *MetricSettings) {
 | 
			
		||||
@@ -105,4 +111,10 @@ func initMetricVars(settings *MetricSettings) {
 | 
			
		||||
	// Timers
 | 
			
		||||
	M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
 | 
			
		||||
	M_Alerting_Exeuction_Time = RegTimer("alerting.execution_time")
 | 
			
		||||
 | 
			
		||||
	// StatTotals
 | 
			
		||||
	M_StatTotal_Dashboards = RegGauge("stat_totals", "stat", "dashboards")
 | 
			
		||||
	M_StatTotal_Users = RegGauge("stat_totals", "stat", "users")
 | 
			
		||||
	M_StatTotal_Orgs = RegGauge("stat_totals", "stat", "orgs")
 | 
			
		||||
	M_StatTotal_Playlists = RegGauge("stat_totals", "stat", "playlists")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var metricsLogger log.Logger = log.New("metrics")
 | 
			
		||||
var metricPublishCounter int64 = 0
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	settings := readSettings()
 | 
			
		||||
@@ -45,12 +46,35 @@ func sendMetrics(settings *MetricSettings) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	updateTotalStats()
 | 
			
		||||
 | 
			
		||||
	metrics := MetricStats.GetSnapshots()
 | 
			
		||||
	for _, publisher := range settings.Publishers {
 | 
			
		||||
		publisher.Publish(metrics)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func updateTotalStats() {
 | 
			
		||||
 | 
			
		||||
	// every interval also publish totals
 | 
			
		||||
	metricPublishCounter++
 | 
			
		||||
	if metricPublishCounter%2 == 0 {
 | 
			
		||||
		metricsLogger.Info("Stats!")
 | 
			
		||||
 | 
			
		||||
		// get stats
 | 
			
		||||
		statsQuery := m.GetSystemStatsQuery{}
 | 
			
		||||
		if err := bus.Dispatch(&statsQuery); err != nil {
 | 
			
		||||
			metricsLogger.Error("Failed to get system stats", "error", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		M_StatTotal_Dashboards.Update(statsQuery.Result.DashboardCount)
 | 
			
		||||
		M_StatTotal_Users.Update(statsQuery.Result.UserCount)
 | 
			
		||||
		M_StatTotal_Playlists.Update(statsQuery.Result.PlaylistCount)
 | 
			
		||||
		M_StatTotal_Orgs.Update(statsQuery.Result.OrgCount)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func sendUsageStats() {
 | 
			
		||||
	if !setting.ReportingEnabled {
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
type SystemStats struct {
 | 
			
		||||
	DashboardCount int
 | 
			
		||||
	UserCount      int
 | 
			
		||||
	OrgCount       int
 | 
			
		||||
	PlaylistCount  int
 | 
			
		||||
	DashboardCount int64
 | 
			
		||||
	UserCount      int64
 | 
			
		||||
	OrgCount       int64
 | 
			
		||||
	PlaylistCount  int64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DataSourceStats struct {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user