mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-08-31 21:38:12 +02:00
rename EosioContract to AtomicAsset.
This commit is contained in:
parent
1b1f601678
commit
2b0b32b5ab
4 changed files with 41 additions and 41 deletions
80
internal/api/atomicasset.go
Normal file
80
internal/api/atomicasset.go
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/eosswedenorg-go/atomicasset"
|
||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||
)
|
||||
|
||||
type AtomicAsset struct {
|
||||
utils.Time
|
||||
client atomicasset.Client
|
||||
block_time float64
|
||||
}
|
||||
|
||||
func AtomicAssetFactory(args ApiArguments) ApiInterface {
|
||||
return NewAtomicAsset(args.Url, float64(args.NumBlocks/2))
|
||||
}
|
||||
|
||||
func NewAtomicAsset(url string, block_time float64) AtomicAsset {
|
||||
return AtomicAsset{
|
||||
client: atomicasset.Client{
|
||||
URL: url,
|
||||
},
|
||||
block_time: block_time,
|
||||
}
|
||||
}
|
||||
|
||||
func (e AtomicAsset) LogInfo() LogParams {
|
||||
return LogParams{
|
||||
"type", "atomicasset",
|
||||
"url", e.client.URL,
|
||||
"block_time", e.block_time,
|
||||
}
|
||||
}
|
||||
|
||||
func (e AtomicAsset) Call() (agentcheck.Response, string) {
|
||||
h, err := e.client.GetHealth()
|
||||
if err != nil {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Failed, "")
|
||||
return resp, err.Error()
|
||||
}
|
||||
|
||||
// Check HTTP Status Code
|
||||
if h.HTTPStatusCode > 299 {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
|
||||
msg := "Taking offline because %v was received from backend"
|
||||
return resp, fmt.Sprintf(msg, h.HTTPStatusCode)
|
||||
}
|
||||
|
||||
// Check postgres
|
||||
if h.Data.Postgres.Status != "OK" {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
|
||||
msg := "Taking offline because Postgres reported '%s'"
|
||||
return resp, fmt.Sprintf(msg, h.Data.Postgres.Status)
|
||||
}
|
||||
|
||||
// Check redis
|
||||
if h.Data.Redis.Status != "OK" {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
|
||||
msg := "Taking offline because Redis reported '%s'"
|
||||
return resp, fmt.Sprintf(msg, h.Data.Redis.Status)
|
||||
}
|
||||
|
||||
// Validate head block.
|
||||
diff := e.GetTime().Sub(h.Data.Chain.HeadTime.Time()).Seconds()
|
||||
|
||||
if diff > e.block_time {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
|
||||
msg := "Taking offline because head block is lagging %.0f seconds"
|
||||
return resp, fmt.Sprintf(msg, diff)
|
||||
} else if diff < -e.block_time {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
|
||||
msg := "Taking offline because head block is %.0f seconds into the future"
|
||||
return resp, fmt.Sprintf(msg, diff)
|
||||
}
|
||||
|
||||
return agentcheck.NewStatusResponse(agentcheck.Up), "OK"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue