Skip to content

Commit

Permalink
Notify responseTime
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Sep 27, 2016
1 parent ff37f42 commit 55aaea3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion chatwork_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func (c *ChatworkNotifier) PostStatus(param *PostStatusParam) error {
}

title := fmt.Sprintf("%s is %s", param.CheckUrl, statusText)
body := fmt.Sprintf("statusCode: %d -> %d", param.BeforeStatusCode, param.CurrentStatusCode)
format := `statusCode: %d -> %d
responseTime: %f sec`
body := fmt.Sprintf(format, param.BeforeStatusCode, param.CurrentStatusCode, param.ResponseTime)

if param.HttpError != nil {
body += fmt.Sprintf("\nhttpError: %v", param.HttpError)
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func perform(name string, values map[string]string) {

start := time.Now()
currentStatusCode, httpError := GetStatusCode(checkUrl)
end := time.Now();
end := time.Now()
responseTime := (end.Sub(start)).Seconds()

fmt.Printf("time:%v\tcheck_url:%s\tstatus:%d\tresponse_time:%f\terror:%v\n", time.Now(), checkUrl, currentStatusCode, responseTime, httpError)
Expand All @@ -93,6 +93,7 @@ func perform(name string, values map[string]string) {
BeforeStatusCode: beforeStatusCode,
CurrentStatusCode: currentStatusCode,
HttpError: httpError,
ResponseTime: responseTime,
}
notifier.PostStatus(&param)
}
Expand Down
1 change: 1 addition & 0 deletions notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type PostStatusParam struct {
CheckUrl string
BeforeStatusCode, CurrentStatusCode int
HttpError error
ResponseTime float64
}

type Notifier interface {
Expand Down
5 changes: 3 additions & 2 deletions slack_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func (s *SlackNotifier) PostStatus(param *PostStatusParam) error {
}

format := `%s is %s
statusCode: %d -> %d`
message := fmt.Sprintf(format, param.CheckUrl, statusText, param.BeforeStatusCode, param.CurrentStatusCode)
statusCode: %d -> %d
responseTime: %f sec`
message := fmt.Sprintf(format, param.CheckUrl, statusText, param.BeforeStatusCode, param.CurrentStatusCode, param.ResponseTime)

if param.HttpError != nil {
message += fmt.Sprintf("\nhttpError: %v", param.HttpError)
Expand Down

0 comments on commit 55aaea3

Please sign in to comment.