Exemple #1
0
func (self *ServiceHealthCheck) checkService(instance jxaas.Instance, serviceId string, repair bool, dest *model.Health) error {
	client := instance.GetJujuClient()

	command := "service " + self.ServiceName + " status"
	log.Info("Running command on %v: %v", serviceId, command)

	runResults, err := client.Run(serviceId, nil, command, 5*time.Second)
	if err != nil {
		return err
	}

	for _, runResult := range runResults {
		unitId := juju.ParseUnit(runResult.UnitId)

		code := runResult.Code
		stdout := string(runResult.Stdout)
		stderr := string(runResult.Stderr)

		log.Debug("Result: %v %v %v %v", runResult.UnitId, code, stdout, stderr)

		healthy := true
		if !strings.Contains(stdout, "start/running") {
			log.Info("Service %v not running on %v", serviceId, runResult.UnitId)
			healthy = false

			if repair {
				command := "service " + self.ServiceName + " start"
				log.Info("Running command on %v: %v", serviceId, command)

				_, err := client.Run(serviceId, []string{unitId}, command, 5*time.Second)
				if err != nil {
					return err
				}

			}
		}

		dest.Units[unitId] = healthy
	}

	return nil
}
Exemple #2
0
// Retrieves a specific metric-dataset for the instance
func (self *Instance) GetMetricValues(key string) (*model.MetricDataset, error) {
	state, err := self.getState0()
	if err != nil {
		return nil, err
	}

	primaryServiceId := self.primaryServiceId

	jujuUnitNames := []string{}

	units := state.Units[primaryServiceId]
	for jujuUnitName, _ := range units {
		unitId := juju.ParseUnit(jujuUnitName)
		metricUnit := self.jujuPrefix + "metrics" + "/" + unitId

		jujuUnitNames = append(jujuUnitNames, metricUnit)
	}

	log.Debug("Searching with names: %v", jujuUnitNames)

	return self.readMetrics(jujuUnitNames, key)
}