-
Notifications
You must be signed in to change notification settings - Fork 3
Listing Metrics with Utapi
To make a successful request to Utapi you would need
Note: The examples here use AWS CLI but any AWS SDK is capable of these actions.
-
Create an IAM user
aws iam --endpoint-url <endpoint> create-user --user-name utapiuser
-
Create access key for the user
aws iam --endpoint-url <endpoint> create-access-key --user-name utapiuser
-
Create a managed IAM policy
aws iam --endpoint-url <endpoint> create-policy --policy-name utapipolicy \ --policy-document file://utapipolicy.json
sample utapi policy
{ "Version": "2012-10-17", "Statement": [ { "Sid": "utapiMetrics", "Action": [ "utapi:ListMetrics" ], "Effect": "Allow", "Resource": "arn:scality:utapi:::buckets/*" } ] }
The user can also be restricted to only some buckets (foo bucket for example) by changing the
Resource
property to"Resource": "arn:scality:utapi:::buckets/foo"
-
Attach user to the managed policy
aws --endpoint-url <endpoint> iam attach-user-policy --user-name utapiuser --policy-arn <policy arn>
Now the user utapiuser
has access to ListMetrics request in Utapi on all
buckets.
There are two options here.
You can generate V4 signature using AWS SDKs. See the following urls for reference.
http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
or
You can use a nifty command line tool available in Scality's S3. You can git clone S3 repo or docker exec into the S3 container and type.
node bin/list_bucket_metrics
It will generate the following output listing available options.
Usage: list_bucket_metrics [options]
Options:
-h, --help output usage information
-V, --version output the version number
-a, --access-key <accessKey> Access key id
-k, --secret-key <secretKey> Secret access key
-b, --buckets <buckets> Name of bucket(s)with a comma separator if more than one
-s, --start <start> Start of time range
-e --end <end> End of time range
-h, --host <host> Host of the server
-p, --port <port> Port of the server
--ssl Enable ssl
-v, --verbose
A typical call to list metrics for a bucket demo
to Utapi in a https enabled deployment would be
node bin/list_bucket_metrics -a myAccessKey -k mySecretKey -b demo -s 1476231300000 -h 127.0.0.1 -p 8100 -ssl
Both start and end times are time expressed as UNIX epoch timestamps.
Keep in mind, since Utapi metrics are normalized to the nearest 15 min. interval, so start time and end time need to be in specific format as follows.
Start time
Start time needs to be normalized to the nearest 15 minute interval with seconds and milliseconds set to 0. So valid start timestamps would look something like 09:00:00:000
, 09:15:00:000
, 09:30:00:000
and 09:45:00:000
.
For example Date: Tue Oct 11 2016 17:35:25 GMT-0700 (PDT) Unix timestamp: 1476232525320
Here's a typical JS method to get start timestamp
getStartTimestamp(t) {
const time = new Date(t);
const minutes = time.getMinutes();
const timestamp = time.setMinutes((minutes - minutes % 15), 0, 0);
return timestamp;
},
This would format the start time timestamp to 1476231300000
End time
End time needs to be normalized to the nearest 15 minute end interval with seconds and milliseconds set to 59 and 999 respectively. So valid start timestamps would look something like 09:14:59:999
, 09:29:59:999
, 09:44:59:999
and 09:59:59:999
.
Here's a typical JS method to get end timestamp
getEndTimestamp(t) {
const time = new Date(t);
const minutes = time.getMinutes();
const timestamp = time.setMinutes((minutes - minutes % 15) + 15, 0, -1);
return timestamp;
}
This would format the end time timestamp to 1476233099999