/// <summary>
        /// Check if all required monitors exists in monitis API
        /// </summary>
        /// <returns></returns>
        public Boolean CheckCustomMonitors()
        {
            CustomMonitorAPI customMonitorAPI = new CustomMonitorAPI(this.APIKey, this.APIType);
            IEnumerable<Monitor> monitorList = customMonitorAPI.GetMonitorList();

            foreach (String monitorName in CustomMonitorList.Singleton.MonitorNames)
            {
                String name = monitorName;
                Monitor monitor = monitorList.FirstOrDefault(f => f.Name.Equals(name));
                if (monitor == null)
                {
                    return false;
                }

                CustomMonitorList.Singleton.GetConfigByMonitorName(monitor.Name).MonitorID = monitor.ID;
            }
            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update monitis custom monitor with new perfomance counters data.
        /// Trigger by timer instance
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdatePerfomanceCounters(object sender, ElapsedEventArgs e)
        {
            //TODO: look like template pattern

            //create query executer for access to data in Windows Azure Table Service
            var queryExecuter = new QueryExecuter(_userSession.AzureInfo.AccountName, _userSession.AzureInfo.AccountKey);

            var customMonitorAPI = new CustomMonitorAPI(_userSession.APIKey, _userSession.APIType);
            foreach (var kvp in _counterNameEventUpdateMap)
            {
                InvokeStatusChanged(kvp.Key + "> start update");

                //get perfomance counter data
                IEnumerable<PerformanceData> data = queryExecuter.GetPerformanceCounters(kvp.Key,
                                                                                         _userSession.AzureInfo.
                                                                                             DeploymentInfo.
                                                                                             RoleInstanceName,
                                                                                         DateTime.UtcNow.AddSeconds(
                                                                                             -_syncPeriod.TotalSeconds),
                                                                                         DateTime.UtcNow);

                InvokeStatusChanged(kvp.Key + "> retrieved records count from Azure:" + data.Count());

                CustomMonitorConfig configByMetricName = CustomMonitorList.Singleton.GetConfigByMetricName(kvp.Key);

                //convert Windows Azure perfomance counters data to monitis monitor parameters data
                List<ResultParameter> convertToMonitorResults = DataConverter.ConvertToMonitorResults(data,
                                                                                        configByMetricName.Descriptor.
                                                                                            Converter);

                InvokeStatusChanged(kvp.Key + "> push data to Monitis");

                //add result to monitor
                customMonitorAPI.AddResults(_userSession.CurrentAuthToken, configByMetricName.MonitorID,
                                            convertToMonitorResults);

                //fire event to update all handlers
                kvp.Value(this, new CounterDataEventArgs { PerformanceDatas = data });
            }

            InvokeStatusChanged(String.Format("Next update after {0} second",
                                              TimeSpan.FromMilliseconds(_updateTimer.Interval).TotalSeconds));
        }
        /// <summary>
        /// Create monitors for Azure metrics and counters in Monitis service
        /// </summary>
        public List<string> CreateAzureMonitors()
        {
            CustomMonitorAPI customMonitorAPI = new CustomMonitorAPI(this.APIKey, this.APIType);

            List<String> notAddedMonitors = new List<String>();
            IEnumerable<Monitor> monitorList = customMonitorAPI.GetMonitorList();
            foreach (var monitorName in CustomMonitorList.Singleton.MonitorNames.Except(monitorList.Select(f => f.Name)))
            {
                AddMonitorResponse addMonitorResponse = customMonitorAPI.AddMonitor(CurrentAuthToken,
                    CustomMonitorList.Singleton.GetConfigByMonitorName(monitorName).Descriptor);

                if (!addMonitorResponse.IsOk)
                {
                    notAddedMonitors.Add(monitorName);
                }
            }
            return notAddedMonitors;
        }
Ejemplo n.º 4
0
        private void MediateTableMetrics(DateTime start, DateTime end)
        {
            var queryExecuter = new QueryExecuter(_userSession.AzureInfo.AccountName, _userSession.AzureInfo.AccountKey);

            InvokeStatusStorageMetricsChanged("Get metrics data from Azure");
            MetricsTransactionsEntity[] metricsTransactionsEntities = queryExecuter.GetMetricData(start, end);

            String statusFormat = "Captured records count: {0}\r\nPushed to monitis service:{1}";

            Int32 totalProcessedRecords = 0;
            InvokeStatusStorageMetricsChanged(String.Format(statusFormat, metricsTransactionsEntities.Length, totalProcessedRecords));
            var customMonitorAPI = new CustomMonitorAPI(_userSession.APIKey, _userSession.APIType);

            foreach (MetricsTransactionsEntity metricsTransactionsEntity in metricsTransactionsEntities)
            {
                CustomMonitorConfig availabilityConfig =
                    CustomMonitorList.Singleton.GetConfigByMetricName(MetricNames.Availability);
                ResultParameter convertToMonitorResult = DataConverter.ConvertToMonitorResult(metricsTransactionsEntity.Availability,
                                                                                metricsTransactionsEntity.Timestamp,
                                                                                availabilityConfig);

                customMonitorAPI.AddResults(_userSession.CurrentAuthToken, availabilityConfig.MonitorID,
                                            new List<ResultParameter> { convertToMonitorResult });

                CustomMonitorConfig totalRequestsConfig =
                    CustomMonitorList.Singleton.GetConfigByMetricName(MetricNames.TotalRequests);
                convertToMonitorResult = DataConverter.ConvertToMonitorResult(metricsTransactionsEntity.TotalRequests,
                                                                metricsTransactionsEntity.Timestamp,
                                                                totalRequestsConfig);
                customMonitorAPI.AddResults(_userSession.CurrentAuthToken, totalRequestsConfig.MonitorID,
                                            new List<ResultParameter> { convertToMonitorResult });

                CustomMonitorConfig totalBillableRequestsConfig =
                    CustomMonitorList.Singleton.GetConfigByMetricName(MetricNames.TotalBillableRequests);
                convertToMonitorResult = DataConverter.ConvertToMonitorResult(metricsTransactionsEntity.TotalBillableRequests,
                                                                metricsTransactionsEntity.Timestamp,
                                                                totalBillableRequestsConfig);
                customMonitorAPI.AddResults(_userSession.CurrentAuthToken, totalBillableRequestsConfig.MonitorID,
                                            new List<ResultParameter> { convertToMonitorResult });

                totalProcessedRecords++;
                InvokeStatusStorageMetricsChanged(String.Format(statusFormat, metricsTransactionsEntities.Length, totalProcessedRecords));
            }
            InvokeStatusStorageMetricsChanged("Completed");
            InvokeStorageMetricsPublishCompleted(EventArgs.Empty);
        }