Пример #1
0
func handle_UnManagedNode(hostname string, ctxt string) error {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
	var node models.Node
	err := coll.Find(bson.M{"hostname": hostname}).One(&node)
	if err == mgo.ErrNotFound {
		node.Hostname = hostname
		node.State = models.NODE_STATE_UNACCEPTED
		if node.Fingerprint, err = skyring.GetCoreNodeManager().GetFingerPrint(node.Hostname, ctxt); err != nil {
			logger.Get().Error(fmt.Sprintf("%s-Faild to retrive fingerprint from : %s", ctxt, node.Hostname))
			return err
		}
		if err := coll.Insert(node); err != nil {
			logger.Get().Error(fmt.Sprintf("%s-Error adding Unmanaged node : %s. error: %v", ctxt, node.Hostname, err))
			return err
		}
		return nil
	}
	return errors.New(fmt.Sprintf("Node with hostname: %v already exists", hostname))
}
Пример #2
0
func updateStorageNodeToDB(storage_node models.Node, ctxt string) error {
	// Add the node details to the DB
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
	var node models.Node
	err := coll.Find(bson.M{"nodeid": storage_node.NodeId}).One(&node)
	if err == mgo.ErrNotFound {
		storage_node.State = models.NODE_STATE_ACTIVE
		if err := coll.Update(bson.M{"hostname": storage_node.Hostname}, storage_node); err != nil {
			logger.Get().Critical("%s-Error Updating the node: %s. error: %v", ctxt, storage_node.Hostname, err)
			return err
		}
		return nil
	} else {
		logger.Get().Critical(fmt.Sprintf("%s-Node with id: %v already exists", ctxt, storage_node.NodeId))
		return errors.New(fmt.Sprintf("Node with id: %v already exists", storage_node.NodeId))
	}
}
Пример #3
0
func SyncNodeUtilization(ctxt string, node models.Node, time_stamp_str string) {
	var disk_writes float64
	var disk_reads float64
	var interface_rx float64
	var interface_tx float64

	table_name := fmt.Sprintf("%s.%s.", conf.SystemConfig.TimeSeriesDBConfig.CollectionName, strings.Replace(node.Hostname, ".", "_", -1))
	if node.Utilizations == nil {
		node.Utilizations = make(map[string]models.Utilization)
	}

	/*
		Node wise storage utilization
	*/

	storage_utilization(ctxt, &node, time_stamp_str, table_name)

	/*
		Get memory statistics
	*/
	memory_utilization(ctxt, &node, time_stamp_str)

	/*
		Get cpu user utilization
	*/
	cpu_utilization(ctxt, &node, time_stamp_str)

	/*
		Get swap used
	*/
	swap_utilization(ctxt, &node, time_stamp_str)

	//Network used
	network_utilization(ctxt, &node, time_stamp_str)

	if err := update_utilizations(node.NodeId, node.Utilizations); err != nil {
		logger.Get().Warning("%s - Failed to update utilizations of node %v to db.Error %v", ctxt, node.Hostname, err)
	}

	// Aggregate disk read
	disk_reads_count := 1
	resourcePrefix := monitoring.AGGREGATION + monitoring.DISK
	resource_name, resourceNameError := GetMonitoringManager().GetResourceName(map[string]interface{}{"resource_name": resourcePrefix + monitoring.READ})
	if resourceNameError != nil {
		logger.Get().Warning("%s - Failed to fetch resource name of %v for %v .Err %v", ctxt, resource_name, node.Hostname, resourceNameError)
	} else {
		disk_reads = FetchAggregatedStatsFromGraphite(ctxt, node.Hostname, resource_name, &disk_reads_count, []string{})
	}

	// Aggregate disk write
	disk_writes_count := 1
	resource_name, resourceNameError = GetMonitoringManager().GetResourceName(map[string]interface{}{"resource_name": resourcePrefix + monitoring.WRITE})
	if resourceNameError != nil {
		logger.Get().Warning("%s - Failed to fetch resource name of %v for %v.Err %v", ctxt, resource_name, node.Hostname, resourceNameError)
	} else {
		disk_writes = FetchAggregatedStatsFromGraphite(ctxt, node.Hostname, resource_name, &disk_writes_count, []string{})
	}
	if disk_writes_count != 0 && disk_reads_count != 0 {
		UpdateMetricToTimeSeriesDb(ctxt, math.Floor(disk_reads+disk_writes+0.5), time_stamp_str, fmt.Sprintf("%s%s-%s_%s", table_name, monitoring.DISK, monitoring.READ, monitoring.WRITE))
	}
	// Aggregate interface rx
	interface_rx_count := 1
	resourcePrefix = monitoring.AGGREGATION + monitoring.INTERFACE + monitoring.OCTETS
	resource_name, resourceNameError = GetMonitoringManager().GetResourceName(map[string]interface{}{"resource_name": resourcePrefix + monitoring.RX})
	if resourceNameError != nil {
		logger.Get().Warning("%s - Failed to fetch resource name of %v for %v.Err %v", ctxt, resourcePrefix+monitoring.RX, node.Hostname, resourceNameError)
	} else {
		interface_rx = FetchAggregatedStatsFromGraphite(ctxt, node.Hostname, resource_name, &interface_rx_count, []string{monitoring.LOOP_BACK_INTERFACE})
	}

	// Aggregate interface tx
	interface_tx_count := 1
	resource_name, resourceNameError = GetMonitoringManager().GetResourceName(map[string]interface{}{"resource_name": resourcePrefix + monitoring.TX})
	if resourceNameError != nil {
		logger.Get().Warning("%s - Failed to fetch resource name of %v for %v.Err %v", ctxt, resource_name, node.Hostname, resourceNameError)
	} else {
		interface_tx = FetchAggregatedStatsFromGraphite(ctxt, node.Hostname, resource_name, &interface_tx_count, []string{monitoring.LOOP_BACK_INTERFACE})
	}
	if interface_rx_count != 0 && interface_tx_count != 0 {
		UpdateMetricToTimeSeriesDb(ctxt, interface_rx+interface_tx, time_stamp_str, fmt.Sprintf("%s%s-%s_%s", table_name, monitoring.INTERFACE, monitoring.RX, monitoring.TX))
	}
}
Пример #4
0
func GetStorageNodeInstance(hostname string, sProfiles []models.StorageProfile, ctxt string) (*models.Node, bool) {
	var storage_node models.Node
	storage_node.Hostname = hostname
	storage_node.Enabled = true
	storage_node.NodeId, _ = salt_backend.GetNodeID(hostname, ctxt)
	networkInfo, err := salt_backend.GetNodeNetwork(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting network details for node: %s. error: %v", ctxt, hostname, err))
		return nil, false
	}
	storage_node.NetworkInfo = networkInfo
	addrs, err := net.LookupHost(hostname)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error looking up node IP for: %s. error: %v", ctxt, hostname, err))
		return nil, false
	}
	storage_node.ManagementIP4 = addrs[0]
	ok, err := salt_backend.NodeUp(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting status of node: %s. error: %v", ctxt, hostname, err))
		return nil, false
	}
	if ok {
		storage_node.Status = models.NODE_STATUS_OK
	} else {
		storage_node.Status = models.NODE_STATUS_ERROR
	}
	disks, err := salt_backend.GetNodeDisk(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting disk details for node: %s. error: %v", ctxt, hostname, err))
		return nil, false
	}
	for _, disk := range disks {
		dId, err := uuid.New()
		if err != nil {
			logger.Get().Error(fmt.Sprintf("%s-Unable to generate uuid for disk : %s. error: %v", ctxt, disk.DevName, err))
			return nil, false
		}
		disk.DiskId = *dId
		applyStorageProfile(&disk, sProfiles)
		storage_node.StorageDisks = append(storage_node.StorageDisks, disk)
	}

	cpus, err := salt_backend.GetNodeCpu(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting cpu details for node: %s. error: %v", ctxt, hostname, err))
		return nil, false
	}
	for _, cpu := range cpus {
		storage_node.CPUs = append(storage_node.CPUs, cpu)
	}

	osInfo, err := salt_backend.GetNodeOs(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting os details for node: %s", ctxt, hostname))
		return nil, false
	}
	storage_node.OS = osInfo

	memoryInfo, err := salt_backend.GetNodeMemory(hostname, ctxt)
	if err != nil {
		logger.Get().Error(fmt.Sprintf("%s-Error getting memory details for node: %s", ctxt, hostname))
		return nil, false
	}
	storage_node.Memory = memoryInfo

	if !storage_node.NodeId.IsZero() && len(storage_node.NetworkInfo.Subnet) != 0 && len(storage_node.StorageDisks) != 0 {
		return &storage_node, true
	} else {
		return nil, false
	}
}