Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

defined records foe CloudWtatch

  • Loading branch information...
commit 3e14ff46b4959cfa58b28a57f6c4e652b9bebd0c 1 parent 4fafffa
@nivertech nivertech authored
Showing with 156 additions and 11 deletions.
  1. +70 −0 include/erlcloud_mon.hrl
  2. +86 −11 src/erlcloud_mon.erl
View
70 include/erlcloud_mon.hrl
@@ -0,0 +1,70 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% File: erlcloud_mon.hrl
+%% Date: 18-Sep-2011
+%%
+%% @doc AWS CloudWatch erlang binding (the CLI SDK uses "mon_" prefix)
+%%
+%% @author Zvi Avraham <zvi-AT-nivertech-DOT-com>
+%% @copyright 2011 Zvi Avraham
+%% @end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%------------------------------------------------------------------------------
+%% @doc date time
+%% @end
+%%------------------------------------------------------------------------------
+%-type datetime() :: string().
+
+%%------------------------------------------------------------------------------
+%% @doc The unit of the metric.
+%% Valid Values: Seconds | Microseconds | Milliseconds
+%% | Bytes | Kilobytes | Megabytes | Gigabytes | Terabytes | Bits | Kilobits | Megabits | Gigabits | Terabits
+%% | Percent | Count | Bytes/Second | Kilobytes/Second | Megabytes/Second | Gigabytes/Second | Terabytes/Second
+%% | Bits/Second | Kilobits/Second | Megabits/Second | Gigabits/Second | Terabits/Second | Count/Second | None
+%% @end
+%%------------------------------------------------------------------------------
+-type unit() :: string().
+
+%%------------------------------------------------------------------------------
+%% @doc Dimension
+%% The Dimension data type further expands on the identity of a metric using a Name, Value pair.
+%% For examples that use one or more dimensions, see PutMetricData.
+%% @see[ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_Dimension.html ]
+%% @end
+%%------------------------------------------------------------------------------
+-record(dimension, {
+ name ::string(), %% The name of the dimension. Length constraints: Minimum value of 1. Maximum value of 255.
+ value ::string() %% The value representing the dimension measurement. Length constraints: Minimum value of 1. Maximum value of 255.
+}).
+-type dimension() :: #dimension{}.
+
+%%------------------------------------------------------------------------------
+%% @doc StatisticSet
+%% @see[ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_StatisticSet.html ]
+%% @end
+%%------------------------------------------------------------------------------
+-record(statistics_set, {
+ sample_count ::non_neg_integer(), %% The number of samples used for the statistic set.
+ maximum ::float(), %% The maximum value of the sample set.
+ minimum ::float(), %% The minimum value of the sample set.
+ sum ::float() %% The sum of values for the sample set.
+}).
+-type statistics_set() :: #statistics_set{}.
+
+%%------------------------------------------------------------------------------
+%% @doc MetricDatum
+%% @see[ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_MetricDatum.html ]
+%% @end
+%%------------------------------------------------------------------------------
+-record(metric_datum, {
+ metric_name ::string(), %% The name of the metric.
+ %% Length constraints: Minimum value of 1. Maximum value of 255.
+ 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::statistics_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.
+ unit ::unit(), %% The unit of the metric.
+ value ::float() %% The value for the metric.
+}).
+-type metric_datum() :: #metric_datum{}.
+
View
97 src/erlcloud_mon.erl
@@ -12,8 +12,9 @@
-module(erlcloud_mon).
-export([
- list_metrics/0,
- put_metric_data/3
+ list_metrics/4,
+ put_metric_data/2,
+ get_metric_statistics/8
]).
-include("erlcloud.hrl").
@@ -26,17 +27,55 @@
-define(XMLNS_MON, "http://monitoring.amazonaws.com/doc/2010-08-01/").
-define(API_VERSION, "2010-08-01").
+-define(FMT(Fmt,Args), lists:flatten(io_lib:format((Fmt),(Args)))).
+
%%------------------------------------------------------------------------------
%% @doc CloudWatch API - ListMetrics
+%% @see [ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_ListMetrics.html ]
+%%
+%% USAGE:
+%%
+%% erlcloud_mon:list_metrics("AWS/EC2", "NetworkIn", [{"InstanceType","m1.large"}], "").
+%% [[{metric_name,"NetworkIn"},
+%% {namespace,"AWS/EC2"},
+%% {dimensions,[[{name,"InstanceType"},{value,"m1.large"}]]}]]
+%%
%% @end
%%------------------------------------------------------------------------------
--spec list_metrics() -> term().
-list_metrics() ->
+-spec list_metrics(
+ Namespace ::string(),
+ MetricName ::string(),
+ DimensionFilter ::[{string(),string()}],
+ NextToken ::string()
+ ) -> term().
+
+list_metrics(
+ Namespace,
+ MetricName,
+ DimensionFilter,
+ NextToken
+ ) ->
+
Config = default_config(),
- Doc = mon_query(Config, "ListMetrics", []),
+ Params =
+ [{"Namespace", Namespace} || Namespace/=""]
+ ++
+ [{"MetricName", MetricName} || MetricName/=""]
+ ++
+ [{"NextToken", NextToken} || NextToken/=""]
+ ++
+ lists:flatten(
+ [begin
+ {Name, Value} = lists:nth(N, DimensionFilter),
+ [{?FMT("Dimensions.member.~b.Name", [N]), Name},
+ {?FMT("Dimensions.member.~b.Value", [N]), Value}]
+ end
+ || N<-lists:seq(1, length(DimensionFilter))]
+ ),
+
+ Doc = mon_query(Config, "ListMetrics", Params),
Members = xmerl_xpath:string("/ListMetricsResponse/ListMetricsResult/Metrics/member", Doc),
[extract_member(Member) || Member <- Members].
- %Doc.
extract_member(Node) ->
[
@@ -55,18 +94,54 @@ extract_dimension(Node) ->
%%------------------------------------------------------------------------------
%% @doc CloudWatch API - PutMetricData
+%% @see [ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_PutMetricData.html ]
%% @end
%%------------------------------------------------------------------------------
--spec put_metric_data(Namespace::string(), MetricName::string(), Value::string()) -> term().
-put_metric_data(Namespace, MetricName, Value) ->
+-spec put_metric_data(
+ Namespace ::string(),
+ MetricData ::[metric_datum()]
+ ) -> term().
+
+put_metric_data(Namespace, MetricData) ->
Config = default_config(),
Params =
- [{"Namespace", Namespace},
- {"MetricData.member.1.MetricName", MetricName},
- {"MetricData.member.1.Value", Value}],
+ [
+ {"Namespace", Namespace}
+ %,
+ %{"MetricData.member.1.MetricName", MetricName},
+ %{"MetricData.member.1.Value", Value}
+ ],
mon_query(Config, "PutMetricData", Params).
%%------------------------------------------------------------------------------
+%% @doc CloudWatch API - GetMetricStatistics
+%% @see [ http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_GetMetricStatistics.html ]
+%% @end
+%%------------------------------------------------------------------------------
+-spec get_metric_statistics(
+ Namespace ::string(),
+ MetricName ::string(),
+ StartTime ::string(),
+ EndTime ::string(),
+ Period ::pos_integer(),
+ Unit ::string(),
+ Statistics ::[string()],
+ Dimensions ::[string()]
+ ) -> term().
+
+get_metric_statistics(
+ Namespace,
+ MetricName,
+ StartTime,
+ EndTime,
+ Period,
+ Unit,
+ Statistics,
+ Dimensions
+ ) ->
+ todo.
+
+%%------------------------------------------------------------------------------
mon_simple_query(Config, Action, Params) ->
mon_query(Config, Action, Params),
ok.
Please sign in to comment.
Something went wrong with that request. Please try again.