| 
									
										
										
										
											2015-03-23 03:14:00 +08:00
										 |  |  | package metrics | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"bytes" | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 	"runtime" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/bus" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/models" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/plugins" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/setting" | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	"github.com/prometheus/client_golang/prometheus" | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-03-23 03:14:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | const exporterName = "grafana" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 03:14:00 +08:00
										 |  |  | var ( | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 	M_Instance_Start       prometheus.Counter | 
					
						
							|  |  |  | 	M_Page_Status          *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Api_Status           *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Proxy_Status         *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Http_Request_Total   *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Http_Request_Summary *prometheus.SummaryVec | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	M_Api_User_SignUpStarted   prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_User_SignUpCompleted prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_User_SignUpInvite    prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Dashboard_Save       prometheus.Summary | 
					
						
							|  |  |  | 	M_Api_Dashboard_Get        prometheus.Summary | 
					
						
							|  |  |  | 	M_Api_Dashboard_Search     prometheus.Summary | 
					
						
							|  |  |  | 	M_Api_Admin_User_Create    prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Login_Post           prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Login_OAuth          prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Org_Create           prometheus.Counter | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Api_Dashboard_Snapshot_Create      prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Dashboard_Snapshot_External    prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Dashboard_Snapshot_Get         prometheus.Counter | 
					
						
							|  |  |  | 	M_Api_Dashboard_Insert               prometheus.Counter | 
					
						
							|  |  |  | 	M_Alerting_Result_State              *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Alerting_Notification_Sent         *prometheus.CounterVec | 
					
						
							|  |  |  | 	M_Aws_CloudWatch_GetMetricStatistics prometheus.Counter | 
					
						
							|  |  |  | 	M_Aws_CloudWatch_ListMetrics         prometheus.Counter | 
					
						
							| 
									
										
										
										
											2018-04-16 15:50:13 +08:00
										 |  |  | 	M_Aws_CloudWatch_GetMetricData       prometheus.Counter | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_DB_DataSource_QueryById            prometheus.Counter | 
					
						
							| 
									
										
										
										
											2016-06-03 18:50:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Timers
 | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_DataSource_ProxyReq_Timer prometheus.Summary | 
					
						
							|  |  |  | 	M_Alerting_Execution_Time   prometheus.Summary | 
					
						
							| 
									
										
										
										
											2016-09-22 17:16:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// StatTotals
 | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_Alerting_Active_Alerts prometheus.Gauge | 
					
						
							|  |  |  | 	M_StatTotal_Dashboards   prometheus.Gauge | 
					
						
							|  |  |  | 	M_StatTotal_Users        prometheus.Gauge | 
					
						
							| 
									
										
										
										
											2018-04-17 16:20:01 +08:00
										 |  |  | 	M_StatActive_Users       prometheus.Gauge | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_StatTotal_Orgs         prometheus.Gauge | 
					
						
							|  |  |  | 	M_StatTotal_Playlists    prometheus.Gauge | 
					
						
							| 
									
										
										
										
											2018-10-30 18:18:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// M_Grafana_Version is a gauge that contains build info about this binary
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Deprecated: use M_Grafana_Build_Version instead.
 | 
					
						
							|  |  |  | 	M_Grafana_Version *prometheus.GaugeVec | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// grafanaBuildVersion is a gauge that contains build info about this binary
 | 
					
						
							|  |  |  | 	grafanaBuildVersion *prometheus.GaugeVec | 
					
						
							| 
									
										
										
										
											2016-06-03 18:50:51 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-03-23 03:14:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | func newCounterVecStartingAtZero(opts prometheus.CounterOpts, labels []string, labelValues ...string) *prometheus.CounterVec { | 
					
						
							|  |  |  | 	counter := prometheus.NewCounterVec(opts, labels) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, label := range labelValues { | 
					
						
							|  |  |  | 		counter.WithLabelValues(label).Add(0) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return counter | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func newCounterStartingAtZero(opts prometheus.CounterOpts, labelValues ...string) prometheus.Counter { | 
					
						
							|  |  |  | 	counter := prometheus.NewCounter(opts) | 
					
						
							|  |  |  | 	counter.Add(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return counter | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | func init() { | 
					
						
							|  |  |  | 	M_Instance_Start = prometheus.NewCounter(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "instance_start_total", | 
					
						
							|  |  |  | 		Help:      "counter for started instances", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	httpStatusCodes := []string{"200", "404", "500", "unknown"} | 
					
						
							|  |  |  | 	M_Page_Status = newCounterVecStartingAtZero( | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 			Name:      "page_response_status_total", | 
					
						
							|  |  |  | 			Help:      "page http response status", | 
					
						
							|  |  |  | 			Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 		}, []string{"code"}, httpStatusCodes...) | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Status = newCounterVecStartingAtZero( | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 			Name:      "api_response_status_total", | 
					
						
							|  |  |  | 			Help:      "api http response status", | 
					
						
							|  |  |  | 			Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 		}, []string{"code"}, httpStatusCodes...) | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Proxy_Status = newCounterVecStartingAtZero( | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 			Name:      "proxy_response_status_total", | 
					
						
							|  |  |  | 			Help:      "proxy http response status", | 
					
						
							|  |  |  | 			Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 		}, []string{"code"}, httpStatusCodes...) | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 	M_Http_Request_Total = prometheus.NewCounterVec( | 
					
						
							|  |  |  | 		prometheus.CounterOpts{ | 
					
						
							|  |  |  | 			Name: "http_request_total", | 
					
						
							|  |  |  | 			Help: "http request counter", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-09-13 21:18:52 +08:00
										 |  |  | 		[]string{"handler", "statuscode", "method"}, | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Http_Request_Summary = prometheus.NewSummaryVec( | 
					
						
							|  |  |  | 		prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-19 06:56:17 +08:00
										 |  |  | 			Name: "http_request_duration_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 			Help: "http request summary", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-09-13 21:18:52 +08:00
										 |  |  | 		[]string{"handler", "statuscode", "method"}, | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_User_SignUpStarted = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_user_signup_started_total", | 
					
						
							|  |  |  | 		Help:      "amount of users who started the signup flow", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_User_SignUpCompleted = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_user_signup_completed_total", | 
					
						
							|  |  |  | 		Help:      "amount of users who completed the signup flow", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_User_SignUpInvite = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_user_signup_invite_total", | 
					
						
							|  |  |  | 		Help:      "amount of users who have been invited", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Api_Dashboard_Save = prometheus.NewSummary(prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-19 06:56:17 +08:00
										 |  |  | 		Name:      "api_dashboard_save_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Help:      "summary for dashboard save duration", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Api_Dashboard_Get = prometheus.NewSummary(prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-19 06:56:17 +08:00
										 |  |  | 		Name:      "api_dashboard_get_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Help:      "summary for dashboard get duration", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Api_Dashboard_Search = prometheus.NewSummary(prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-19 06:56:17 +08:00
										 |  |  | 		Name:      "api_dashboard_search_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Help:      "summary for dashboard search duration", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Admin_User_Create = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_admin_user_created_total", | 
					
						
							|  |  |  | 		Help:      "api admin user created counter", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Login_Post = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_login_post_total", | 
					
						
							|  |  |  | 		Help:      "api login post counter", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Login_OAuth = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_login_oauth_total", | 
					
						
							|  |  |  | 		Help:      "api login oauth counter", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Org_Create = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_org_create_total", | 
					
						
							|  |  |  | 		Help:      "api org created counter", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Dashboard_Snapshot_Create = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_dashboard_snapshot_create_total", | 
					
						
							|  |  |  | 		Help:      "dashboard snapshots created", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Dashboard_Snapshot_External = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_dashboard_snapshot_external_total", | 
					
						
							|  |  |  | 		Help:      "external dashboard snapshots created", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Dashboard_Snapshot_Get = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_dashboard_snapshot_get_total", | 
					
						
							|  |  |  | 		Help:      "loaded dashboards", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Api_Dashboard_Insert = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "api_models_dashboard_insert_total", | 
					
						
							|  |  |  | 		Help:      "dashboards inserted ", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Alerting_Result_State = prometheus.NewCounterVec(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "alerting_result_total", | 
					
						
							|  |  |  | 		Help:      "alert execution result counter", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}, []string{"state"}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Alerting_Notification_Sent = prometheus.NewCounterVec(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "alerting_notification_sent_total", | 
					
						
							|  |  |  | 		Help:      "counter for how many alert notifications been sent", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}, []string{"type"}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Aws_CloudWatch_GetMetricStatistics = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "aws_cloudwatch_get_metric_statistics_total", | 
					
						
							|  |  |  | 		Help:      "counter for getting metric statistics from aws", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Aws_CloudWatch_ListMetrics = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "aws_cloudwatch_list_metrics_total", | 
					
						
							|  |  |  | 		Help:      "counter for getting list of metrics from aws", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_Aws_CloudWatch_GetMetricData = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2018-04-16 15:50:13 +08:00
										 |  |  | 		Name:      "aws_cloudwatch_get_metric_data_total", | 
					
						
							|  |  |  | 		Help:      "counter for getting metric data time series from aws", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:46:04 +08:00
										 |  |  | 	M_DB_DataSource_QueryById = newCounterStartingAtZero(prometheus.CounterOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "db_datasource_query_by_id_total", | 
					
						
							|  |  |  | 		Help:      "counter for getting datasource by id", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_DataSource_ProxyReq_Timer = prometheus.NewSummary(prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-19 06:56:17 +08:00
										 |  |  | 		Name:      "api_dataproxy_request_all_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-10-30 19:50:57 +08:00
										 |  |  | 		Help:      "summary for dataproxy request duration", | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_Alerting_Execution_Time = prometheus.NewSummary(prometheus.SummaryOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-15 01:28:54 +08:00
										 |  |  | 		Name:      "alerting_execution_time_milliseconds", | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Help:      "summary of alert exeuction duration", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_Alerting_Active_Alerts = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "alerting_active_alerts", | 
					
						
							|  |  |  | 		Help:      "amount of active alerts", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_StatTotal_Dashboards = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "stat_totals_dashboard", | 
					
						
							|  |  |  | 		Help:      "total amount of dashboards", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_StatTotal_Users = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "stat_total_users", | 
					
						
							|  |  |  | 		Help:      "total amount of users", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 16:20:01 +08:00
										 |  |  | 	M_StatActive_Users = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							|  |  |  | 		Name:      "stat_active_users", | 
					
						
							|  |  |  | 		Help:      "number of active users", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	M_StatTotal_Orgs = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "stat_total_orgs", | 
					
						
							|  |  |  | 		Help:      "total amount of orgs", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	M_StatTotal_Playlists = prometheus.NewGauge(prometheus.GaugeOpts{ | 
					
						
							| 
									
										
										
										
											2017-09-14 00:19:16 +08:00
										 |  |  | 		Name:      "stat_total_playlists", | 
					
						
							|  |  |  | 		Help:      "total amount of playlists", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-09-26 21:25:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	M_Grafana_Version = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | 
					
						
							|  |  |  | 		Name:      "info", | 
					
						
							| 
									
										
										
										
											2018-10-30 18:18:43 +08:00
										 |  |  | 		Help:      "Information about the Grafana. This metric is deprecated. please use `grafana_build_info`", | 
					
						
							| 
									
										
										
										
											2017-09-26 21:25:44 +08:00
										 |  |  | 		Namespace: exporterName, | 
					
						
							|  |  |  | 	}, []string{"version"}) | 
					
						
							| 
									
										
										
										
											2018-10-30 18:18:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	grafanaBuildVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | 
					
						
							|  |  |  | 		Name:      "build_info", | 
					
						
							|  |  |  | 		Help:      "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built.", | 
					
						
							|  |  |  | 		Namespace: exporterName, | 
					
						
							|  |  |  | 	}, []string{"version", "revision", "branch", "goversion"}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // SetBuildInformation sets the build information for this binary
 | 
					
						
							|  |  |  | func SetBuildInformation(version, revision, branch string) { | 
					
						
							|  |  |  | 	// We export this info twice for backwards compability.
 | 
					
						
							|  |  |  | 	// Once this have been released for some time we should be able to remote `M_Grafana_Version`
 | 
					
						
							|  |  |  | 	// The reason we added a new one is that its common practice in the prometheus community
 | 
					
						
							|  |  |  | 	// to name this metric `*_build_info` so its easy to do aggregation on all programs.
 | 
					
						
							|  |  |  | 	M_Grafana_Version.WithLabelValues(version).Set(1) | 
					
						
							|  |  |  | 	grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version()).Set(1) | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-09-22 17:16:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-03 01:54:07 +08:00
										 |  |  | func initMetricVars() { | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 	prometheus.MustRegister( | 
					
						
							|  |  |  | 		M_Instance_Start, | 
					
						
							|  |  |  | 		M_Page_Status, | 
					
						
							|  |  |  | 		M_Api_Status, | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 		M_Proxy_Status, | 
					
						
							|  |  |  | 		M_Http_Request_Total, | 
					
						
							|  |  |  | 		M_Http_Request_Summary, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		M_Api_User_SignUpStarted, | 
					
						
							|  |  |  | 		M_Api_User_SignUpCompleted, | 
					
						
							|  |  |  | 		M_Api_User_SignUpInvite, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Save, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Get, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Search, | 
					
						
							|  |  |  | 		M_DataSource_ProxyReq_Timer, | 
					
						
							|  |  |  | 		M_Alerting_Execution_Time, | 
					
						
							|  |  |  | 		M_Api_Admin_User_Create, | 
					
						
							|  |  |  | 		M_Api_Login_Post, | 
					
						
							|  |  |  | 		M_Api_Login_OAuth, | 
					
						
							|  |  |  | 		M_Api_Org_Create, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Snapshot_Create, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Snapshot_External, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Snapshot_Get, | 
					
						
							|  |  |  | 		M_Api_Dashboard_Insert, | 
					
						
							|  |  |  | 		M_Alerting_Result_State, | 
					
						
							|  |  |  | 		M_Alerting_Notification_Sent, | 
					
						
							|  |  |  | 		M_Aws_CloudWatch_GetMetricStatistics, | 
					
						
							|  |  |  | 		M_Aws_CloudWatch_ListMetrics, | 
					
						
							| 
									
										
										
										
											2018-04-16 15:50:13 +08:00
										 |  |  | 		M_Aws_CloudWatch_GetMetricData, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		M_DB_DataSource_QueryById, | 
					
						
							|  |  |  | 		M_Alerting_Active_Alerts, | 
					
						
							|  |  |  | 		M_StatTotal_Dashboards, | 
					
						
							|  |  |  | 		M_StatTotal_Users, | 
					
						
							| 
									
										
										
										
											2018-04-17 16:20:01 +08:00
										 |  |  | 		M_StatActive_Users, | 
					
						
							| 
									
										
										
										
											2017-09-06 17:23:52 +08:00
										 |  |  | 		M_StatTotal_Orgs, | 
					
						
							| 
									
										
										
										
											2017-09-26 21:25:44 +08:00
										 |  |  | 		M_StatTotal_Playlists, | 
					
						
							| 
									
										
										
										
											2018-10-30 18:18:43 +08:00
										 |  |  | 		M_Grafana_Version, | 
					
						
							|  |  |  | 		grafanaBuildVersion) | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func updateTotalStats() { | 
					
						
							| 
									
										
										
										
											2018-04-17 16:20:01 +08:00
										 |  |  | 	statsQuery := models.GetSystemStatsQuery{} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&statsQuery); err != nil { | 
					
						
							|  |  |  | 		metricsLogger.Error("Failed to get system stats", "error", err) | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-17 16:20:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	M_StatTotal_Dashboards.Set(float64(statsQuery.Result.Dashboards)) | 
					
						
							|  |  |  | 	M_StatTotal_Users.Set(float64(statsQuery.Result.Users)) | 
					
						
							|  |  |  | 	M_StatActive_Users.Set(float64(statsQuery.Result.ActiveUsers)) | 
					
						
							|  |  |  | 	M_StatTotal_Playlists.Set(float64(statsQuery.Result.Playlists)) | 
					
						
							|  |  |  | 	M_StatTotal_Orgs.Set(float64(statsQuery.Result.Orgs)) | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 19:32:55 +08:00
										 |  |  | var usageStatsURL = "https://stats.grafana.org/grafana-usage-report" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 19:33:39 +08:00
										 |  |  | func getEdition() string { | 
					
						
							|  |  |  | 	if setting.IsEnterprise { | 
					
						
							|  |  |  | 		return "enterprise" | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return "oss" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-13 01:27:21 +08:00
										 |  |  | func sendUsageStats(oauthProviders map[string]bool) { | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 	if !setting.ReportingEnabled { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	metricsLogger.Debug("Sending anonymous usage stats to stats.grafana.org") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	version := strings.Replace(setting.BuildVersion, ".", "_", -1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	metrics := map[string]interface{}{} | 
					
						
							|  |  |  | 	report := map[string]interface{}{ | 
					
						
							|  |  |  | 		"version": version, | 
					
						
							|  |  |  | 		"metrics": metrics, | 
					
						
							|  |  |  | 		"os":      runtime.GOOS, | 
					
						
							|  |  |  | 		"arch":    runtime.GOARCH, | 
					
						
							| 
									
										
										
										
											2018-07-02 19:33:39 +08:00
										 |  |  | 		"edition": getEdition(), | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	statsQuery := models.GetSystemStatsQuery{} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&statsQuery); err != nil { | 
					
						
							|  |  |  | 		metricsLogger.Error("Failed to get system stats", "error", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	metrics["stats.dashboards.count"] = statsQuery.Result.Dashboards | 
					
						
							|  |  |  | 	metrics["stats.users.count"] = statsQuery.Result.Users | 
					
						
							|  |  |  | 	metrics["stats.orgs.count"] = statsQuery.Result.Orgs | 
					
						
							|  |  |  | 	metrics["stats.playlist.count"] = statsQuery.Result.Playlists | 
					
						
							|  |  |  | 	metrics["stats.plugins.apps.count"] = len(plugins.Apps) | 
					
						
							|  |  |  | 	metrics["stats.plugins.panels.count"] = len(plugins.Panels) | 
					
						
							|  |  |  | 	metrics["stats.plugins.datasources.count"] = len(plugins.DataSources) | 
					
						
							|  |  |  | 	metrics["stats.alerts.count"] = statsQuery.Result.Alerts | 
					
						
							|  |  |  | 	metrics["stats.active_users.count"] = statsQuery.Result.ActiveUsers | 
					
						
							|  |  |  | 	metrics["stats.datasources.count"] = statsQuery.Result.Datasources | 
					
						
							| 
									
										
										
										
											2018-01-24 05:51:05 +08:00
										 |  |  | 	metrics["stats.stars.count"] = statsQuery.Result.Stars | 
					
						
							| 
									
										
										
										
											2018-05-25 20:33:37 +08:00
										 |  |  | 	metrics["stats.folders.count"] = statsQuery.Result.Folders | 
					
						
							|  |  |  | 	metrics["stats.dashboard_permissions.count"] = statsQuery.Result.DashboardPermissions | 
					
						
							|  |  |  | 	metrics["stats.folder_permissions.count"] = statsQuery.Result.FolderPermissions | 
					
						
							|  |  |  | 	metrics["stats.provisioned_dashboards.count"] = statsQuery.Result.ProvisionedDashboards | 
					
						
							|  |  |  | 	metrics["stats.snapshots.count"] = statsQuery.Result.Snapshots | 
					
						
							|  |  |  | 	metrics["stats.teams.count"] = statsQuery.Result.Teams | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dsStats := models.GetDataSourceStatsQuery{} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&dsStats); err != nil { | 
					
						
							|  |  |  | 		metricsLogger.Error("Failed to get datasource stats", "error", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// send counters for each data source
 | 
					
						
							|  |  |  | 	// but ignore any custom data sources
 | 
					
						
							|  |  |  | 	// as sending that name could be sensitive information
 | 
					
						
							|  |  |  | 	dsOtherCount := 0 | 
					
						
							|  |  |  | 	for _, dsStat := range dsStats.Result { | 
					
						
							|  |  |  | 		if models.IsKnownDataSourcePlugin(dsStat.Type) { | 
					
						
							|  |  |  | 			metrics["stats.ds."+dsStat.Type+".count"] = dsStat.Count | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			dsOtherCount += dsStat.Count | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	metrics["stats.ds.other.count"] = dsOtherCount | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 22:00:15 +08:00
										 |  |  | 	dsAccessStats := models.GetDataSourceAccessStatsQuery{} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&dsAccessStats); err != nil { | 
					
						
							|  |  |  | 		metricsLogger.Error("Failed to get datasource access stats", "error", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// send access counters for each data source
 | 
					
						
							|  |  |  | 	// but ignore any custom data sources
 | 
					
						
							|  |  |  | 	// as sending that name could be sensitive information
 | 
					
						
							|  |  |  | 	dsAccessOtherCount := make(map[string]int64) | 
					
						
							|  |  |  | 	for _, dsAccessStat := range dsAccessStats.Result { | 
					
						
							|  |  |  | 		if dsAccessStat.Access == "" { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		access := strings.ToLower(dsAccessStat.Access) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if models.IsKnownDataSourcePlugin(dsAccessStat.Type) { | 
					
						
							|  |  |  | 			metrics["stats.ds_access."+dsAccessStat.Type+"."+access+".count"] = dsAccessStat.Count | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			old := dsAccessOtherCount[access] | 
					
						
							|  |  |  | 			dsAccessOtherCount[access] = old + dsAccessStat.Count | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for access, count := range dsAccessOtherCount { | 
					
						
							|  |  |  | 		metrics["stats.ds_access.other."+access+".count"] = count | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 03:03:09 +08:00
										 |  |  | 	anStats := models.GetAlertNotifierUsageStatsQuery{} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&anStats); err != nil { | 
					
						
							|  |  |  | 		metricsLogger.Error("Failed to get alert notification stats", "error", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, stats := range anStats.Result { | 
					
						
							|  |  |  | 		metrics["stats.alert_notifiers."+stats.Type+".count"] = stats.Count | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-13 01:27:21 +08:00
										 |  |  | 	authTypes := map[string]bool{} | 
					
						
							|  |  |  | 	authTypes["anonymous"] = setting.AnonymousEnabled | 
					
						
							|  |  |  | 	authTypes["basic_auth"] = setting.BasicAuthEnabled | 
					
						
							|  |  |  | 	authTypes["ldap"] = setting.LdapEnabled | 
					
						
							|  |  |  | 	authTypes["auth_proxy"] = setting.AuthProxyEnabled | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for provider, enabled := range oauthProviders { | 
					
						
							|  |  |  | 		authTypes["oauth_"+provider] = enabled | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for authType, enabled := range authTypes { | 
					
						
							|  |  |  | 		enabledValue := 0 | 
					
						
							|  |  |  | 		if enabled { | 
					
						
							|  |  |  | 			enabledValue = 1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		metrics["stats.auth_enabled."+authType+".count"] = enabledValue | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 05:19:57 +08:00
										 |  |  | 	out, _ := json.MarshalIndent(report, "", " ") | 
					
						
							|  |  |  | 	data := bytes.NewBuffer(out) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 02:04:58 +08:00
										 |  |  | 	client := http.Client{Timeout: 5 * time.Second} | 
					
						
							| 
									
										
										
										
											2018-05-25 19:32:55 +08:00
										 |  |  | 	go client.Post(usageStatsURL, "application/json", data) | 
					
						
							| 
									
										
										
										
											2016-06-03 18:50:51 +08:00
										 |  |  | } |