Skip to content

Commit

Permalink
add new api for total usage count
Browse files Browse the repository at this point in the history
  • Loading branch information
ashay-maheshwari committed Feb 12, 2017
1 parent e7906b3 commit e1bb32f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
22 changes: 19 additions & 3 deletions src/design/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:END:
** Post Data to Analytics Server
:PROPERTIES:
:CUSTOM_ID: display_feedback_form
:CUSTOM_ID: analytics_server_post_data
:END:
- URL :: /

Expand All @@ -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

Expand All @@ -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

6 changes: 3 additions & 3 deletions src/runtime/config/config.org
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}}}
Expand Down
35 changes: 32 additions & 3 deletions src/runtime/rest/api.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -124,6 +152,7 @@ api = Blueprint('APIs', __name__)
<<imports_for_sources>>
<<get_analytics>>
<<get_elkusage>>
<<get_total_usage>>
#+END_SRC


Expand Down

0 comments on commit e1bb32f

Please sign in to comment.