Permalink
Browse files

timestamp in both tuple datetime and Amazon string formats

  • Loading branch information...
1 parent 36bbb27 commit 17bc4dd83fa531052e8e625fce8f8f92ab0bfa50 @nivertech nivertech committed Sep 18, 2011
Showing with 29 additions and 14 deletions.
  1. +1 −1 include/erlcloud_mon.hrl
  2. +28 −13 src/erlcloud_mon.erl
@@ -62,7 +62,7 @@
dimensions ::[dimension()], %% A list of dimensions associated with the metric.
%% Length constraints: Minimum of 0 item(s) in the list. Maximum of 10 item(s) in the list.
statistic_values::statistic_set(), %% A set of statistical values describing the metric.
- timestamp ::datetime(), %% The time stamp used for the metric. If not specified, the default value is set to the time the metric data was received.
+ timestamp ::datetime()|string(),%% The time stamp used for the metric. If not specified, the default value is set to the time the metric data was received.
unit ::unit(), %% The unit of the metric.
value ::float() %% The value for the metric.
}).
View
@@ -14,7 +14,7 @@
-export([
list_metrics/4,
put_metric_data/2,
- put_metric_data/4,
+ put_metric_data/5,
get_metric_statistics/8,
test/0,
test2/0
@@ -143,17 +143,30 @@ params_metric_data(NM,MD) ->
lists:flatten(
[
[ {?FMT("~s.MetricName",[Prefix]), MD#metric_datum.metric_name} ],
- [ {?FMT("~s.Unit", [Prefix]), MD#metric_datum.unit} || MD#metric_datum.unit=/=undefined ],
- [ {?FMT("~s.Timestamp", [Prefix]), MD#metric_datum.timestamp} || MD#metric_datum.timestamp=/=undefined ],
- [ {?FMT("~s.Value", [Prefix]), float_to_list(MD#metric_datum.value)} || MD#metric_datum.value=/=undefined ],
- [ params_stat(Prefix, MD#metric_datum.statistic_values) || MD#metric_datum.statistic_values=/=undefined ],
+ [ {?FMT("~s.Unit", [Prefix]), MD#metric_datum.unit} || MD#metric_datum.unit=/=undefined ],
+ [ {?FMT("~s.Timestamp", [Prefix]), format_timestamp(MD#metric_datum.timestamp)} || MD#metric_datum.timestamp=/=undefined ],
+ [ {?FMT("~s.Value", [Prefix]), float_to_list(MD#metric_datum.value)} || MD#metric_datum.value=/=undefined ],
+ [ params_stat(Prefix, MD#metric_datum.statistic_values) || MD#metric_datum.statistic_values=/=undefined ],
[ params_dimension(Prefix, ND, Dimension)
|| {ND,Dimension} <- lists:zip(lists:seq(1, length(MD#metric_datum.dimensions)), MD#metric_datum.dimensions)
]
]
).
%%------------------------------------------------------------------------------
+%% @doc format datetime as Amazon timestamp
+%% @end
+%%------------------------------------------------------------------------------
+format_timestamp({{Yr, Mo, Da}, {H, M, S}} = Timestamp)
+ when is_integer(Yr), is_integer(Mo), is_integer(Da),
+ is_integer(H), is_integer(M), is_integer(S)
+ ->
+ erlcloud_aws:format_timestamp(Timestamp);
+
+format_timestamp(Timestamp) when is_list(Timestamp) ->
+ Timestamp.
+
+%%------------------------------------------------------------------------------
-spec params_dimension(Prefix::string(), ND::pos_integer(), Dimension::dimension()) -> [{string(),string()}].
params_dimension(Prefix, ND, Dimension) ->
DimPrefix = ?FMT("~s.Dimensions.member.~b", [Prefix, ND]),
@@ -163,8 +176,7 @@ params_dimension(Prefix, ND, Dimension) ->
].
%%------------------------------------------------------------------------------
-%% @doc format statistic value record to string
-%% "Sum=577,Minimum=65,Maximum=189,SampleCount=5"
+%% @doc format statistic value records to URI params
%% @end
%%------------------------------------------------------------------------------
-spec params_stat(Prefix::string(), StatisticValues::statistic_set()) -> [{string(),string()}].
@@ -185,10 +197,11 @@ params_stat(Prefix, StatisticValues) ->
Namespace ::string(),
MetricName ::string(),
Value ::string(),
- Unit ::unit()
+ Unit ::unit(),
+ Timestamp ::datetime()|string()
) -> term().
-put_metric_data(Namespace, MetricName, Value, Unit) ->
+put_metric_data(Namespace, MetricName, Value, Unit, Timestamp) ->
Config = default_config(),
Params =
[
@@ -197,7 +210,9 @@ put_metric_data(Namespace, MetricName, Value, Unit) ->
{"MetricData.member.1.Value", Value}
]
++
- [ {"MetricData.member.1.Unit", Unit} || Unit=/="", Unit=/=undefined ],
+ [ {"MetricData.member.1.Unit", Unit} || Unit=/=undefined, Unit=/="" ]
+ ++
+ [ {"MetricData.member.1.Timestamp", format_timestamp(Timestamp)} || Timestamp=/=undefined, Timestamp=/="" ],
mon_simple_query(Config, "PutMetricData", Params).
@@ -269,9 +284,9 @@ test() ->
unit = "Count",
value = undefined
},
- %put_metric_data("my", [M1, M2]).
- put_metric_data("my", [M2]).
+ put_metric_data("my", [M1, M2]).
+ %put_metric_data("my", [M2]).
test2() ->
- put_metric_data("my", "zvi", "13", "Count").
+ put_metric_data("my", "zvi", "13", "Count", "").

0 comments on commit 17bc4dd

Please sign in to comment.