public async Task <ActionResult <IEnumerable <MetricItem> > > GetMetricItems(string userName, string shimKey) { ClearContext(); string hazelcastIP = Environment.GetEnvironmentVariable("ENV_HIP"); if (string.IsNullOrEmpty(hazelcastIP)) { hazelcastIP = "127.0.0.1"; } var cfg = new ClientConfig(); cfg.GetNetworkConfig().AddAddress(hazelcastIP); var client = HazelcastClient.NewHazelcastClient(cfg); IMap <string, double> mapMetricsAggregatedData = client.GetMap <string, double>("metrics-aggregated-data"); ICollection <string> keys = mapMetricsAggregatedData.KeySet(); MetricItem metricItem; foreach (var key in keys) { string[] keyParts = key.Split('*'); if (String.Equals(userName, keyParts[0]) && String.Equals(shimKey, keyParts[1])) { metricItem = new MetricItem(); metricItem.Id = key; metricItem.Value = mapMetricsAggregatedData.Get(key);; _context.MetricItems.Add(metricItem); await _context.SaveChangesAsync(); } } return(await _context.MetricItems.ToListAsync()); }
public async Task <ActionResult <MetricItem> > PostMetricItem(MetricItem metricItem) { _context.MetricItems.Add(metricItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMetricItem", new { Id = metricItem.Id }, metricItem)); }
/// <inheritdoc /> public void Decrement(CounterOptions options, long amount, Action <MetricItem> itemSetup) { var item = new MetricItem(); itemSetup(item); _registry.Counter(options, () => Advanced.BuildCounter(options)).Decrement(item, amount); }
public async Task <ActionResult <MetricItem> > GetMetricItem(string userName, string shimKey, string endpoint) { var metricItem = new MetricItem(); await Task.Run(() => { string hazelcastIP = Environment.GetEnvironmentVariable("ENV_HIP"); if (string.IsNullOrEmpty(hazelcastIP)) { hazelcastIP = "127.0.0.1"; } var cfg = new ClientConfig(); cfg.GetNetworkConfig().AddAddress(hazelcastIP); var client = HazelcastClient.NewHazelcastClient(cfg); IMap <string, double> mapMetricsAggregatedData = client.GetMap <string, double>("metrics-aggregated-data"); ICollection <string> keys = mapMetricsAggregatedData.KeySet(); foreach (var key in keys) { string[] keyParts = key.Split('*'); if (String.Equals(userName, keyParts[0]) && String.Equals(shimKey, keyParts[1]) && String.Equals(endpoint, keyParts[2])) { metricItem = new MetricItem(); metricItem.Id = key; metricItem.Value = mapMetricsAggregatedData.Get(key); } } }); return(metricItem); }
/// <inheritdoc /> public void Increment(CounterOptions options, Action <MetricItem> itemSetup) { var item = new MetricItem(); itemSetup(item); _registry.Counter(options, () => _counterBuilder.Build()).Increment(item); }
/// <inheritdoc /> public void Mark(MeterOptions options, long amount, Action <MetricItem> itemSetup) { var item = new MetricItem(); itemSetup(item); _registry.Meter(options, () => _meterBuilder.Build(_clock)).Mark(item, amount); }
public async Task <IActionResult> PutMetricItem(string id, MetricItem metricItem) { if (id != metricItem.Id) { return(BadRequest()); } _context.Entry(metricItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MetricItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <inheritdoc /> public void Mark(MeterOptions options, long amount, Action <MetricItem> itemSetup) { var item = new MetricItem(); itemSetup(item); _registry.Meter(options, () => Advanced.BuildMeter(options)).Mark(item, amount); }
public void can_increment_and_decrement_metric_item() { var item = new MetricItem().With("test-item", "value"); _counter.Increment(item, 2L); _counter.Decrement(item); _counter.Value.Items.First().Count.Should().Be(1L); }
/// <summary> /// Method to update a metric item /// </summary> /// <param name="metricItem">Metric item to update</param> /// <param name="userName">logged in user name</param> private void UpdateMetric(MetricItem metricItem, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; //get existing metric details var existingMetric = metricRepository.Get(metricItem.Id.Value); existingMetric.Name = metricItem.Name; existingMetric.DataTypeId = metricItem.DataType.Id.Value; existingMetric.GoalTypeId = metricItem.GoalType.Id.Value; existingMetric.IsActive = metricItem.IsActive; existingMetric.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); existingMetric.LastModifiedBy = loggedInUserId; metricRepository.Save(); }
/// <summary> /// Method to add a metric to database /// </summary> /// <param name="metricItem">metric item to be added</param> /// <param name="userName">logged in user name</param> private void AddMetric(MetricItem metricItem, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; var metric = new Metric() { Name = metricItem.Name, DataTypeId = metricItem.DataType.Id.Value, GoalTypeId = metricItem.GoalType.Id.Value, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId, CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(), IsActive = metricItem.IsActive }; metricRepository.AddOrUpdate(metric); metricRepository.Save(); }
/// <summary> /// Validates an update request for a metric /// </summary> /// <param name="metricItem">Metric item to update</param> /// <returns>List of validation errors of exists</returns> private List <string> ValidateMetricUpdateRequest(MetricItem metricItem) { List <string> validationErrors = new List <string>(); //get existing metric details var existingMetric = metricRepository.Get(metricItem.Id.Value); if (existingMetric == null) { string errorMessage = string.Format(Constants.MetricNotFound, metricItem.Name); validationErrors.Add(errorMessage); } else { // If the request is to update the metric name it self, check if the // new name already exists or not if (existingMetric.Name != metricItem.Name) { if (metricRepository.GetAll().Any(m => m.Name == metricItem.Name)) { string errorMessage = string.Format(Constants.MetricExists, metricItem.Name); validationErrors.Add(errorMessage); } } // If targets are set for this metric, only "IsActive" status can be updated if (existingMetric.AnnualTargets.Any()) { if (existingMetric.GoalTypeId != metricItem.GoalType.Id || existingMetric.DataTypeId != metricItem.DataType.Id) { string errorMessage = string.Format(Constants.MetricUpdateTargetSetErrorMessage, metricItem.Name); validationErrors.Add(errorMessage); } } } return(validationErrors); }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is MetricData metricData)) { return(false); } if (null == metricData.Metrics || 0 == metricData.Metrics.Count) { return(false); } foreach (var metric in metricData.Metrics) { MetricItem metricItem = new MetricItem() { Kind = metric.Kind, Maximum = metric.Maximum ?? 0, Minimum = metric.Minimum ?? 0, SampleRate = envelope.SampleRate, StandardDeviation = metric.StandardDeviation ?? 0, Value = metric.Value, Name = metric.Name, Count = metric.Count ?? 0 }; if (!string.IsNullOrWhiteSpace(metricItem.Name) && -1 < metricItem.Name.IndexOf('\\')) { metricItem.NormalizedName = metricItem.Name.Substring(1 + metricItem.Name.LastIndexOf('\\')); } else { metricItem.NormalizedName = metricItem.Name; } analyticsItem.Metrics.Add(metricItem); } return(true); }
/// <summary> /// Записывает метрику в журнал. /// </summary> /// <typeparam name="T">Тип значения метрики.</typeparam> /// <param name="item">Метрика записываемая в журнал.</param> public void Log <T>(MetricItem <T> item) { }
/// <inheritdoc /> public void Mark(MetricItem item) { Mark(item.ToString()); }
public void Mark(MetricItem item, long amount) { }
public void Increment(MetricItem item) { }
public void Decrement(MetricItem item) { }
private async Task OnItemsLoaded(Guid guid, DispatcherTimer timer, Random rnd) { if (timer.IsEnabled) { timer.Stop(); } StatusQueryCommand result; try { result = await StatusQueryCommand.BeginExecute(guid, true); } catch (Exception ex) { if (this.Logger != null) { this.Logger.Log(LogSeverity.Error, ex.GetType().ToString(), ex); } if (this.ThePopupFactory != null) { this.ThePopupFactory.NotifyFailure(ex); } this.Busy = false; return; } if (result != null && result.Data != null) { var list = result.Data as IMetricAggregateInfoList; if (list != null) { this.ItemsToShow.Clear(); this.items = list; var groups = this.Gadget.SelectedMetric.GetGroupFieldSystemNames().Where(@group => this.items.Count == 0 || this.items[0].GetType().GetProperty(@group) != null).ToList(); //foreach (var item in this.GetItemsToAddToShowList()) foreach (var item in this.items) { var item1 = item; var metricItem = new MetricItem { Result = SafeTypeConverter.Convert<double>(((dynamic)item).Result), Category = string.Join(",", groups.Select(x => item1.GetType().GetProperty(x).GetValue(item1, null))), Color = new SolidColorBrush(Color.FromArgb(255, (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256))), Index = this.items.IndexOf(item) }; this.ItemsToShow.Add(metricItem); } } else { var data = result.Data as IList<string>; if (data != null) { var infoType = DynamicTypeManager.GetInfoType(this.Gadget.ProcessSystemName); var fields = new List<string>(); foreach (var fieldName in data) { var displayName = string.Empty; var property = infoType.GetPropertyByName(fieldName); if (property != null) { var displayAttribute = property.GetCustomAttributes(typeof(DisplayAttribute), false).Cast<DisplayAttribute>().FirstOrDefault(); if (displayAttribute != null) { displayName = displayAttribute.GetName(); } } fields.Add(!string.IsNullOrEmpty(displayName) ? displayName : fieldName); } this.RestrictedFields = string.Join(", ", fields); } } this.Busy = false; this.RaisePropertyChanged(() => this.ItemsToShow); } else if (result != null && !string.IsNullOrEmpty(result.Error)) { this.Logger.Log(LogSeverity.Error, result.GetType().ToString(), result.Error); this.ThePopupFactory.NotifyFailure(result.Error); this.Busy = false; } else if (!timer.IsEnabled) { timer.Start(); } }
public void Increment(MetricItem item, long amount) { }
/// <inheritdoc /> public void Increment(MetricItem item) { Increment(item.ToString()); }
public void Mark(MetricItem item) { }
/// <inheritdoc /> public void Decrement(MetricItem item) { Decrement(item.ToString()); }
/// <inheritdoc /> public void Mark(MetricItem item, long amount) { Mark(item.ToString(), amount); }
/// <inheritdoc /> public void Decrement(MetricItem item, long amount) { Decrement(item.ToString(), amount); }