diff --git a/agent/main.go b/agent/main.go index a6d27715..1534581d 100644 --- a/agent/main.go +++ b/agent/main.go @@ -5,9 +5,6 @@ package main import ( "flag" _ "net/http/pprof" - - - ) func main() { @@ -24,13 +21,10 @@ func main() { if err := config.NewLoggerLevel("info", ""); err != nil { panic(err) } - + exit := make(chan struct{}) - + // Invoke the Agent runAgent(exit) - - } - diff --git a/agent/main_common.go b/agent/main_common.go index 611637bb..51f9085b 100644 --- a/agent/main_common.go +++ b/agent/main_common.go @@ -18,6 +18,7 @@ import ( "github.com/DataDog/datadog-process-agent/statsd" "github.com/DataDog/datadog-process-agent/util" ) + var opts struct { configPath string ddConfigPath string @@ -59,16 +60,14 @@ func versionString() string { return buf.String() } + const agentDisabledMessage = `process-agent not enabled. Set env var DD_PROCESS_AGENT_ENABLED=true or add process_agent_enabled: true to your datadog.conf file. Exiting.` - - -func runAgent(exit chan bool){ - +func runAgent(exit chan bool) { if opts.version { fmt.Println(versionString()) @@ -187,7 +186,6 @@ func runAgent(exit chan bool){ } } - func debugCheckResults(cfg *config.AgentConfig, check string) error { sysInfo, err := checks.CollectSystemInfo(cfg) if err != nil { @@ -230,4 +228,4 @@ func printResults(cfg *config.AgentConfig, ch checks.Check) error { fmt.Println(string(b)) } return nil -} \ No newline at end of file +} diff --git a/agent/main_nodocker.go b/agent/main_nodocker.go index e65f8c89..696f6c7c 100644 --- a/agent/main_nodocker.go +++ b/agent/main_nodocker.go @@ -3,15 +3,15 @@ package main import ( + log "github.com/cihub/seelog" "os" "os/signal" "syscall" - log "github.com/cihub/seelog" - ) func initMetadataProviders() { } + // Handles signals - tells us whether we should exit. func handleSignals(exit chan bool) { sigIn := make(chan os.Signal, 100) diff --git a/agent/main_windows.go b/agent/main_windows.go index 93f46ff0..86519334 100644 --- a/agent/main_windows.go +++ b/agent/main_windows.go @@ -5,17 +5,17 @@ package main import ( "flag" "fmt" -// "log" + // "log" _ "net/http/pprof" "os" "path/filepath" "time" + log "github.com/cihub/seelog" "golang.org/x/sys/windows/svc" "golang.org/x/sys/windows/svc/debug" "golang.org/x/sys/windows/svc/eventlog" "golang.org/x/sys/windows/svc/mgr" - log "github.com/cihub/seelog" ) var elog debug.Log @@ -38,7 +38,7 @@ var winopts struct { func init() { fmt.Printf("main_windows.init()") - + } type myservice struct{} @@ -75,7 +75,7 @@ func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes c }() elog.Info(0x40000003, ServiceName) runAgent(exit) - + changes <- svc.Status{State: svc.Stopped} return } @@ -114,6 +114,7 @@ func EnableLoggingToFile() { logger, _ := log.LoggerFromConfigAsBytes([]byte(seeConfig)) log.ReplaceLogger(logger) } + // main is the main application entry point func main() { flag.StringVar(&opts.configPath, "config", defaultConfigPath, "Path to datadog.yaml config") @@ -127,7 +128,7 @@ func main() { flag.BoolVar(&winopts.uninstallService, "uninstall-service", false, "Remove the trace agent from the Service Control Manager") flag.BoolVar(&winopts.startService, "start-service", false, "Starts the trace agent service") flag.BoolVar(&winopts.stopService, "stop-service", false, "Stops the trace agent service") - + flag.Parse() EnableLoggingToFile() isIntSess, err := svc.IsAnInteractiveSession() diff --git a/checks/container_nodocker.go b/checks/container_nodocker.go index 50bbd5ce..7f7e2884 100644 --- a/checks/container_nodocker.go +++ b/checks/container_nodocker.go @@ -5,8 +5,8 @@ package checks import ( "time" - "github.com/DataDog/datadog-process-agent/config" "github.com/DataDog/datadog-agent/pkg/util/docker" + "github.com/DataDog/datadog-process-agent/config" "github.com/DataDog/datadog-process-agent/model" ) @@ -37,7 +37,7 @@ func (c *ContainerCheck) RealTime() bool { return false } // Run runs the ContainerCheck to collect a list of running containers and the // stats for each container. func (c *ContainerCheck) Run(cfg *config.AgentConfig, groupID int32) ([]model.MessageBody, error) { - + return nil, nil } @@ -59,9 +59,7 @@ func fmtContainers( i := 0 for _, _ = range containers { - chunk = append(chunk, &model.Container{ - - }) + chunk = append(chunk, &model.Container{}) if len(chunk) == perChunk { chunked[i] = chunk @@ -73,4 +71,4 @@ func fmtContainers( chunked[i] = chunk } return chunked -} \ No newline at end of file +} diff --git a/checks/container_rt_nodocker.go b/checks/container_rt_nodocker.go index fd5def16..ef982c0b 100644 --- a/checks/container_rt_nodocker.go +++ b/checks/container_rt_nodocker.go @@ -56,8 +56,7 @@ func fmtContainerStats( chunk := make([]*model.ContainerStat, 0, perChunk) i := 0 for _, _ = range containers { - chunk = append(chunk, &model.ContainerStat{ - }) + chunk = append(chunk, &model.ContainerStat{}) if len(chunk) == perChunk { chunked[i] = chunk chunk = make([]*model.ContainerStat, 0, perChunk) diff --git a/checks/process.go b/checks/process.go index ebd5d7b2..2ef6e003 100644 --- a/checks/process.go +++ b/checks/process.go @@ -207,7 +207,6 @@ func formatIO(fp *process.FilledProcess, lastIO *process.IOCountersStat, before } } - func formatMemory(fp *process.FilledProcess) *model.MemoryStat { ms := &model.MemoryStat{ Rss: fp.MemInfo.RSS, @@ -225,7 +224,6 @@ func formatMemory(fp *process.FilledProcess) *model.MemoryStat { return ms } - // skipProcess will skip a given process if it's blacklisted or hasn't existed // for multiple collections. func skipProcess( diff --git a/checks/process_nix.go b/checks/process_nix.go index 2f0a166c..dfadded3 100644 --- a/checks/process_nix.go +++ b/checks/process_nix.go @@ -14,7 +14,6 @@ import ( "github.com/DataDog/datadog-process-agent/config" "github.com/DataDog/datadog-process-agent/model" - ) func formatUser(fp *process.FilledProcess) *model.ProcessUser { @@ -71,4 +70,3 @@ func calculatePct(deltaProc, deltaTime, numCPU float64) float32 { // In order to emulate top we multiply utilization by # of CPUs so a busy loop would be 100%. return float32(overalPct * numCPU) } - diff --git a/checks/process_windows.go b/checks/process_windows.go index 1f988a95..267d5f0e 100644 --- a/checks/process_windows.go +++ b/checks/process_windows.go @@ -5,10 +5,9 @@ package checks import ( "runtime" + "github.com/DataDog/datadog-process-agent/model" "github.com/DataDog/gopsutil/cpu" "github.com/DataDog/gopsutil/process" - "github.com/DataDog/datadog-process-agent/model" - ) func formatUser(fp *process.FilledProcess) *model.ProcessUser { @@ -25,9 +24,9 @@ func formatCPU(fp *process.FilledProcess, t2, t1, syst2, syst1 cpu.TimesStat) *m // is in nanoseconds. return &model.CPUStat{ LastCpu: t2.CPU, - TotalPct: calculatePct(((t2.User-t1.User)+(t2.System-t1.System)) * 100, deltaSys, numCPU), - UserPct: calculatePct((t2.User-t1.User) * 100, deltaSys, numCPU), - SystemPct: calculatePct((t2.System-t1.System) * 100, deltaSys, numCPU), + TotalPct: calculatePct(((t2.User-t1.User)+(t2.System-t1.System))*100, deltaSys, numCPU), + UserPct: calculatePct((t2.User-t1.User)*100, deltaSys, numCPU), + SystemPct: calculatePct((t2.System-t1.System)*100, deltaSys, numCPU), NumThreads: fp.NumThreads, Cpus: []*model.SingleCPUStat{}, Nice: fp.Nice, @@ -49,9 +48,8 @@ func calculatePct(deltaProc, deltaTime, numCPU float64) float32 { overalPct = 100 } - // In order to emulate task mgr, we divide by number of CPUs. + // In order to emulate task mgr, we divide by number of CPUs. // Task mgr displays percentage of available CPU (so a busy loop process // on a 2 core CPU is 50%) return float32(overalPct / numCPU) } - diff --git a/config/config.go b/config/config.go index 0f4e98d9..34556bb5 100644 --- a/config/config.go +++ b/config/config.go @@ -267,8 +267,8 @@ func NewAgentConfig(agentIni *File, agentYaml *YamlAgentConfig) (*AgentConfig, e // (Re)configure the logging from our configuration //if err := NewLoggerLevel(cfg.LogLevel, cfg.LogFile); err != nil { -// return nil, err -// } + // return nil, err + // } cfg.HostName = "" if ecsutil.IsFargateInstance() {