예제 #1
0
파일: storage.go 프로젝트: ManikDV/storage
func PrintClusterInfo() {
	clusterStats, err := db.GetClusterStats()
	if err != nil {
		log.Error(err)
		return
	}

	log.Info("Mongoses:")
	for _, mongos := range clusterStats.Mongoses {
		log.Infof("\tId:%s, ping: %s, uptime:%d, isWaiting:%t \n", mongos.Id, mongos.Ping, mongos.Up, mongos.Waiting)
	}

	log.Info("Shards:")
	for _, shard := range clusterStats.Shards {
		log.Infof("\tId:%s, host:%s, tags:%s\n", shard.Id, shard.Host, shard.Tags)
	}

	log.Info("Databases:")
	for _, database := range clusterStats.Databases {
		log.Infof("\tName:%s, partitioned:%t, primary:%s\n", database.Id, database.Partitioned, database.Primary)
	}

	log.Info("Collections:")
	for _, collection := range clusterStats.Collections {
		log.Infof("\tCollection name:%s, collection count:%d\n", collection.Name, collection.Count)
	}
}
예제 #2
0
파일: handlers.go 프로젝트: ManikDV/storage
// Processes request for cluster info
func GetClusterInfo(w http.ResponseWriter, r *http.Request) {
	log.Info("GetClusterInfo")

	session := db.Session.Clone()
	defer session.Close()

	stats, err := db.GetClusterStats()
	if err != nil {
		log.Error(err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	} else {
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		w.WriteHeader(http.StatusOK)
		if err := json.NewEncoder(w).Encode(stats); err != nil {
			log.Error(err)
		}
	}
}