Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Storj/dataserv into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
F483 committed Aug 20, 2015
2 parents 1576922 + 884205f commit 92f863e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
33 changes: 30 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,44 @@ Fail Examples:
Status Code: 404
Text: Ping Failed: Farmer not found.

Online Status
*************
Online Status - Readable
************************

This API call was build to be human readable rather than machine readable. We get a simple
list of the all the farmers, their addresses, their advertised height. All of this is ordered by height.
We only display farmers that have done a ping in the last `online_time` minutes, which by default
is 15 minutes. Last seen is the amount of seconds since we have last seen an API call from the farmer.
is 15 minutes.

::

GET /api/online

Success Example:

::

GET /api/online
RESPONSE:
Status Code: 200
Text:
18RZNu2nxTdeNyuDCwAMq8aBpgC3FFERPp | Last Seen: 3 second(s) | Height: 7634
137x69jwmcyy4mYCBtQUVoxa21p9Fxyss5 | Last Seen: 7 second(s) | Height: 6234
14wLMb2A9APqrdXJhTQArYLyivmEAf7Y1r | Last Seen: 10 second(s) | Height: 431
1CgLoZT1ZuSHPBp3H4rLTXJvEUDV3kK7QK | Last Seen: 13 second(s) | Height: 245
1QACy1Tx5JFzGDyPd8J3oU8SrjhkZkru4H | Last Seen: 14 second(s) | Height: 88
1NeV1z5BMmFpCXgotwVeZjuN5k124W76MA | Last Seen: 14 second(s) | Height: 10

Online Status - JSON
********************

This API call was build to be human readable rather than machine readable. We get a simple
list of the all the farmers, their addresses, their advertised height. All of this is ordered by height.
We only display farmers that have done a ping in the last `online_time` minutes, which by default
is 15 minutes. Last seen is the amount of seconds since we have last seen an API call from the farmer.

::

GET /api/online/json

Success Example:

Expand Down
15 changes: 15 additions & 0 deletions dataserv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ def ping(btc_addr):
def online():
# this could be formatted a bit better, but we just want to publicly display
# that status of the farmers connected to the node
output = ""
current_time = datetime.datetime.utcnow()
text = "{0} | Last Seen: {1} | Height: {2}<br/>"

for farmer in online_farmers():
last_seen = secs_to_mins((current_time - farmer.last_seen).seconds)
output += text.format(farmer.btc_addr, last_seen, farmer.height)

return output


@app.route('/api/online/json', methods=["GET"])
def online_json():
# this could be formatted a bit better, but we just want to publicly display
# that status of the farmers connected to the node

payload = {
"farmers": [json.loads(farmer.to_json()) for farmer in online_farmers()]
Expand Down

0 comments on commit 92f863e

Please sign in to comment.