protected override void OnStart(ActorSystem actorSystem) { base.OnStart(actorSystem); this.telemetry.Run(); this.monitor = ActorMonitoringExtension.Monitors(actorSystem); this.monitor.RegisterMonitor(new ActorAppInsightsMonitor(this.telemetry.CreateTelemetryClient())); }
static void Main(string[] args) { _system = ActorSystem.Create("akka-performance-demo"); var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(_system, new ActorPerformanceCountersMonitor( new CustomMetrics { Counters = { "akka.custom.metric1", "akka.custom.metric2" }, Gauges = { "akka.messageboxsize" }, Timers = { "akka.handlertime" } })); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); for (int i = 0; i < 11; i++) { _system.ActorOf <HelloActor>(); } _system.ActorOf <WorkerActor>(); if (registeredMonitor) { Console.WriteLine("Successfully registered Performance Counters monitor"); } else { Console.WriteLine("Failed to register Performance Counters monitor"); } Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(2000); count--; } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
protected override void OnStart(ActorSystem actorSystem) { base.OnStart(actorSystem); var instrumentationKey = this.Config.Get <AppSettings>().ApplicationInsights.InstrumentationKey; Log.Info($"AppInsights key is {instrumentationKey}"); if (!string.IsNullOrWhiteSpace(instrumentationKey)) { this.monitor = ActorMonitoringExtension.Monitors(actorSystem); this.monitor.RegisterMonitor(new ActorAppInsightsMonitor(instrumentationKey)); } }
static void Main(string[] args) { _system = ActorSystem.Create("akka-performance-demo"); var registeredMonitor = ActorMonitoringExtension.RegisterMonitor( _system, new ActorAppInsightsMonitor( "<INSERT YOUR KEY>", true)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); var goodbye1 = _system.ActorOf <GoodbyeActor>(); var hello1 = _system.ActorOf <HelloActor>(); if (registeredMonitor) { Console.WriteLine("Successfully registered AppInsights monitor"); } else { Console.WriteLine("Failed to register AppInsights monitor"); } Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(100); count--; } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); goodbye1.Tell(new Tuple <IActorRef, string>(hello1, "Start")); Thread.Sleep(5000); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
static void Main(string[] args) { _system = ActorSystem.Create("akka-datadog-demo"); var statsdConfig = new StatsdConfig { StatsdServerName = "127.0.0.1" }; var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(_system, new ActorDatadogMonitor(statsdConfig)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); Console.WriteLine(registeredMonitor ? "Successfully registered StatsD monitor" : "Failed to register StatsD monitor"); Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); for (var i = 0; i < 20; i++) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(10); } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Terminate(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
static void Main(string[] args) { using (system = ActorSystem.Create("akka-performance-demo")) { var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(system, new Monitor()); IWindsorContainer container = new WindsorContainer(); container.Register(Component.For <IInterceptor>(). ImplementedBy <MonitorInterceptor>(). Named("monitorInterceptor"), Component.For <HelloActor>(). LifestyleTransient(). Interceptors(InterceptorReference.ForKey("monitorInterceptor")). Anywhere); WindsorDependencyResolver propsResolver = new WindsorDependencyResolver(container, system); var hello = system.ActorOf(propsResolver.Create <HelloActor>(), "Worker1"); hello.Tell("What's Up"); hello.Tell("Goodbye"); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(100); count--; } while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); MetricServer metricServer = null; var appConfig = app.ApplicationServices.GetService <AppSettings>(); AppSettings = appConfig; //APP Life Cycle lifetime.ApplicationStarted.Register(() => { app.ApplicationServices.GetService <ILogger>(); var actorSystem = app.ApplicationServices.GetService <ActorSystem>(); // start Akka.NET ActorSystem = actorSystem; //싱글톤 클러스터 액터 actorSystem.BootstrapSingleton <SingleToneActor>("SingleToneActor", "akkanet"); var singleToneActor = actorSystem.BootstrapSingletonProxy("SingleToneActor", "akkanet", "/user/SingleToneActor", "singleToneActorProxy"); AkkaLoad.RegisterActor("SingleToneActor", singleToneActor); // ########### 로드 테스트 전용 // 클러스터내 싱글톤은 하나만 존재할수있음 : akka.cluster.singleton - akka.conf참고 //액터 선택 : AkkaLoad.ActorSelect("ClusterWorkerPoolActor") var worker = AkkaLoad.RegisterActor( "ClusterWorkerPoolActor", actorSystem.ActorOf(Props.Create <ClusterWorkerPoolActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "cluster-workerpool" )); //커멘드 액터( 로드테스트용) //액터생성 AkkaLoad.RegisterActor( "TPSCommandActor", actorSystem.ActorOf(Props.Create <TPSCommandActor>(worker), "TPSCommandActor" )); // ########### 로드 테스트 전용 //액터생성 AkkaLoad.RegisterActor( "basic", actorSystem.ActorOf(Props.Create <BasicActor>(), "basic" )); // DI 연동 AkkaLoad.RegisterActor( "toner", actorSystem.ActorOf(actorSystem.DI().Props <TonerActor>() .WithRouter(new RoundRobinPool(1)), "toner" )); AkkaLoad.RegisterActor( "printer", actorSystem.ActorOf(actorSystem.DI().Props <PrinterActor>() .WithDispatcher("custom-dispatcher") .WithRouter(FromConfig.Instance).WithDispatcher("custom-task-dispatcher"), "printer-pool" )); // DI 미연동 AkkaLoad.RegisterActor( "highpass", actorSystem.ActorOf(Props.Create <HighPassGateActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "highpass-gate-pool" )); AkkaLoad.RegisterActor( "cashpass", actorSystem.ActorOf(Props.Create <CashGateActor>() .WithDispatcher("slow-dispatcher") .WithRouter(FromConfig.Instance), "cashpass-gate-pool" )); AkkaLoad.RegisterActor( "clusterRoundRobin", actorSystem.ActorOf(Props.Create <ClusterPoolActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "cluster-roundrobin" )); // 스트림 - 밸브조절액터 int timeSec = 1; var throttleActor = AkkaLoad.RegisterActor( "throttleActor", actorSystem.ActorOf(Props.Create <ThrottleActor>(timeSec) )); var throttleWork = actorSystem.ActorOf(Props.Create <ThrottleWork>(5, 1)); throttleActor.Tell(new SetTarget(throttleWork)); try { var MonitorTool = Environment.GetEnvironmentVariable("MonitorTool"); var MonitorToolCon = Environment.GetEnvironmentVariable("MonitorToolCon"); var MonitorToolCons = MonitorToolCon.Split(":"); string StatsdServerName = MonitorToolCons[0]; int StatsdPort = 8125; if (MonitorToolCons.Length > 1 && 10 > MonitorToolCons.Length) { StatsdPort = int.Parse(MonitorToolCons[1]); } switch (MonitorTool) { case "win": var win = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorPerformanceCountersMonitor( new CustomMetrics { Counters = { "akka.custom.metric1", "akka.custom.metric2", "akka.custom.metric3", "akka.custom.received1", "akka.custom.received2" }, Gauges = { "akka.gauge.msg10", "akka.gauge.msg100", "akka.gauge.msg1000", "akka.gauge.msg10000" }, Timers = { "akka.handlertime" } })); // 윈도우 성능 모니터링 수집대상항목은 최초 Admin권한으로 akka항목으로 레지스트리에 프로그램실행시 자동 등록되며 // 커스텀항목 결정및 최초 1번 작동후 변경되지 않음으로 // 수집 항목 변경시 아래 Register 삭제후 다시 최초 Admin권한으로 작동 // Actor명으로 매트릭스가 분류됨으로 기능단위의 네이밍이 권장됨 // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Akka\Performance break; case "azure": var azure = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorAppInsightsMonitor(appConfig.MonitorToolCon)); break; case "prometheus": // prometheusMonotor 를 사용하기위해서, MerticServer를 켠다...(수집형 모니터) // http://localhost:10250/metrics metricServer = new MetricServer(10250); metricServer.Start(); var prometheus = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorPrometheusMonitor(actorSystem)); break; case "datadog": var statsdConfig = new StatsdConfig { StatsdServerName = StatsdServerName, StatsdPort = StatsdPort }; var dataDog = ActorMonitoringExtension. RegisterMonitor(actorSystem, new ActorDatadogMonitor(statsdConfig)); break; } } catch (Exception e) { Console.WriteLine("=============== Not Suport Window Monitor Tools ==============="); } ActorMonitoringExtension.Monitors(actorSystem).IncrementDebugsLogged(); }); lifetime.ApplicationStopping.Register(() => { Console.WriteLine("=============== Start Graceful Down ==============="); var actorSystem = app.ApplicationServices.GetService <ActorSystem>(); if (appConfig.MonitorTool == "prometheus") { metricServer.Stop(); } // Graceful Down Test,Using CashGateActor Actor AkkaLoad.ActorSelect("cashpass").Ask(new StopActor()).Wait(); var cluster = Akka.Cluster.Cluster.Get(actorSystem); cluster.RegisterOnMemberRemoved(() => MemberRemoved(actorSystem)); cluster.Leave(cluster.SelfAddress); asTerminatedEvent.WaitOne(); Console.WriteLine($"=============== Completed Graceful Down : {cluster.SelfAddress} ==============="); }); }