Esempio n. 1
0
func PopulateClusterDetails(bootstrapNode string, ctxt string) (*uuid.UUID, string, error) {
	out, err := cephapi_backend.GetCluster(bootstrapNode, ctxt)
	if err != nil {
		return nil, "", fmt.Errorf("%s-Error getting cluster details. error: %v", ctxt, err)
	}

	var cluster models.Cluster = models.Cluster{
		ClusterId: out.Id,
		Name:      out.Name,
		Type:      bigfin_conf.ProviderName,
	}
	cluster.MonitoringInterval = monitoring.DefaultClusterMonitoringInterval
	cluster.Monitoring = models.MonitoringState{
		Plugins:    utils.GetProviderSpecificDefaultThresholdValues(),
		StaleNodes: []string{},
	}
	cluster.CompatVersion = fmt.Sprintf("%f", bigfin_conf.ProviderConfig.Provider.CompatVersion)
	cluster.AutoExpand = true

	// Persist the cluster details
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
	if err := coll.Insert(cluster); err != nil {
		return nil, "", fmt.Errorf("%s-Error persisting the cluster. error: %v", ctxt, err)
	}

	return &out.Id, out.Name, nil
}
Esempio n. 2
0
func FetchStorageProfileUtilizations(ctxt string, osdDetails OSDStats, cluster models.Cluster) (statsToPush map[string]map[string]string, err error, storageProfileEvents []models.Event) {
	statsToPush = make(map[string]map[string]string)
	statsForEventAnalyse := make(map[string]float64)
	cluster.StorageProfileUsage = make(map[string]models.Utilization)
	monitoringConfig := conf.SystemConfig.TimeSeriesDBConfig
	slus, sluFetchErr := getOsds(cluster.ClusterId)
	if sluFetchErr != nil {
		return nil, sluFetchErr, []models.Event{}
	}
	currentTimeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	metric_prefix := monitoringConfig.CollectionName + "." + strings.Replace(cluster.Name, ".", "_", -1) + "." + skyring_monitoring.STORAGE_PROFILE_UTILIZATION + "_"
	var spFree int64
	var spUsed int64
	for _, slu := range slus {
		for _, osdDetail := range osdDetails.OSDs {
			if osdDetail.Name == slu.Name {

				metric_name := metric_prefix + strings.Replace(slu.StorageProfile, ".", "_", -1) + "."
				if utilization, ok := statsToPush[metric_name+skyring_monitoring.USED_SPACE]; ok {
					existingUtilization, err := strconv.ParseInt(utilization[currentTimeStamp], 10, 64)
					if err != nil {
						return nil, fmt.Errorf("Error fetching osd stats for cluster %v. Error %v", cluster.Name, err), []models.Event{}
					}
					spUsed = (osdDetail.Used * 1024) + existingUtilization
					statsToPush[metric_name+skyring_monitoring.USED_SPACE] = map[string]string{currentTimeStamp: strconv.FormatInt(spUsed, 10)}
				} else {
					spUsed = osdDetail.Used * 1024
					statsToPush[metric_name+skyring_monitoring.USED_SPACE] = map[string]string{currentTimeStamp: strconv.FormatInt(spUsed, 10)}
				}

				if utilization, ok := statsToPush[metric_name+skyring_monitoring.FREE_SPACE]; ok {
					existingUtilization, err := strconv.ParseInt(utilization[currentTimeStamp], 10, 64)
					if err != nil {
						return nil, fmt.Errorf("Error fetching osd stats for cluster %v. Error %v", cluster.Name, err), []models.Event{}
					}
					spFree = (osdDetail.Available * 1024) + existingUtilization
					statsToPush[metric_name+skyring_monitoring.FREE_SPACE] = map[string]string{currentTimeStamp: strconv.FormatInt(spFree, 10)}
				} else {
					spFree = osdDetail.Available * 1024
					statsToPush[metric_name+skyring_monitoring.FREE_SPACE] = map[string]string{currentTimeStamp: strconv.FormatInt(spFree, 10)}
				}
				var percentUsed float64
				if spUsed+spFree > 0 {
					percentUsed = float64(spUsed*100) / float64(spUsed+spFree)
				}
				cluster.StorageProfileUsage[slu.StorageProfile] = models.Utilization{Used: int64(spUsed), Total: int64(spUsed + spFree), PercentUsed: percentUsed, UpdatedAt: time.Now().String()}

				statsToPush[metric_name+skyring_monitoring.USAGE_PERCENT] = map[string]string{currentTimeStamp: fmt.Sprintf("%v", percentUsed)}

				statsForEventAnalyse[slu.StorageProfile] = percentUsed
			}
		}
	}

	for statProfile, stat := range statsForEventAnalyse {
		event, isRaiseEvent, err := skyring_utils.AnalyseThresholdBreach(ctxt, skyring_monitoring.STORAGE_PROFILE_UTILIZATION, statProfile, stat, cluster)
		if err != nil {
			logger.Get().Error("%s - Failed to analyse threshold breach for storage profile utilization of %v.Error %v", ctxt, statProfile, err)
			continue
		}
		if isRaiseEvent {
			storageProfileEvents = append(storageProfileEvents, event)
		}
	}

	if err := updateDB(
		bson.M{"clusterid": cluster.ClusterId},
		bson.M{"$set": bson.M{"storageprofileusage": cluster.StorageProfileUsage}},
		models.COLL_NAME_STORAGE_CLUSTERS); err != nil {
		logger.Get().Error("%s - Updating the storage profile statistics to db for the cluster %v failed.Error %v", ctxt, cluster.Name, err.Error())
	}

	return statsToPush, nil, storageProfileEvents
}