Obtaining Usage Statistics via REST API
---------------------------------------

Thi section describes how to obtain usage statistics via REST API for billing or other purposes.

.. note:: Delete statistics objects after collecting the required data.

Listing Statistics Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~

You can list all available statistics objects with the ``ostor-usage`` service and no parameters. The output only contains objects that have not been deleted. For example:

::

   # s3_curl GET "http://s3.example.com/?ostor-usage"
   {
       "nr_items": 7,
       "truncated": false,
       "items": [
           "s3-usage-8000000000000065-2017-02-01T16:31:54.000Z-1800",
           "s3-usage-8000000000000067-2017-02-01T16:30:51.000Z-1800",
           "s3-usage-8000000000000068-2017-02-01T16:27:25.000Z-1800",
           "s3-usage-8000000000000069-2017-02-01T16:27:24.000Z-1800",
           "s3-usage-8000000000000069-2017-02-01T16:31:07.000Z-1800",
           "s3-usage-800000000000006a-2017-02-01T16:27:24.000Z-1800",
           "s3-usage-800000000000006a-2017-02-01T16:31:08.000Z-1800"
       ]
   }

Querying Statistics Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can display usage statistics with the ``ostor-usage`` service and parameter ``obj`` specifying the statistics object. The output includes the accessed buckets, user ID, and counters. For example:

.. only:: html

   ::
   
       # s3_curl GET "http://s3.example.com/?ostor-usage&obj=s3-usage-8000000000000065-2017-02-01T16:31:54.000Z-1800"
       {
           "fmt_version": 1,
           "service_id": 8000000000000065,
           "start_ts": 1485966714,
           "period": 1390,
           "nr_items": 1,
           "items": [
               {
                   "key": {
                       "bucket": "client",
                       "epoch": 98309,
                       "user_id": "b81d6c5f895a8c86",
                       "tag": ""
                   },
                   "counters": {
                       "ops": {
                           "put": 1,
                           "get": 3,
                           "list": 0,
                           "other": 0
                       },
                       "net_io": {
                           "uploaded": 41258,
                           "downloaded": 45511311
                       }
                   }
               }
           ]
       }

.. only:: latex

   ::
   
       # s3_curl GET "http://s3.example.com/?ostor-usage\
        &obj=s3-usage-8000000000000065-2017-02-01T16:31:54.000Z-1800"
       {
           "fmt_version": 1,
           "service_id": 8000000000000065,
           "start_ts": 1485966714,
           "period": 1390,
           "nr_items": 1,
           "items": [
               {
                   "key": {
                       "bucket": "client",
                       "epoch": 98309,
                       "user_id": "b81d6c5f895a8c86",
                       "tag": ""
                   },
                   "counters": {
                       "ops": {
                           "put": 1,
                           "get": 3,
                           "list": 0,
                           "other": 0
                       },
                       "net_io": {
                           "uploaded": 41258,
                           "downloaded": 45511311
                       }
                   }
               }
           ]
       }

Deleting Statistics Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can delete existing statistics objects with the ``ostor-usage`` service and parameter ``obj`` specifying the statistics object:

.. only:: html

   ::
   
       # s3_curl DELETE "http://s3.example.com/?ostor-usage&obj=s3-usage-8000000000000065-2017-02-01T16:31:54.000Z-1800"

.. only:: latex

   ::
   
       # s3_curl DELETE "http://s3.example.com/?ostor-usage\
        &obj=s3-usage-8000000000000065-2017-02-01T16:31:54.000Z-1800"
