func (f *CPUFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { if err := stats.Init(); err != nil { return false, fmt.Errorf("Unable to obtain CPU information: %v", err) } modelName := stats.CPUModelName() if modelName != "" { node.Attributes["cpu.modelname"] = modelName } mhz := stats.CPUMHzPerCore() node.Attributes["cpu.frequency"] = fmt.Sprintf("%.0f", mhz) f.logger.Printf("[DEBUG] fingerprint.cpu: frequency: %.0f MHz", mhz) numCores := stats.CPUNumCores() node.Attributes["cpu.numcores"] = fmt.Sprintf("%d", numCores) f.logger.Printf("[DEBUG] fingerprint.cpu: core count: %d", numCores) tt := stats.TotalTicksAvailable() node.Attributes["cpu.totalcompute"] = fmt.Sprintf("%.0f", tt) if node.Resources == nil { node.Resources = &structs.Resources{} } node.Resources.CPU = int(tt) return true, nil }
// dockerClients creates two *docker.Client, one for long running operations and // the other for shorter operations. In test / dev mode we can use ENV vars to // connect to the docker daemon. In production mode we will read docker.endpoint // from the config file. func (d *DockerDriver) dockerClients() (*docker.Client, *docker.Client, error) { if client != nil && waitClient != nil { return client, waitClient, nil } var err error var merr multierror.Error createClients.Do(func() { if err = shelpers.Init(); err != nil { d.logger.Printf("[FATAL] driver.docker: unable to initialize stats: %v", err) return } // Default to using whatever is configured in docker.endpoint. If this is // not specified we'll fall back on NewClientFromEnv which reads config from // the DOCKER_* environment variables DOCKER_HOST, DOCKER_TLS_VERIFY, and // DOCKER_CERT_PATH. This allows us to lock down the config in production // but also accept the standard ENV configs for dev and test. dockerEndpoint := d.config.Read("docker.endpoint") if dockerEndpoint != "" { cert := d.config.Read("docker.tls.cert") key := d.config.Read("docker.tls.key") ca := d.config.Read("docker.tls.ca") if cert+key+ca != "" { d.logger.Printf("[DEBUG] driver.docker: using TLS client connection to %s", dockerEndpoint) client, err = docker.NewTLSClient(dockerEndpoint, cert, key, ca) } else { d.logger.Printf("[DEBUG] driver.docker: using standard client connection to %s", dockerEndpoint) client, err = docker.NewClient(dockerEndpoint) } client.HTTPClient.Timeout = dockerTimeout return } d.logger.Println("[DEBUG] driver.docker: using client connection initialized from environment") client, err = docker.NewClientFromEnv() if err != nil { merr.Errors = append(merr.Errors, err) } client.HTTPClient.Timeout = dockerTimeout waitClient, err = docker.NewClientFromEnv() if err != nil { merr.Errors = append(merr.Errors, err) } }) return client, waitClient, merr.ErrorOrNil() }
// NewExecutor returns an Executor func NewExecutor(logger *log.Logger) Executor { if err := shelpers.Init(); err != nil { logger.Printf("[FATAL] executor: unable to initialize stats: %v", err) return nil } exec := &UniversalExecutor{ logger: logger, processExited: make(chan interface{}), totalCpuStats: stats.NewCpuStats(), userCpuStats: stats.NewCpuStats(), systemCpuStats: stats.NewCpuStats(), pids: make(map[int]*nomadPid), } return exec }