public async Task <string> AddObserverAsync(TimeSpan lifetime, IMetricObserver observer) { try { _ = observer ?? throw new ArgumentNullException(nameof(observer)); string leaseKey = Guid.NewGuid().ToString(); State.MetricLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Metric")); leaseTimer ??= RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); await WriteStateAsync(); return(await Task.FromResult(leaseKey)); } catch (Exception ex) { await logger?.LogErrorAsync(ex, "Subscription add metric observer."); await NotifyErrorAsync(ex); throw; } }
/// <summary> /// Adds a metric observer to the subscription. Used to observe metrics in the subscription. /// </summary> /// <param name="subscriptionUriString">Unique URI that identifies the subscription.</param> /// <param name="lifetime">Lifetime of the lease.</param> /// <param name="observer">Observer to receive events.</param> /// <returns>A unqiue string for the lease key, which is used to renew or delete the observer's lease.</returns> public async Task <string> AddSubscriptionObserverAsync(string subscriptionUriString, TimeSpan lifetime, MetricObserver observer) { IMetricObserver observerRef = await client.CreateObjectReference <IMetricObserver>(observer); ISubscription subscription = GetSubscription(subscriptionUriString); return(await subscription.AddObserverAsync(lifetime, observerRef)); }
/// <summary> /// Adds a metric observer to a resource. /// </summary> /// <param name="resourceUriString">Unique URI that identifies the resource.</param> /// <param name="lifetime">The lifetime of the lease.</param> /// <param name="observer">Metric observer to receive events.</param> /// <returns>A unique string for the lease key, which is used to refresh the lease for the observer.</returns> public async Task <string> AddResourceObserverAsync(string resourceUriString, TimeSpan lifetime, MetricObserver observer) { IMetricObserver objRef = await client.CreateObjectReference <IMetricObserver>(observer); IPiSystem resource = GetPiSystem(resourceUriString); return(await resource.AddObserverAsync(lifetime, objRef)); }
public static void Main(string[] args) { // Get the default registry instance. This is the registry used when adding metrics // through OkanshiMonitor. var registry = DefaultMonitorRegistry.Instance; // Create a new poller to get data from the registry every 10 seconds poller = new MetricMonitorRegistryPoller(registry, TimeSpan.FromSeconds(10), false); observer = new ConsoleObserver(poller, x => JsonConvert.SerializeObject(x, Formatting.Indented)); // Start the actual program Start(); }
public async Task <string> AddObserverAsync(TimeSpan lifetime, IMetricObserver observer) { if (observer == null) { Exception ex = new ArgumentNullException("resource metric observer"); await NotifyErrorAsync(ex); return(await Task.FromResult <string>(null)); } Exception error = null; string leaseKey = null; try { leaseKey = Guid.NewGuid().ToString(); State.MetricLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Metric")); if (leaseTimer == null) { leaseTimer = RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); } } catch (Exception ex) { error = ex; //GetLogger().Log(1001, Orleans.Runtime.Severity.Error, "Resource add metric observer {0}", new object[] { State.Metadata.ResourceUriString }, ex); } if (error != null) { await NotifyErrorAsync(error); } return(await Task.FromResult <string>(leaseKey)); }
public async Task <string> AddObserverAsync(TimeSpan lifetime, IMetricObserver observer) { if (observer == null) { Exception ex = new ArgumentNullException("subscription metric observer"); await NotifyErrorAsync(ex); return(await Task.FromResult <string>(null)); } string leaseKey = Guid.NewGuid().ToString(); State.MetricLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Metric")); if (leaseTimer == null) { leaseTimer = RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); } await WriteStateAsync(); return(await Task.FromResult <string>(leaseKey)); }