diff --git a/src/design/index.org b/src/design/index.org index 97401f5..aa8fe94 100755 --- a/src/design/index.org +++ b/src/design/index.org @@ -37,7 +37,7 @@ :END: ** Post Data to Analytics Server :PROPERTIES: - :CUSTOM_ID: display_feedback_form + :CUSTOM_ID: analytics_server_post_data :END: - URL :: / @@ -51,9 +51,9 @@ ** Get Records count from Elasticsearch server :PROPERTIES: - :CUSTOM_ID: display_feedback_form + :CUSTOM_ID: get_elasticseacrch_server_count :END: - - URL :: /elkusage + - URL :: /api//elkusage - Method :: GET @@ -62,3 +62,19 @@ - Success Response + Code: 200 + + +** Get total usage count from Elasticsearch server and stats server + :PROPERTIES: + :CUSTOM_ID: total_usage-count + :END: + - URL :: /api/totalusage + + - Method :: GET + + - URL Params + None + + - Success Response + + Code: 200 + diff --git a/src/runtime/config/config.org b/src/runtime/config/config.org index 16ff091..b0445a2 100755 --- a/src/runtime/config/config.org +++ b/src/runtime/config/config.org @@ -34,12 +34,12 @@ elastic_index = "vlabs/usage" elastic_count = "vlabs/_count" #elastic_doc_type = "usage" -count_url = elastic_host + elastic_count -url = elastic_host + elastic_index +elk_count_url = elastic_host + elastic_count +elk_url = elastic_host + elastic_index headers = {"Content-type":"application/json", "Accept":"text/plain"} - +stats_server_url= "http://stats.vlabs.ac.in/analytics" #Request body for disabling string analyzer in elasticsearch request_body = {"index" : {"analysis": {"analyzer": {"default": {"type":"keyword"}}}}} diff --git a/src/runtime/rest/api.org b/src/runtime/rest/api.org index c1bc2bb..4a8769c 100755 --- a/src/runtime/rest/api.org +++ b/src/runtime/rest/api.org @@ -12,7 +12,35 @@ * Analytics REST -** Get Analytics Count + +** Get total Analytics Count + + Total Analytics = Usage(stats.vlabs.ac.in) + Usage(vlabs-analytics.vlabs.ac.in) + + +#+NAME: get_total_usage +#+BEGIN_SRC python +@api.route('/api/totalusage') +def get_total_usage(): + try: + res = requests.get(elk_count_url) + elk_response = json.loads(res.content) + + req = requests.get(stats_server_url) + stats_response = json.loads(req.content) + + total_analytics = {} + total_analytics = elk_response["count"] + stats_response["usage"] + return json.dumps(total_analytics) + + except: + return "Error in communication" + + + +#+END_SRC + + +** Get Elasticsearch Analytics Count + Route/API to fetch analytics from Elasticsearch Server. + API makes a get request to Elasticsearch and gets the total number of analytics record holded. @@ -30,7 +58,7 @@ @api.route('/api/elkusage') def get_elkusage(): try: - res = requests.get(count_url) + res = requests.get(elk_count_url) elk_response = ast.literal_eval(res.text) return json.dumps(elk_response) except: @@ -87,7 +115,7 @@ def fetch_analytics(analytics): data_dict["REGION"] = ip_dir["region_name"] json_data = json.dumps(data_dict) - res = requests.post(url, data=json_data, headers=headers) + res = requests.post(elk_url, data=json_data, headers=headers) return "".format(analytics) @@ -124,6 +152,7 @@ api = Blueprint('APIs', __name__) <> <> <> +<> #+END_SRC