Skip to content

Commit

Permalink
Merge pull request #98 from OscarLuu/statsdaemon_health_monitoring
Browse files Browse the repository at this point in the history
statsdaemon: add health monitoring
  • Loading branch information
jehiah authored Mar 9, 2020
2 parents 246d751 + 88e29df commit 0d533dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,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) {
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

0 comments on commit 0d533dc

Please sign in to comment.