/// <summary> /// Performs all of the initialization to get the PCF metrics forwarding engine up and running. /// </summary> /// <param name="settings">The options and settings needed to communicate with PCF.</param> /// <param name="system">Optional. An <see cref="ActorSystem" /> used to spawn the underlying actors needed to do the job.</param> /// <returns>A new <see cref="PcfMetricRecorder" /> instance.</returns> public static PcfMetricRecorder Create(PcfMetricForwarderSettings settings, ActorSystem system = null) { var weOwnActorSystem = false; if (system == null) // create our own ActorSystem if it doesn't already exist. { weOwnActorSystem = true; system = ActorSystem.Create("pbpcfmetrics", settings.DebugLogging ? DebugHocon : NormalHocon); } // spawn as a System actor, so in the event of being in a non-owned system our traces get shut down // only after all of the user-defined actors have terminated. var reporterActor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf( Props.Create(() => new MetricsReporterActor(settings)), $"pcf-reporter-{NameCounter.GetAndIncrement()}"); var counterActor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf( Props.Create(() => new CounterAggregator(reporterActor, settings.TimeProvider ?? new DateTimeOffsetTimeProvider())), $"pcf-reporter-{NameCounter.GetAndIncrement()}"); return(new PcfMetricRecorder(reporterActor, counterActor, weOwnActorSystem ? system : null)); }
internal PcfMetricRecorder(PcfMetricForwarderSettings settings, IActorRef reporterActorRef, IActorRef counterAggregatorRef, ActorSystem ownedActorSystem = null) { Settings = settings; _reporterActorRef = reporterActorRef; _counterAggregatorRef = counterAggregatorRef; _ownedActorSystem = ownedActorSystem; TimeProvider = Settings.TimeProvider ?? new DateTimeOffsetTimeProvider(); }
/// <summary> /// Creates a new metric recorder using the values provided in <see cref="PcfEnvironment" /> /// </summary> internal PcfMetricRecorder(IActorRef reporterActorRef, IActorRef counterAggregatorRef, ActorSystem ownedActorSystem) : this(PcfMetricForwarderSettings.FromEnvironment(), reporterActorRef, counterAggregatorRef, ownedActorSystem) { }
/// <summary> /// Performs all of the initialization to get the PCF metrics forwarding engine up and running. /// </summary> /// <param name="system">Optional. An <see cref="ActorSystem" /> used to spawn the underlying actors needed to do the job.</param> /// <returns>A new <see cref="PcfMetricRecorder" /> instance.</returns> public static PcfMetricRecorder Create(ActorSystem system = null) { return(Create(PcfMetricForwarderSettings.FromEnvironment(), system)); }