Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statsdaemon: add health monitoring #98

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ Usage of ./statsdaemon:
-receive-counter="": Metric name for total metrics received per interval
-tcpaddr="": TCP service address, if set
-version=false: print version string
-heartbeat-file="": heartbeat file to update after a successful write to graphite
```
24 changes: 24 additions & 0 deletions statsdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var (
percentThreshold = Percentiles{}
prefix = flag.String("prefix", "", "Prefix for all stats")
postfix = flag.String("postfix", "", "Postfix for all stats")
heartbeatFilePath = flag.String("heartbeat-file", "", "heartbeat file to update after a successful write to graphite.")
)

func init() {
Expand Down Expand Up @@ -245,6 +246,9 @@ func submit(deadline time.Time) error {
}

log.Printf("sent %d stats to %s", num, *graphiteAddress)
if *heartbeatFilePath != "" {
heartbeat()
}

return nil
}
Expand Down Expand Up @@ -572,6 +576,26 @@ func tcpListener() {
}
}

func heartbeat() {
_, err := os.Stat(*heartbeatFilePath)
if os.IsNotExist(err) {
jehiah marked this conversation as resolved.
Show resolved Hide resolved
file, err := os.Create(*heartbeatFilePath)
if err != nil {
log.Fatalf("ERROR: Creating heartbeat file - %s", err)
}
defer file.Close()
} else {
currentTime := time.Now()
err = os.Chtimes(*heartbeatFilePath, currentTime, currentTime)
if err != nil {
log.Fatalf("ERROR: Touching %s", err)
}
}
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}

func main() {
flag.Parse()

Expand Down