mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
add querystring logic to mongo db health check to accommodate consul vs haproxy checking
This commit is contained in:
parent
0bbff92c73
commit
dd13af5bf1
5 changed files with 36 additions and 35 deletions
|
@ -8,7 +8,7 @@
|
||||||
"port": 27017,
|
"port": 27017,
|
||||||
"checks": [{
|
"checks": [{
|
||||||
"id": "mongo-ping",
|
"id": "mongo-ping",
|
||||||
"http": "http://{{ ansible_ssh_host }}:5579/db_check/mongo",
|
"http": "http://{{ ansible_ssh_host }}:5579/db_check/mongo?consul=1",
|
||||||
"interval": "15s",
|
"interval": "15s",
|
||||||
"failures_before_critical": 4
|
"failures_before_critical": 4
|
||||||
}]
|
}]
|
||||||
|
|
|
@ -124,7 +124,7 @@ backend postgres
|
||||||
option httpchk GET /db_check/postgres
|
option httpchk GET /db_check/postgres
|
||||||
server postgres-db01 db_pgsql:5000 check inter 2000ms
|
server postgres-db01 db_pgsql:5000 check inter 2000ms
|
||||||
backend mongo
|
backend mongo
|
||||||
option httpchk GET /db_check/mongo
|
option httpchk GET /db_check/mongo?haproxy=1
|
||||||
server mongo-db22 db_mongo:5000 check inter 2000ms
|
server mongo-db22 db_mongo:5000 check inter 2000ms
|
||||||
backend redis
|
backend redis
|
||||||
option httpchk GET /db_check/redis
|
option httpchk GET /db_check/redis
|
||||||
|
|
|
@ -146,7 +146,7 @@ backend postgres
|
||||||
server postgres-db02 db_pgsql:5000 check inter 2000ms
|
server postgres-db02 db_pgsql:5000 check inter 2000ms
|
||||||
|
|
||||||
backend mongo
|
backend mongo
|
||||||
option httpchk GET /db_check/mongo
|
option httpchk GET /db_check/mongo?haproxy=1
|
||||||
server mongo-db20d db20d:5000 check inter 2000ms
|
server mongo-db20d db20d:5000 check inter 2000ms
|
||||||
server mongo-db22 db22:5000 check inter 2000ms
|
server mongo-db22 db22:5000 check inter 2000ms
|
||||||
server mongo-db23a db23a:5000 check inter 2000ms
|
server mongo-db23a db23a:5000 check inter 2000ms
|
||||||
|
|
|
@ -167,7 +167,7 @@ backend postgres
|
||||||
server db-postgres db-postgres.node.nyc1.consul:5579 check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
|
server db-postgres db-postgres.node.nyc1.consul:5579 check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
|
||||||
|
|
||||||
backend mongo
|
backend mongo
|
||||||
option httpchk GET /db_check/mongo
|
option httpchk GET /db_check/mongo?haproxy=1
|
||||||
default-server check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
|
default-server check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
|
||||||
{% for host in groups.mongo %}
|
{% for host in groups.mongo %}
|
||||||
server {{host}} {{host}}.node.nyc1.consul:5579
|
server {{host}} {{host}}.node.nyc1.consul:5579
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask, abort
|
from flask import Flask, abort, request
|
||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import pymysql
|
import pymysql
|
||||||
|
@ -80,10 +80,11 @@ def db_check_mongo():
|
||||||
# The `mongo` hostname below is a reference to the newsblurnet docker network, where 172.18.0.0/16 is defined
|
# The `mongo` hostname below is a reference to the newsblurnet docker network, where 172.18.0.0/16 is defined
|
||||||
client = pymongo.MongoClient(f"mongodb://{settings.MONGO_DB['username']}:{settings.MONGO_DB['password']}@{settings.SERVER_NAME}/?authSource=admin")
|
client = pymongo.MongoClient(f"mongodb://{settings.MONGO_DB['username']}:{settings.MONGO_DB['password']}@{settings.SERVER_NAME}/?authSource=admin")
|
||||||
db = client.newsblur
|
db = client.newsblur
|
||||||
|
if request.args.get('consul') == '1':
|
||||||
return str(1)
|
return str(1)
|
||||||
except:
|
except:
|
||||||
abort(503)
|
abort(503)
|
||||||
|
if request.args.get('haproxy') == '1':
|
||||||
try:
|
try:
|
||||||
stories = db.stories.estimated_document_count()
|
stories = db.stories.estimated_document_count()
|
||||||
except (pymongo.errors.NotMasterError, pymongo.errors.ServerSelectionTimeoutError):
|
except (pymongo.errors.NotMasterError, pymongo.errors.ServerSelectionTimeoutError):
|
||||||
|
|
Loading…
Add table
Reference in a new issue