__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #-*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import time
  16. from flask import request, g, session, abort, render_template
  17. from rrd import app
  18. from rrd.consts import GRAPH_TYPE_HOST
  19. @app.before_request
  20. def dashboard_before():
  21. if request.method == "GET":
  22. now = int(time.time())
  23. #是否显示顶部图表导航
  24. g.nav_header = request.args.get("nav_header") or "on"
  25. g.cols = request.args.get("cols") or "2"
  26. try:
  27. g.cols = int(g.cols)
  28. except:
  29. g.cols = 2
  30. if g.cols <= 0:
  31. g.cols = 2
  32. if g.cols >= 6:
  33. g.cols = 6
  34. g.legend = request.args.get("legend") or "off"
  35. g.graph_type = request.args.get("graph_type") or GRAPH_TYPE_HOST
  36. g.sum = request.args.get("sum") or "off" #是否求和
  37. g.sumonly = request.args.get("sumonly") or "off" #是否只显示求和
  38. g.cf = (request.args.get("cf") or "AVERAGE").upper() # MAX, MIN, AVGRAGE, LAST
  39. g.start = int(request.args.get("start") or -3600)
  40. if g.start < 0:
  41. g.start = now + g.start
  42. g.end = int(request.args.get("end") or 0)
  43. if g.end <= 0:
  44. g.end = now + g.end
  45. g.end = g.end - 60
  46. g.id = request.args.get("id") or ""
  47. g.limit = int(request.args.get("limit") or 0)
  48. g.page = int(request.args.get("page") or 0)