Example #1
0
func newCoreosSources(options map[string][]string) ([]api.Source, error) {
	fleetEndpoints := defaultFleetEndpoints
	if len(options["fleetEndpoint"]) > 0 {
		fleetEndpoints = options["fleetEndpoint"]
	}

	nodesApi, err := nodes.NewCoreOSNodes(fleetEndpoints)
	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
}
Example #2
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
}
Example #3
0
func newCoreOSCadvisorSource(pollDuration time.Duration) (Source, error) {
	if *argCadvisorPort <= 0 {
		return nil, fmt.Errorf("invalid cadvisor port - %d", *argCadvisorPort)
	}
	nodesApi, err := nodes.NewCoreOSNodes()
	if err != nil {
		return nil, err
	}
	return &cadvisorSource{
		pollDuration: pollDuration,
		cadvisorApi:  datasource.NewCadvisor(),
		nodesApi:     nodesApi,
		cadvisorPort: strconv.Itoa(*argCadvisorPort),
		lastQuery:    time.Now(),
	}, nil
}