mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
fix the flask_metrics file to use django settings and update docker-compose
This commit is contained in:
parent
c6ce91360d
commit
3173541735
2 changed files with 25 additions and 27 deletions
|
@ -14,10 +14,10 @@ services:
|
||||||
depends_on:
|
depends_on:
|
||||||
- node-exporter
|
- node-exporter
|
||||||
- haproxy
|
- haproxy
|
||||||
- flask_metrics
|
- flask_metrics_mongo
|
||||||
external_links:
|
external_links:
|
||||||
- haproxy
|
- haproxy
|
||||||
- flask_metrics
|
- flask_metrics_mongo
|
||||||
|
|
||||||
node-exporter:
|
node-exporter:
|
||||||
container_name: node-exporter
|
container_name: node-exporter
|
||||||
|
@ -40,20 +40,17 @@ services:
|
||||||
- ./docker/grafana/dashboards/:/etc/grafana/provisioning/dashboards/
|
- ./docker/grafana/dashboards/:/etc/grafana/provisioning/dashboards/
|
||||||
external_links:
|
external_links:
|
||||||
- prometheus
|
- prometheus
|
||||||
flask_metrics:
|
flask_metrics_mongo:
|
||||||
container_name: flask_metrics
|
container_name: flask_metrics_mongo
|
||||||
build:
|
image: newsblur/flask_monitor:latest
|
||||||
context: .
|
command: bash -c "python /srv/newsblur/flask_metrics/flask_metrics_mongo.py"
|
||||||
dockerfile: docker/flask_metrics/Dockerfile
|
environment:
|
||||||
command: bash -c "python /srv/newsblur/flask_metrics/flask_metrics.py"
|
- DOCKERBUILD=True
|
||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- 5569:5569
|
||||||
depends_on:
|
depends_on:
|
||||||
- db_mongo
|
- db_mongo
|
||||||
- newsblur_web
|
- newsblur_web
|
||||||
- nginx
|
- nginx
|
||||||
environment:
|
|
||||||
- MONGODB_PORT=29019
|
|
||||||
- MONGODB_SERVER=db_mongo
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${PWD}:/srv/newsblur
|
- ${PWD}:/srv/newsblur
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import os
|
|
||||||
from flask import Flask, render_template, Response
|
from flask import Flask, render_template, Response
|
||||||
import pymongo
|
import pymongo
|
||||||
|
from newsblur_web import settings
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
if settings.MONGO_DB['host'] == 'db_mongo:29019':
|
||||||
MONGO_HOST = os.environ.get('MONGODB_SERVER')
|
host = settings.MONGO_DB['host'].split(":")[0]
|
||||||
MONGO_PORT = int(os.environ.get('MONGODB_PORT'))
|
port = int(settings.MONGO_DB['host'].split(":")[1])
|
||||||
connection = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)
|
connection = pymongo.MongoClient(host, port)
|
||||||
|
else:
|
||||||
@app.route("/mongo/objects/")
|
connection = pymongo.MongoClient(f"mongodb://{settings.MONGO_DB['username']}:{settings.MONGO_DB['password']}@{settings.SERVER_NAME}/?authSource=admin")
|
||||||
|
MONGO_HOST = settings.SERVER_NAME
|
||||||
|
@app.route("/objects/")
|
||||||
def objects():
|
def objects():
|
||||||
stats = connection.newsblur.command("dbstats")
|
stats = connection.newsblur.command("dbstats")
|
||||||
data = dict(objects=stats['objects'])
|
data = dict(objects=stats['objects'])
|
||||||
|
@ -25,11 +27,10 @@ def objects():
|
||||||
return Response(html_body, content_type="text/plain")
|
return Response(html_body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/mongo/repl-set-lag/")
|
@app.route("/repl-set-lag/")
|
||||||
def repl_set_lag():
|
def repl_set_lag():
|
||||||
|
|
||||||
def _get_oplog_length():
|
def _get_oplog_length():
|
||||||
oplog = connection.local.oplog.rs
|
oplog = connection.rs.command('printReplicationInfo')
|
||||||
last_op = oplog.find({}, {'ts': 1}).sort([('$natural', -1)]).limit(1)[0]['ts'].time
|
last_op = oplog.find({}, {'ts': 1}).sort([('$natural', -1)]).limit(1)[0]['ts'].time
|
||||||
first_op = oplog.find({}, {'ts': 1}).sort([('$natural', 1)]).limit(1)[0]['ts'].time
|
first_op = oplog.find({}, {'ts': 1}).sort([('$natural', 1)]).limit(1)[0]['ts'].time
|
||||||
oplog_length = last_op - first_op
|
oplog_length = last_op - first_op
|
||||||
|
@ -76,7 +77,7 @@ def repl_set_lag():
|
||||||
return Response(html_body, content_type="text/plain")
|
return Response(html_body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/mongo/size/")
|
@app.route("/size/")
|
||||||
def size():
|
def size():
|
||||||
stats = connection.newsblur.command("dbstats")
|
stats = connection.newsblur.command("dbstats")
|
||||||
data = dict(size=stats['fsUsedSize'])
|
data = dict(size=stats['fsUsedSize'])
|
||||||
|
@ -93,7 +94,7 @@ def size():
|
||||||
return Response(html_body, content_type="text/plain")
|
return Response(html_body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/mongo/ops/")
|
@app.route("/ops/")
|
||||||
def ops():
|
def ops():
|
||||||
status = connection.admin.command('serverStatus')
|
status = connection.admin.command('serverStatus')
|
||||||
data = dict(
|
data = dict(
|
||||||
|
@ -114,7 +115,7 @@ def ops():
|
||||||
return Response(html_body, content_type="text/plain")
|
return Response(html_body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/mongo/page-faults/")
|
@app.route("/page-faults/")
|
||||||
def page_faults():
|
def page_faults():
|
||||||
status = connection.admin.command('serverStatus')
|
status = connection.admin.command('serverStatus')
|
||||||
try:
|
try:
|
||||||
|
@ -135,7 +136,7 @@ def page_faults():
|
||||||
return Response(html_body, content_type="text/plain")
|
return Response(html_body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/mongo/page-queues/")
|
@app.route("/page-queues/")
|
||||||
def page_queues():
|
def page_queues():
|
||||||
status = connection.admin.command('serverStatus')
|
status = connection.admin.command('serverStatus')
|
||||||
data = dict(
|
data = dict(
|
||||||
|
@ -157,4 +158,4 @@ def page_queues():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(" ---> Starting NewsBlur Flask Metrics server...")
|
print(" ---> Starting NewsBlur Flask Metrics server...")
|
||||||
app.run(host="0.0.0.0", port=5000)
|
app.run(host="0.0.0.0", port=5569)
|
Loading…
Add table
Reference in a new issue