Project

General

Profile

« Previous | Next » 

Revision 61719

implemented api entry to return metrics in prometheus format

View differences:

main.py
1 1
import os
2 2
from fastapi import FastAPI, Form
3
from fastapi.responses import PlainTextResponse
3 4
import logging
4 5
from starlette.staticfiles import StaticFiles
5 6
from starlette.responses import FileResponse
......
60 61
def favicon():
61 62
    return FileResponse(os.path.join(os.path.join(_CURDIR, 'static' ),'favicon.ico'))
62 63

  
64

  
65

  
66

  
67
@app.get("/api/metrics", response_class=PlainTextResponse)
68
def main_page_stats():
69
    connector= DLIESConnector()
70
    data =dict(result=connector.get_main_page_stats())
71
    print(data)
72
    output ="""# TYPE scholexplorer_indexed_datasets gauge\nscholexplorer_indexed_datasets {}\n# TYPE scholexplorer_indexed_publications gauge\nscholexplorer_indexed_publications {}\n# TYPE scholexplorer_indexed_relations gauge\nscholexplorer_indexed_relations {}""".format(data['result']['dataset'], data['result']['publication'], data['result']['total'])
73
    return output
74

  
75

  
76

  
77

  
63 78
@app.get("/api/main_page_stats")
64 79
def main_page_stats():
65 80
    connector= DLIESConnector()

Also available in: Unified diff