mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
Merge branch 'master' into devel
This commit is contained in:
commit
324356f9f4
4 changed files with 21 additions and 1 deletions
2
Makefile
2
Makefile
|
|
@ -23,7 +23,7 @@ deps:
|
||||||
info-file :
|
info-file :
|
||||||
echo PACKAGE_NAME=\"$(PROGRAM_NAME)\" "\n"\
|
echo PACKAGE_NAME=\"$(PROGRAM_NAME)\" "\n"\
|
||||||
PACKAGE_DESCRIPTION=\"HAproxy healthcheck program for EOSIO API.\" "\n"\
|
PACKAGE_DESCRIPTION=\"HAproxy healthcheck program for EOSIO API.\" "\n"\
|
||||||
PACKAGE_VERSION=\"0.3.4\" "\n"\
|
PACKAGE_VERSION=\"0.3.5\" "\n"\
|
||||||
PACKAGE_PREFIX=\"$(PREFIX:/%=%)\" "\n"\
|
PACKAGE_PREFIX=\"$(PREFIX:/%=%)\" "\n"\
|
||||||
PACKAGE_PROGRAM=\"build/$(PROGRAM_NAME)\" > scripts/info
|
PACKAGE_PROGRAM=\"build/$(PROGRAM_NAME)\" > scripts/info
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ func GetInfo(params ReqParams) (Info, error) {
|
||||||
resp := r.Response()
|
resp := r.Response()
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
// Set HTTPStatusCode
|
||||||
|
info.HTTPStatusCode = resp.StatusCode
|
||||||
|
|
||||||
// Parse json
|
// Parse json
|
||||||
err = json.Unmarshal(body, &info)
|
err = json.Unmarshal(body, &info)
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +74,9 @@ func GetHealth(params ReqParams) (Health, error) {
|
||||||
resp := r.Response()
|
resp := r.Response()
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
// Set HTTPStatusCode
|
||||||
|
health.HTTPStatusCode = resp.StatusCode
|
||||||
|
|
||||||
// Parse json
|
// Parse json
|
||||||
err = json.Unmarshal(body, &health)
|
err = json.Unmarshal(body, &health)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type Info struct {
|
||||||
ServerVersion string `json:"server_version"`
|
ServerVersion string `json:"server_version"`
|
||||||
HeadBlockNum int64 `json:"head_block_num"`
|
HeadBlockNum int64 `json:"head_block_num"`
|
||||||
HeadBlockTime time.Time `json:"head_block_time"`
|
HeadBlockTime time.Time `json:"head_block_time"`
|
||||||
|
HTTPStatusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service struct from /v2/health
|
// Service struct from /v2/health
|
||||||
|
|
@ -22,4 +23,5 @@ type Service struct {
|
||||||
type Health struct {
|
type Health struct {
|
||||||
VersionHash string `json:"version_hash"`
|
VersionHash string `json:"version_hash"`
|
||||||
Health []Service `json:"health"`
|
Health []Service `json:"health"`
|
||||||
|
HTTPStatusCode int
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ func check_api(p eosapi.ReqParams, block_time float64) (haproxy.HealthCheckStatu
|
||||||
return haproxy.HealthCheckFailed, msg
|
return haproxy.HealthCheckFailed, msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check HTTP Status Code
|
||||||
|
if info.HTTPStatusCode > 299 {
|
||||||
|
return haproxy.HealthCheckDown,
|
||||||
|
fmt.Sprintf("Taking offline because %v was received from backend", info.HTTPStatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
// Validate head block.
|
// Validate head block.
|
||||||
now := time.Now().In(time.UTC)
|
now := time.Now().In(time.UTC)
|
||||||
diff := now.Sub(info.HeadBlockTime).Seconds()
|
diff := now.Sub(info.HeadBlockTime).Seconds()
|
||||||
|
|
@ -48,6 +54,12 @@ func check_api_v2(p eosapi.ReqParams, offset int64) (haproxy.HealthCheckStatus,
|
||||||
return haproxy.HealthCheckFailed, msg
|
return haproxy.HealthCheckFailed, msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check HTTP Status Code
|
||||||
|
if health.HTTPStatusCode > 299 {
|
||||||
|
return haproxy.HealthCheckDown,
|
||||||
|
fmt.Sprintf("Taking offline because %v was received from backend", health.HTTPStatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch elasticsearch and nodeos block numbers from json.
|
// Fetch elasticsearch and nodeos block numbers from json.
|
||||||
var es_block int64 = 0
|
var es_block int64 = 0
|
||||||
var node_block int64 = 0
|
var node_block int64 = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue