Skip to content

Commit

Permalink
Merge pull request #25 from enzhu-wish/master
Browse files Browse the repository at this point in the history
Add new metrics for monitoring plan cache size
  • Loading branch information
enzhu-wish authored Aug 27, 2020
2 parents 2fc7157 + 979daa1 commit 51087ee
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion collector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,27 @@ var (
Name: "deleted_documents_total",
Help: "deletedDocuments reports the total number of documents deleted from collections with a ttl index.",
})
metricsTTLPassesTotal = prometheus.NewCounter(prometheus.CounterOpts{
metricsTTLPassesTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: "metrics_ttl",
Name: "passes_total",
Help: "passes reports the number of times the background process removes documents from collections with a ttl index",
})
)
var (
metricsQueryPlanCacheTotalSizeEstimateBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: "metrics_query",
Name: "plan_cache_total_size_estimate_bytes",
Help: "planCacheTotalSizeEstimateBytes reports the estimated size of plan cache in bytes.",
})
metricsQueryUpdateOneOpStyleBroadcastWithExactIDCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: "metrics_query",
Name: "update_broadcast_with_exact_ID_count",
Help: "updateOneOpStyleBroadcastWithExactIDCount Tracks the number of {multi:false} updates with an exact match on _id that are broadcasted to multiple shards.",
})
)

// DocumentStats are the stats associated to a document.
type DocumentStats struct {
Expand Down Expand Up @@ -404,6 +418,30 @@ func (cursorStats *CursorStats) Export(ch chan<- prometheus.Metric) {
metricsCursorOpen.WithLabelValues("total").Set(cursorStats.Open.Total)
}

// TTLStats are the stats with a ttl index
type TTLStats struct {
DeletedDocuments float64 `bson:"deletedDocuments"`
Passes float64 `bson:"passes"`
}

// Export exports the ttl stats.
func (ttlStats *TTLStats) Export(ch chan<- prometheus.Metric) {
metricsTTLDeletedDocumentsTotal.Set(ttlStats.DeletedDocuments)
metricsTTLPassesTotal.Set(ttlStats.Passes)
}

// QueryStats are the stats with a ttl index
type QueryStats struct {
PlanCacheSize float64 `bson:"planCacheTotalSizeEstimateBytes"`
UpdateCount float64 `bson:"updateOneOpStyleBroadcastWithExactIDCount"`
}

// Export exports the query stats.
func (queryStats *QueryStats) Export(ch chan<- prometheus.Metric) {
metricsQueryPlanCacheTotalSizeEstimateBytes.Set(queryStats.PlanCacheSize)
metricsQueryUpdateOneOpStyleBroadcastWithExactIDCount.Set(queryStats.UpdateCount)
}

// MetricsStats are all stats associated with metrics of the system
type MetricsStats struct {
Document *DocumentStats `bson:"document"`
Expand All @@ -414,6 +452,8 @@ type MetricsStats struct {
Repl *ReplStats `bson:"repl"`
Storage *StorageStats `bson:"storage"`
Cursor *CursorStats `bson:"cursor"`
TTL *TTLStats `bson:"ttl"`
Query *QueryStats `bson:"query"`
}

// Export exports the metrics stats.
Expand Down Expand Up @@ -442,6 +482,12 @@ func (metricsStats *MetricsStats) Export(ch chan<- prometheus.Metric) {
if metricsStats.Cursor != nil {
metricsStats.Cursor.Export(ch)
}
if metricsStats.TTL != nil {
metricsStats.TTL.Export(ch)
}
if metricsStats.Query != nil {
metricsStats.Query.Export(ch)
}

metricsCursorTimedOutTotal.Collect(ch)
metricsCursorOpen.Collect(ch)
Expand Down Expand Up @@ -473,6 +519,7 @@ func (metricsStats *MetricsStats) Export(ch chan<- prometheus.Metric) {
metricsStorageFreelistSearchTotal.Collect(ch)
metricsTTLDeletedDocumentsTotal.Collect(ch)
metricsTTLPassesTotal.Collect(ch)
metricsQueryPlanCacheTotalSizeEstimateBytes.Collect(ch)
}

// Describe describes the metrics for prometheus
Expand Down Expand Up @@ -507,4 +554,5 @@ func (metricsStats *MetricsStats) Describe(ch chan<- *prometheus.Desc) {
metricsStorageFreelistSearchTotal.Describe(ch)
metricsTTLDeletedDocumentsTotal.Describe(ch)
metricsTTLPassesTotal.Describe(ch)
metricsQueryPlanCacheTotalSizeEstimateBytes.Describe(ch)
}

0 comments on commit 51087ee

Please sign in to comment.