func UpdateStorageProfileUtilizationToSummaries(ctxt string, cluster models.Cluster) { pluginIndex := monitoring.GetPluginIndex(monitoring.STORAGE_PROFILE_UTILIZATION, cluster.Monitoring.Plugins) if pluginIndex != -1 { if storageProfileUtilization, err := ComputeStorageProfileUtilization( bson.M{"clusterid": cluster.ClusterId}, cluster.Monitoring.Plugins[pluginIndex].Configs); err != nil { logger.Get().Error("%s - Failed to fetch storage profile utilization of cluster %v.Error %v", ctxt, cluster.Name, err) } else { UpdateDb(bson.M{"clusterid": cluster.ClusterId}, bson.M{"storageprofileusage": storageProfileUtilization}, models.COLL_NAME_CLUSTER_SUMMARY, ctxt) } } systemthresholds := monitoring.GetSystemDefaultThresholdValues() utilization, err := ComputeStorageProfileUtilization(nil, systemthresholds[monitoring.STORAGE_PROFILE_UTILIZATION].Configs) if err != nil { logger.Get().Error("%s - Error updating the storage profile utilization to system summary. Error %v", ctxt, err) } else { UpdateDb(bson.M{"name": monitoring.SYSTEM}, bson.M{"storageprofileusage": utilization}, models.COLL_NAME_SKYRING_UTILIZATION, ctxt) } }
func AnalyseThresholdBreach(ctxt string, utilizationType string, resourceName string, resourceUtilization float64, cluster models.Cluster) (models.Event, bool, error) { var event models.Event timeStamp := time.Now() pluginIndex := monitoring.GetPluginIndex(utilizationType, cluster.Monitoring.Plugins) if pluginIndex == -1 { logger.Get().Error( "%s - The cluster %s is not configured to monitor threshold breaches for %v and hence cannot monitor utilization of %v", ctxt, cluster.Name, utilizationType, resourceName) return models.Event{}, false, fmt.Errorf( "%s - The cluster %s is not configured to monitor threshold breaches for %v and hence cannot monitor utilization of %v", ctxt, cluster.Name, utilizationType, resourceName) } plugin := cluster.Monitoring.Plugins[pluginIndex] var applicableConfig monitoring.PluginConfig var applicableThresholdValue float64 var message string var entityIdentifier string entityId, entityIdFetchError := getEntityIdFromNameAndUtilizationType(utilizationType, resourceName, cluster) if entityIdFetchError != nil { logger.Get().Error("%s - Error fetching the id for %v in cluster %v", ctxt, resourceName, cluster.Name) return models.Event{}, false, fmt.Errorf("%s - Error fetching the id for %v in cluster %v", ctxt, resourceName, cluster.Name) } entityIdentifier = (*entityId).String() if len(plugin.Configs) == 0 { return models.Event{}, false, fmt.Errorf("%s - No threshold configurations found for %v of %v in cluster %v", ctxt, utilizationType, resourceName, cluster.Name) } for _, config := range plugin.Configs { if config.Category == monitoring.THRESHOLD { currentThresholdValue, thresholdValError := strconv.ParseFloat(config.Value, 64) if thresholdValError != nil { logger.Get().Error("%s - %v-%v configuration for %v in cluster %v could not be converted.Err %v\n", ctxt, config.Category, config.Type, plugin.Name, cluster.Name, thresholdValError) } if resourceUtilization > currentThresholdValue && applicableThresholdValue < currentThresholdValue { applicableConfig = config applicableThresholdValue = currentThresholdValue } } } if applicableConfig.Type == "" { applicableConfig.Type = models.STATUS_OK message = fmt.Sprintf("%v of cluster %v with value %v back to normal", plugin.Name, cluster.Name, resourceUtilization) } tEvent := models.ThresholdEvent{ ClusterId: cluster.ClusterId, UtilizationType: plugin.Name, ThresholdSeverity: strings.ToUpper(applicableConfig.Type), TimeStamp: timeStamp, EntityId: *entityId, EntityName: resourceName, } err, isRaiseEvent := UpdateThresholdInfoToTable(tEvent) if err != nil { logger.Get().Error("%s - %v", ctxt, err) } if isRaiseEvent { event = models.Event{ Timestamp: timeStamp, ClusterId: cluster.ClusterId, NodeId: cluster.ClusterId, Tag: fmt.Sprintf("skyring/%v/cluster/%v/threshold/%v/%v", cluster.Type, cluster.ClusterId, plugin.Name, strings.ToUpper(applicableConfig.Type)), Tags: map[string]string{ models.CURRENT_VALUE: strconv.FormatFloat(resourceUtilization, 'E', -1, 64), models.ENTITY_ID: entityIdentifier, models.PLUGIN: plugin.Name, models.THRESHOLD_TYPE: strings.ToUpper(applicableConfig.Type), models.THRESHOLD_VALUE: strconv.FormatFloat(applicableThresholdValue, 'E', -1, 64), models.ENTITY_NAME: resourceName, }, Severity: strings.ToUpper(applicableConfig.Type), } if message == "" { message = fmt.Sprintf("%v of cluster %v with value %v breached %v threshold of value %v", plugin.Name, cluster.Name, resourceUtilization, strings.ToUpper(applicableConfig.Type), applicableThresholdValue) } event.Message = message return event, true, nil } return models.Event{}, false, nil }