// Gather gathers system utilization data. func Gather(config Config, lg logger.Logger) *Data { uDat := Data{ MetadataVersion: metadataVersion, Vendors: &vendors{}, LogicalProcessors: runtime.NumCPU(), } if config.DetectDocker { id, err := sysinfo.DockerID() if err != nil && err != sysinfo.ErrDockerUnsupported && err != sysinfo.ErrDockerNotFound { lg.Warn("error gathering Docker information", map[string]interface{}{ "error": err.Error(), }) } else if id != "" { uDat.Vendors.Docker = &vendor{ID: id} } } if config.DetectAWS { aws, err := getAWS() if nil == err { uDat.Vendors.AWS = aws } else if isAWSValidationError(err) { lg.Warn("AWS validation error", map[string]interface{}{ "error": err.Error(), }) } } if uDat.Vendors.AWS == nil && uDat.Vendors.Docker == nil { uDat.Vendors = nil } host, err := sysinfo.Hostname() if nil == err { uDat.Hostname = host } else { lg.Warn("error getting hostname", map[string]interface{}{ "error": err.Error(), }) } bts, err := sysinfo.PhysicalMemoryBytes() if nil == err { mib := sysinfo.BytesToMebibytes(bts) uDat.RAMMib = &mib } else { lg.Warn("error getting memory", map[string]interface{}{ "error": err.Error(), }) } uDat.Config = overrideFromConfig(config) return &uDat }
// GetSample gathers a new Sample. func GetSample(now time.Time, lg logger.Logger) *Sample { s := Sample{ when: now, numGoroutine: runtime.NumGoroutine(), numCPU: runtime.NumCPU(), } if usage, err := sysinfo.GetUsage(); err == nil { s.usage = usage } else { lg.Warn("unable to usage", map[string]interface{}{ "error": err.Error(), }) } runtime.ReadMemStats(&s.memStats) return &s }