private void SendMetrics(IList <MetricDatum> data, string dataNamesspace) { if (data == null || data.Count == 0 || String.IsNullOrWhiteSpace(dataNamesspace)) { WriteMessage("Nothing to send"); return; } var appSettings = ConfigurationManager.AppSettings; WriteMessage(String.Join(",", data.Select(d => d.Value.ToString()).ToArray())); //setup cloudwatch service AmazonCloudWatch client = Amazon.AWSClientFactory.CreateAmazonCloudWatchClient(appSettings["AWS-CloudWatch-AccessKey"], appSettings["AWS-CloudWatch-SecretKey"], new AmazonCloudWatchConfig { ServiceURL = appSettings["AWS-CloudWatch-ServiceUrl"] }); //cloud-watch only lets us send maximum of 20 pieces of metric data per request, // so split in to groups of 20 var dataGrp = from i in Enumerable.Range(0, data.Count()) group data[i] by i / 20; dataGrp.ToList().ForEach(dataSet => client.PutMetricData(new PutMetricDataRequest() .WithMetricData(dataSet.AsEnumerable()) .WithNamespace(dataNamesspace)) ); }
public void Disconnect() { if (ec2 != null) { Debug.Assert(RunMonitoring); Debug.Assert(MonitoringThread != null); Debug.Assert(route53 != null); Debug.Assert(s3 != null); Debug.Assert(CloudWatch != null); myTaskQueue.Close(); bool killedTheThread = false; //Shut the thread lock (Ec2Lock) { RunMonitoring = false; } if (!MonitoringThread.Join(10000)) { MonitoringThread.Abort(); killedTheThread = true; } MonitoringThread = null; ec2.Dispose(); ec2 = null; route53.Dispose(); route53 = null; s3.Dispose(); s3 = null; CloudWatch.Dispose(); CloudWatch = null; if (killedTheThread) { throw new ZAwsException("Connection failure, could not close connection gracefully. Might require restart."); } } else { Debug.Assert(!RunMonitoring); Debug.Assert(MonitoringThread == null); } }
public override void ViewDidLoad() { base.ViewDidLoad (); client = Amazon.AWSClientFactory.CreateAmazonCloudWatchClient (RegionEndpoint.USWest2); this.Title = "Cloud Watch"; Source = new TableViewSource(); TableView.Source = Source; addBtn = new UIBarButtonItem (UIBarButtonSystemItem.Add, delegate { AddItem(); }); refreshBtn = new UIBarButtonItem (UIBarButtonSystemItem.Refresh, delegate { Refresh(); }); UIActivityIndicatorView spinner = new UIActivityIndicatorView (new RectangleF (0, 0, 22, 22)); spinner.StartAnimating (); loadingBtn = new UIBarButtonItem (spinner); ReloadUI(); Refresh(); }
public override void ViewDidLoad() { base.ViewDidLoad(); client = Amazon.AWSClientFactory.CreateAmazonCloudWatchClient(RegionEndpoint.USWest2); this.Title = "Cloud Watch"; Source = new TableViewSource(); TableView.Source = Source; addBtn = new UIBarButtonItem(UIBarButtonSystemItem.Add, delegate { AddItem(); }); refreshBtn = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, delegate { Refresh(); }); UIActivityIndicatorView spinner = new UIActivityIndicatorView(new RectangleF(0, 0, 22, 22)); spinner.StartAnimating(); loadingBtn = new UIBarButtonItem(spinner); ReloadUI(); Refresh(); }
public void Connect() { if (ec2 != null) { throw new ZAwsEWrongState("Controller is already open"); } Debug.Assert(route53 == null); Debug.Assert(s3 == null); Debug.Assert(!RunMonitoring); Debug.Assert(MonitoringThread == null); ec2 = AWSClientFactory.CreateAmazonEC2Client(awsAccessKey, awsSecretKey, new AmazonEC2Config().WithServiceURL(awsEc2ZoneUrl)); route53 = AWSClientFactory.CreateAmazonRoute53Client(awsAccessKey, awsSecretKey, new AmazonRoute53Config() { ServiceURL = awsRoute53ZoneUrl }); s3 = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey, new AmazonS3Config().WithServiceURL(awsS3ZoneUrl)); CloudWatch = AWSClientFactory.CreateAmazonCloudWatchClient(awsAccessKey, awsSecretKey, new AmazonCloudWatchConfig() { ServiceURL = awsCloudWatchZoneUrl }); //Start the thread MonitoringThread = new Thread(new ThreadStart(MonitorFunction)); RunMonitoring = true; MonitoringThread.Start(); }
private void SetupClient() { if (_client != null) return; AmazonCloudWatchConfig cloudWatchConfig = null; RegionEndpoint regionEndpoint = null; if (string.IsNullOrEmpty(EndPoint) && ConfigurationManager.AppSettings["AWSServiceEndpoint"] != null) EndPoint = ConfigurationManager.AppSettings["AWSServiceEndpoint"]; if (string.IsNullOrEmpty(AccessKey) && ConfigurationManager.AppSettings["AWSAccessKey"] != null) AccessKey = ConfigurationManager.AppSettings["AWSAccessKey"]; if (string.IsNullOrEmpty(Secret) && ConfigurationManager.AppSettings["AWSSecretKey"] != null) Secret = ConfigurationManager.AppSettings["AWSSecretKey"]; _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret); try { if (!string.IsNullOrEmpty(EndPoint)) { if (EndPoint.StartsWith("http")) { cloudWatchConfig = new AmazonCloudWatchConfig { ServiceURL = EndPoint }; if (string.IsNullOrEmpty(AccessKey)) _client = AWSClientFactory.CreateAmazonCloudWatchClient(cloudWatchConfig); } else { regionEndpoint = RegionEndpoint.GetBySystemName(EndPoint); if (string.IsNullOrEmpty(AccessKey)) _client = AWSClientFactory.CreateAmazonCloudWatchClient(regionEndpoint); } } } catch (AmazonServiceException) { } if (!string.IsNullOrEmpty(AccessKey)) if (regionEndpoint != null) _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret, regionEndpoint); else if (cloudWatchConfig != null) _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret, cloudWatchConfig); else _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret); //Debug var metricDatum = new Amazon.CloudWatch.Model.MetricDatum().WithMetricName("CloudWatchAppender").WithValue(1).WithUnit("Count"); //_client.PutMetricData(new PutMetricDataRequest().WithNamespace("CloudWatchAppender").WithMetricData(metricDatum)); }
private void Form1_Shown(object sender, EventArgs e) { // Initialize Cloud Watch with region APNorthEast1 (Tokyo) cw = Amazon.AWSClientFactory.CreateAmazonCloudWatchClient(AWSAccessKey, AWSSecretKey, RegionEndpoint.APNortheast1); // Retrieve the list of Metrics ListMetricsRequest metricsRequest = new ListMetricsRequest(); for (int i = 1; i < namespaceList.Count; i++) { fromindex[i] = metricList.Count; metricsRequest.Namespace = namespaceList[i]; metricsRequest.NextToken = null; try { var result = cw.ListMetrics(metricsRequest).ListMetricsResult; var tempList = result.Metrics; while (result.NextToken != null) { metricsRequest.NextToken = result.NextToken; result = cw.ListMetrics(metricsRequest).ListMetricsResult; tempList.AddRange(result.Metrics); } tempList = tempList.OrderBy(a => a.Dimensions.Count) .ThenBy(a => a.MetricName) .ThenBy(a => a.Dimensions.Count > 0 ? a.Dimensions[0].Name : "") .ThenBy(a => a.Dimensions.Count > 0 ? a.Dimensions[0].Value : "") .ThenBy(a => a.Dimensions.Count > 1 ? a.Dimensions[1].Name : "") .ThenBy(a => a.Dimensions.Count > 1 ? a.Dimensions[1].Value : "").ToList(); metricList.AddRange(tempList); toindex[i] = metricList.Count; // Debug.WriteLine(metricList.Count); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); return; } } // For all metrics fromindex[0] = 0; toindex[0] = metricList.Count; // Initialize plottedStat for (int i = 0; i < metricList.Count; i++) { plottedStat.Add(-1); // no stat was plotted } // Give control to search text box to start a search for metrics searchTBox.Select(); }