Exemple #1
0
        MetricDatum to_sdk_metric_datum(Metric m, int numBuckets)
        {
            var          a  = m.Accumulator();
            StatisticSet ss = new StatisticSet();

            ss.Sum         = a.sum(numBuckets);
            ss.Minimum     = a.min(numBuckets);
            ss.Maximum     = a.max(numBuckets);
            ss.SampleCount = a.count(numBuckets);

            MetricDatum d = new MetricDatum();

            d.StatisticValues = ss;

            foreach (var p in m.All_dimensions())
            {
                if (p.Key == "MetricName")
                {
                    d.MetricName = p.Value;
                }
                else
                {
                    d.Dimensions.Add(new Amazon.CloudWatch.Model.Dimension()
                    {
                        Name = p.Key, Value = p.Value
                    });
                }
            }

            d.Unit      = MetricsConstant.unit(d.MetricName);
            d.Timestamp = DateTime.Now;
            return(d);
        }
Exemple #2
0
        string generate_query_args(Metric m, int idx, DateTime tp)
        {
            string prefix = "MetricData.member.";

            prefix += idx;
            prefix += ".";
            string        metric_name = "";
            StringBuilder ss          = new StringBuilder();

            {
                int i = 1;
                foreach (var p in m.All_dimensions())
                {
                    if (p.Key != "MetricName")
                    {
                        string dim_prefix = "Dimensions.member.";
                        dim_prefix += i++;
                        dim_prefix += ".";
                        ss.Append(prefix).Append(dim_prefix).Append("Name=").Append(escape(p.Key)).Append("&")
                        .Append(prefix).Append(dim_prefix).Append("Value=").Append(escape(p.Value)).Append("&");
                    }
                    else
                    {
                        ss.Append(prefix).Append("MetricName=").Append(p.Value).Append("&");
                        metric_name = p.Value;
                    }
                }
            }

            {
                var a     = m.Accumulator();
                var count = a.count(kNumBuckets);
                if (count == 0)
                {
                    return(null);
                }

                string stat_prefix = prefix;
                stat_prefix += "StatisticValues.";
                ss.Append(stat_prefix).Append("Maximum=").Append(escape(a.max(kNumBuckets))).Append("&")
                .Append(stat_prefix).Append("Minimum=").Append(escape(a.min(kNumBuckets))).Append("&")
                .Append(stat_prefix).Append("Sum=").Append(escape(a.sum(kNumBuckets))).Append("&")
                .Append(stat_prefix).Append("SampleCount=").Append(escape(count)).Append("&");
            }

            ss.Append(prefix).Append("Unit=").Append(MetricsConstant.unit(metric_name)).Append("&");
            ss.Append(prefix).Append("Timestamp=").Append(escape(KPLNETInterface.Utils.format_ptime(tp))).Append("&");

            return(ss.ToString());
        }
Exemple #3
0
        void upload()
        {
            List <Metric> uploads = new List <Metric>();

            foreach (var m in metrics_index.get_all())
            {
                if (MetricsConstant.filter(m.All_dimensions(), level, granularity) && m.Accumulator().count(kNumBuckets) > 0)
                {
                    uploads.Add(m);
                }
            }

            // Sort in reverse order to create a stack we can pop in unreversed order.
            uploads.Sort
            (
                (a, b) =>
            {
                var v1 = a.All_dimensions();
                var v2 = b.All_dimensions();

                if (v1.Count != v2.Count)
                {
                    return(v1.Count < v2.Count ? -1 : 1);
                }

                for (int i = 0; i < v1.Count; i++)
                {
                    if (v1[i].Key != v2[i].Key || v1[i].Value != v2[i].Value)
                    {
                        return(v1[i].Key.CompareTo(v2[i].Key));
                    }
                }

                return(1);
            }
            );

            if (config_.clientType == KPLNETInterface.ClientType.SocketClient)
            {
                uploadHTTP(uploads);
            }
            else
            {
                uploadClient(uploads);
            }
        }