Ejemplo n.º 1
0
func startAgent() {
	if !cfg.GetNode().Active {
		go runAgent()
	} else {
		log.Warnln("Node already active")
	}
}
Ejemplo n.º 2
0
func createCpusetCpus(cpusetcpus string, cores int) string {
	if cpusetcpus == "" {
		if cores < 1 {
			log.Warnln("Number of requested CPUs = 0. Setting to 1")
			cores = 1
		}
		if assigned, ok := res.GetCoresAvailable(cores); ok {
			cpusetcpus = assigned
		} else {
			log.Debugln("Error setting cpusetcpus in hostconfig")
		}
	}

	return cpusetcpus
}
Ejemplo n.º 3
0
func Run(chosenPolicy *data.Policy) {
	log.WithField("status", "init").Debugln("Gru Executor")
	defer log.WithField("status", "done").Debugln("Gru Executor")

	if chosenPolicy == nil {
		log.Warnln("No policy to execute")
		return
	}

	for _, target := range chosenPolicy.Targets {
		actions := chosenPolicy.Actions[target]
		srv := getTargetService(target)
		executeActions(srv, actions)
	}

}
Ejemplo n.º 4
0
func Run(clusterData data.Shared) *data.Policy {
	log.WithField("status", "init").Debugln("Gru Planner")
	defer log.WithField("status", "done").Debugln("Gru Planner")

	var chosenPolicy *data.Policy

	if len(clusterData.Service) == 0 {
		log.Warnln("No cluster data for policy computation")
		return chosenPolicy
	}

	srvList := getServicesListFromClusterData(clusterData)
	policies := policy.CreatePolicies(srvList, clusterData)
	chosenPolicy = currentStrategy.MakeDecision(policies)
	data.SavePolicy(*chosenPolicy)
	displayPolicy(chosenPolicy)

	return chosenPolicy
}
Ejemplo n.º 5
0
func StopMonitor() {
	ch_stop <- struct{}{}
	log.Warnln("Autonomic monitor stopped")
}
Ejemplo n.º 6
0
func updateMetrics() {
	var err error
	metrics = newMetrics()
	metrics.Node.UUID = cfg.GetNodeConfig().UUID
	metrics.Node.Name = cfg.GetNodeConfig().Name
	metrics.Node.Resources.CPU.Total = res.GetResources().CPU.Total
	metrics.Node.Resources.CPU.Availabe = res.GetResources().CPU.Total - res.GetResources().CPU.Used
	localShared, err := data.GetSharedLocal()
	if err != nil {
		log.WithField("err", err).Warnln("Cannot update node active metric")
	} else {
		metrics.Node.ActiveServices = len(localShared.System.ActiveServices)
	}

	for _, name := range service.List() {
		srv, _ := service.GetServiceByName(name)
		srv_metrics := metrics.Service[name]
		srv_metrics.Name = name
		srv_metrics.Image = srv.Image
		srv_metrics.Type = srv.Type

		srv_metrics.Instances.All = len(srv.Instances.All)
		srv_metrics.Instances.Pending = len(srv.Instances.Pending)
		srv_metrics.Instances.Running = len(srv.Instances.Running)
		srv_metrics.Instances.Paused = len(srv.Instances.Paused)
		srv_metrics.Instances.Stopped = len(srv.Instances.Stopped)

		stats, err := data.GetStats()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update stats metrics")
		} else {
			if srv_stats, ok := stats.Metrics.Service[name]; ok {
				srv_metrics.Stats = srv_stats
			} else {
				log.Warnln("Cannot find stats metrics for service ", name)
			}

			metrics.Node.Stats = stats.Metrics.System
		}

		analytics, err := data.GetAnalytics()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update analytics metrics")
		} else {
			if srv_analytisc, ok := analytics.Service[name]; ok {
				srv_metrics.Analytics = srv_analytisc
			} else {
				log.Debugln("Cannot find analytics metrics for service ", name)
			}
		}

		shared, err := data.GetSharedCluster()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update shared data metrics")
		} else {
			if srv_shared, ok := shared.Service[name]; ok {
				srv_metrics.Shared = srv_shared.Data
			}
		}

		metrics.Service[name] = srv_metrics
	}

	plc, err := data.GetPolicy()
	if err != nil {
		log.WithField("err", err).Warnln("Cannot update plans metrics")
	} else {
		metrics.Policy.Name = plc.Name
		metrics.Policy.Weight = plc.Weight
	}

}