1- package collector_mongod
1+ package mongod
22
33import (
44 "github.com/prometheus/client_golang/prometheus"
4444 Name : "indexes_size" ,
4545 Help : "The total size of all indexes" ,
4646 }, []string {"db" , "coll" })
47+ collectionIndexSize = prometheus .NewGaugeVec (prometheus.GaugeOpts {
48+ Namespace : Namespace ,
49+ Subsystem : "db_coll" ,
50+ Name : "index_size" ,
51+ Help : "The individual index size" ,
52+ }, []string {"db" , "coll" , "index" })
4753)
4854
4955// CollectionStatList contains stats from all collections
@@ -55,12 +61,12 @@ type CollectionStatList struct {
5561type CollectionStatus struct {
5662 Database string
5763 Name string
58- Size int `bson:"size,omitempty"`
59- Count int `bson:"count,omitempty"`
60- AvgObjSize int `bson:"avgObjSize,omitempty"`
61- StorageSize int `bson:"storageSize,omitempty"`
62- Indexes int `bson:"indexSizes ,omitempty"`
63- IndexesSize int `bson:"totalIndexSize ,omitempty"`
64+ Size int `bson:"size,omitempty"`
65+ Count int `bson:"count,omitempty"`
66+ AvgObjSize int `bson:"avgObjSize,omitempty"`
67+ StorageSize int `bson:"storageSize,omitempty"`
68+ IndexesSize int `bson:"totalIndexSize ,omitempty"`
69+ IndexSizes map [ string ] float64 `bson:"indexSizes ,omitempty"`
6470}
6571
6672// Export exports database stats to prometheus
@@ -74,15 +80,24 @@ func (collStatList *CollectionStatList) Export(ch chan<- prometheus.Metric) {
7480 collectionObjectCount .With (ls ).Set (float64 (member .Count ))
7581 collectionAvgObjSize .With (ls ).Set (float64 (member .AvgObjSize ))
7682 collectionStorageSize .With (ls ).Set (float64 (member .StorageSize ))
77- collectionIndexes .With (ls ).Set (float64 (member .Indexes ))
83+ collectionIndexes .With (ls ).Set (float64 (len ( member .IndexSizes ) ))
7884 collectionIndexesSize .With (ls ).Set (float64 (member .IndexesSize ))
85+ for indexName , size := range member .IndexSizes {
86+ ls = prometheus.Labels {
87+ "db" : member .Database ,
88+ "coll" : member .Name ,
89+ "index" : indexName ,
90+ }
91+ collectionIndexSize .With (ls ).Set (size )
92+ }
7993 }
8094 collectionSize .Collect (ch )
8195 collectionObjectCount .Collect (ch )
8296 collectionAvgObjSize .Collect (ch )
8397 collectionStorageSize .Collect (ch )
8498 collectionIndexes .Collect (ch )
8599 collectionIndexesSize .Collect (ch )
100+ collectionIndexSize .Collect (ch )
86101}
87102
88103// Describe describes database stats for prometheus
0 commit comments