예제 #1
0
// Collect collects all mongodb's metrics.
func (exporter *MongodbCollector) Collect(ch chan<- prometheus.Metric) {
	mongoSess := shared.MongoSession(exporter.Opts.URI)
	defer mongoSess.Close()
	if mongoSess != nil {
		serverVersion, err := shared.MongoSessionServerVersion(mongoSess)
		if err != nil {
			glog.Errorf("Problem gathering the mongo server version: %s", err)
		}

		nodeType, err := shared.MongoSessionNodeType(mongoSess)
		if err != nil {
			glog.Errorf("Problem gathering the mongo node type: %s", err)
		}

		glog.Infof("Connected to: %s (node type: %s, server version: %s)", exporter.Opts.URI, nodeType, serverVersion)
		switch {
		case nodeType == "mongos":
			exporter.collectMongos(mongoSess, ch)
		case nodeType == "mongod":
			exporter.collectMongod(mongoSess, ch)
		case nodeType == "replset":
			exporter.collectMongodReplSet(mongoSess, ch)
		default:
			glog.Infof("Unrecognized node type %s!", nodeType)
		}
	}
}
예제 #2
0
// Describe describes all mongodb's metrics.
func (exporter *MongodbCollector) Describe(ch chan<- *prometheus.Desc) {
	glog.Info("Describing groups")
	session := shared.MongoSession(exporter.Opts.URI)
	defer session.Close()
	if session != nil {
		serverStatus := collector_mongos.GetServerStatus(session)
		if serverStatus != nil {
			serverStatus.Describe(ch)
		}
	}
}