python中的grafana简单json插件通过flask连接到数据库

时间:2018-12-03 23:54:20

标签: python flask grafana simplejson grafana-api

任何人都可以通过python FLASK.am中的Grafana简单JSON插件来帮助我,而不理解“ / search”,/ query,“ targets”,“ from range”和“ from to”其非常混乱且非常少的文档。实际上,我在互联网上只找到一个代码。请帮助我如何声明我的/ search和/ query。请更正我的代码

connection = cx_Oracle.mkedsn('','',servicename='')

conn = cx_Oracle.connect(user='',password='',dsn=dsn_tns)
c.execute('''SELECT APPLE, BANANA, CARROT FROM VEGETABLES''')
for row in c:
print (row)
conn.close()
**output: {"apple":"fruit","banana":"fruit","carrot":"vegetable"}**

我想在grafana中以表格格式查看此json。请帮助我如何在grafana中编写/ search和/ query更少的资源和更少的文档    我下面针对上述数据库请求的grafana代码

 from flask import  FLASK
 import cx_Oracle, json
dbconnection = cx_Oracle.makedsn('','',servicename='')

app = Flask(__name__)

@app.route('/')
def healthtest():
return "Good" 

@app.route('/search', methods=['POST'])
req = req.get_json():
def searching():

 return searching
@app.route('/query',methods=['GET'])

if  target == "Food":
conn = cx_Oracle.connect(user='',password='',dsn=dsn_tns)
c.execute('''SELECT APPLE, BANANA, CARROT FROM VEGETABLES''')
for row in c:
print (row)
conn.close()
else :
    print "No DATA"

   app.run(host=0.0.0.0, port=0000, debug=True)

对于简单的JSON插件,我需要添加类似的目标,范围从到请帮助我如何在grafana表中填充JSON响应。我的查询名称是“食品”,并且我有两个列“水果”和“蔬菜” “。

0 个答案:

没有答案