Skip to content

Commit

Permalink
Display number of failed http requests to upstreams
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy007 committed Jan 5, 2016
1 parent 47e4f92 commit 1f86191
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions proxy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func convertUpstream(u *rpc.RPCClient) map[string]interface{} {
"accepts": atomic.LoadUint64(&u.Accepts),
"rejects": atomic.LoadUint64(&u.Rejects),
"lastSubmissionAt": atomic.LoadInt64(&u.LastSubmissionAt),
"failsCount": atomic.LoadUint64(&u.FailsCount),
}
return upstream
}
Expand Down
5 changes: 5 additions & 0 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"sync"
"sync/atomic"
"time"
)

Expand All @@ -23,6 +24,7 @@ type RPCClient struct {
Rejects uint64
LastSubmissionAt int64
client *http.Client
FailsCount uint64
}

type GetBlockReply struct {
Expand Down Expand Up @@ -160,6 +162,9 @@ func (r *RPCClient) Sick() bool {

func (r *RPCClient) markSick() {
r.Lock()
if !r.sick {
atomic.AddUint64(&r.FailsCount, 1)
}
r.sickRate++
r.successRate = 0
if r.sickRate >= 5 {
Expand Down
2 changes: 2 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ <h4>Upstream</h4>
<th>Url</th>
<th>Accepted</th>
<th>Rejected</th>
<th>Fails</th>
</tr>
{{#each upstreams}}
{{#if sick}}
Expand All @@ -93,6 +94,7 @@ <h4>Upstream</h4>
<td>{{url}}</td>
<td>{{formatNumber accepts}}</td>
<td><strong>{{formatNumber rejects}}</strong></td>
<td>{{failsCount}}</td>
</tr>
{{/each}}
</table>
Expand Down

0 comments on commit 1f86191

Please sign in to comment.