Exemple #1
0
func newExternalSources(options map[string][]string) ([]api.Source, error) {
	hostsFile := defaultHostsFile
	if len(options["hostsFile"]) > 0 {
		hostsFile = options["hostsFile"][0]
	}
	standalone := defaultStandalone
	if len(options["standalone"]) > 0 {
		standaloneOption, err := strconv.ParseBool(options["standalone"][0])
		if err != nil {
			return nil, err
		}
		standalone = standaloneOption
	}

	nodesApi, err := nodes.NewExternalNodes(standalone, hostsFile)
	if err != nil {
		return nil, err
	}

	cadvisorPort := defaultCadvisorPort
	if len(options["cadvisorPort"]) > 0 {
		cadvisorPort, err = strconv.Atoi(options["cadvisorPort"][0])
		if err != nil {
			return nil, err
		}
	}

	return []api.Source{
		&cadvisorSource{
			cadvisorApi:  datasource.NewCadvisor(),
			nodesApi:     nodesApi,
			cadvisorPort: cadvisorPort,
		},
	}, nil
}
Exemple #2
0
func newExternalCadvisorSource(pollDuration time.Duration) (Source, error) {
	if *argCadvisorPort <= 0 {
		return nil, fmt.Errorf("invalid cadvisor port - %d", *argCadvisorPort)
	}
	nodesApi, err := nodes.NewExternalNodes()
	if err != nil {
		return nil, err
	}
	return &cadvisorSource{
		pollDuration: pollDuration,
		cadvisorApi:  datasource.NewCadvisor(),
		nodesApi:     nodesApi,
		cadvisorPort: strconv.Itoa(*argCadvisorPort),
		lastQuery:    time.Now(),
	}, nil
}