Skip to content

Commit

Permalink
Create Error File On Telegraf Failure (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon authored Mar 4, 2024
1 parent 2ad5e3a commit e241634
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ var fServiceName = flag.String("service-name", "telegraf", "service name (window
var fServiceDisplayName = flag.String("service-display-name", "Telegraf Data Collector Service", "service display name (windows only)")
var fRunAsConsole = flag.Bool("console", false, "run as console application (windows only)")
var fSetEnv = flag.String("setenv", "", "set an env in the configuration file in the format of KEY=VALUE")
var fStartUpErrorFile = flag.String("startup-error-file", "", "file to touch if agent can't start")

var stop chan struct{}

Expand Down Expand Up @@ -175,6 +176,14 @@ func reloadLoop(

err := runAgent(ctx, inputFilters, outputFilters)
if err != nil && err != context.Canceled {
if *fStartUpErrorFile != "" {
f, err := os.OpenFile(*fStartUpErrorFile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Printf("E! Unable to create errorFile: %s", err)
} else {
_ = f.Close()
}
}
log.Fatalf("E! [telegraf] Error running agent: %v", err)
}
}
Expand Down

0 comments on commit e241634

Please sign in to comment.