private static IEventStoreConnection CreateEventStoreConnection(Serilog.ILogger logger, string connectionString, string connectionName) { var connectionSettings = ConnectionSettings.Create() .KeepReconnecting() .SetReconnectionDelayTo(TimeSpan.FromSeconds(3)) .KeepRetrying() .PerformOnAnyNode() .PreferRandomNode() .UseCustomLogger(new SerilogEventStoreLogger(logger)); var connection = EventStoreConnection .Create(connectionString, connectionSettings, connectionName); connection .Connected += (sender, args) => logger.Information("Connected to Event Store {ConnectionName}", connectionName); connection.Closed += (sender, args) => logger.Information("Connection to Event Store {ConnectionName} closed", connectionName); connection.Reconnecting += (sender, args) => logger.Information("Attempting to connect to Event Store {ConnectionName}", connectionName); connection.ConnectAsync().GetAwaiter().GetResult(); return(connection); }
public void ReportWritesProgress(int threadId, int sent, int prepareTimeouts, int commitTimeouts, int forwardTimeouts, int wrongExpctdVersions, int streamsDeleted, int fails, int requests) { var sentP = ToPercent(sent, requests); var failsP = ToPercent(fails, sent); var table = new ConsoleTable("WRITER ID", "Completed %", "Completed/Total", "Failed %", "Failed/Sent", "Prepare Timeouts", "Commit Timeouts", "Forward Timeouts", "Wrong Versions", "Stream Deleted"); table.AppendRow(threadId.ToString(), string.Format("{0:0.0}%", sentP), string.Format("{0}/{1}", sent, requests), string.Format("{0:0.0}%", failsP), string.Format("{0}/{1}", fails, sent), prepareTimeouts.ToString(), commitTimeouts.ToString(), forwardTimeouts.ToString(), wrongExpctdVersions.ToString(), streamsDeleted.ToString()); if (failsP > 50d) { _log.Fatal(table.CreateIndentedTable()); } else { _log.Information(table.CreateIndentedTable()); } }
public void Info(string format, params object[] args) { if (args.Length == 0) { _log.Information(format); } else { _log.Information(format, args); } }
private async Task OnReadEvent(IStreamSubscription arg1, ResolvedEvent arg2, CancellationToken t) { var eventData = Encoding.UTF8.GetString(arg2.Event.Data); var metaData = Encoding.UTF8.GetString(arg2.Event.Metadata); var ev = JsonConvert.DeserializeObject <TEvent>(eventData); var m = JsonConvert.DeserializeObject <EventMetadata>(metaData); _logger.Information("EventDispatcher is receiving {eventName}.", typeof(TEvent).Name); await _dispatcher.Dispatch(m, ev); }
public async Task Configure(IEventStoreFacade connection, IEventHandlerDispatcher dispatcher, Serilog.ILogger logger) { _logger = logger; _logger.Information("Subscribed for {eventName} for local projections. (with EventDispatcher)", typeof(TEvent).Name); var stream = $"$et-{typeof(TEvent).Name}"; this._dispatcher = dispatcher; // Should we wait for the subscription? - or should we re-subscribe await connection.SubscribeToStreamAsync(stream, OnReadEvent, true); }
internal static DiskIo ParseOnUnix(string procIoStr, Serilog.ILogger log) { ulong readBytes, writtenBytes, readOps, writeOps; try { var dict = procIoStr.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Split(':')) .ToDictionary(s => s[0].Trim(), s => s[1].Trim()); readBytes = ulong.Parse(dict["read_bytes"]); writtenBytes = ulong.Parse(dict["write_bytes"]); readOps = ulong.Parse(dict["syscr"]); writeOps = ulong.Parse(dict["syscw"]); } catch (Exception ex) { log.Information(ex, "Could not parse Linux stats."); return(null); } return(new DiskIo(readBytes, writtenBytes, readOps, writeOps)); }
public void Handle(CoreProjectionProcessingMessage.RestartRequested message) { _logger.Information( "Projection '{projection}'({projectionCorrelationId}) restart has been requested due to: '{reason}'", _name, _projectionCorrelationId, message.Reason); if (_state != State.Running) { SetFaulted( string.Format( "A concurrency violation was detected, but the projection is not running. Current state is: {0}. The reason for the restart is: '{1}' ", _state, message.Reason)); return; } CompleteCheckpointSuggestedWorkItem(); EnsureUnsubscribed(); GoToState(State.Initial); Start(); }
private void GetPerfCounterInformation(Dictionary <string, object> stats, int count) { if (_giveup) { return; } var process = Process.GetCurrentProcess(); try { stats["proc-startTime"] = process.StartTime.ToUniversalTime().ToString("O"); stats["proc-id"] = process.Id; stats["proc-mem"] = new StatMetadata(process.WorkingSet64, "Process", "Process Virtual Memory"); stats["proc-cpu"] = new StatMetadata(_eventCountersHelper.GetProcCpuUsage(), "Process", "Process Cpu Usage"); stats["proc-threadsCount"] = _eventCountersHelper.GetProcThreadsCount(); stats["proc-contentionsRate"] = _eventCountersHelper.GetContentionsRateCount(); stats["proc-thrownExceptionsRate"] = _eventCountersHelper.GetThrownExceptionsRate(); switch (OS.OsFlavor) { case OsFlavor.Windows: stats["sys-cpu"] = _perfCounter.GetTotalCpuUsage(); break; case OsFlavor.Linux: case OsFlavor.MacOS: var loadAverages = _hostStat.GetLoadAverages(); stats["sys-loadavg-1m"] = loadAverages.Average1m; stats["sys-loadavg-5m"] = loadAverages.Average5m; stats["sys-loadavg-15m"] = loadAverages.Average15m; break; default: stats["sys-cpu"] = -1; break; } stats["sys-freeMem"] = GetFreeMem(); var gcStats = _eventCountersHelper.GetGcStats(); stats["proc-gc-allocationSpeed"] = gcStats.AllocationSpeed; stats["proc-gc-gen0ItemsCount"] = gcStats.Gen0ItemsCount; stats["proc-gc-gen0Size"] = gcStats.Gen0Size; stats["proc-gc-gen1ItemsCount"] = gcStats.Gen1ItemsCount; stats["proc-gc-gen1Size"] = gcStats.Gen1Size; stats["proc-gc-gen2ItemsCount"] = gcStats.Gen2ItemsCount; stats["proc-gc-gen2Size"] = gcStats.Gen2Size; stats["proc-gc-largeHeapSize"] = gcStats.LargeHeapSize; stats["proc-gc-timeInGc"] = gcStats.TimeInGc; stats["proc-gc-totalBytesInHeaps"] = gcStats.TotalBytesInHeaps; } catch (InvalidOperationException) { _log.Information("Received error reading counters. Attempting to rebuild."); _perfCounter = new PerfCounterHelper(_log); _giveup = count > 10; if (_giveup) { _log.Error("Maximum rebuild attempts reached. Giving up on rebuilds."); } else { GetPerfCounterInformation(stats, count + 1); } } }
public bool TryProcess(CommandProcessorContext context, string[] args, out int exitCode) { var commandName = args[0].ToUpper(); var commandArgs = args.Skip(1).ToArray(); ICmdProcessor commandProcessor; if (!_processors.TryGetValue(commandName, out commandProcessor)) { _log.Information("Unknown command: {command}.", commandName); if (_regCommandsProcessor != null) { _regCommandsProcessor.Execute(context, new string[0]); } exitCode = 1; return(false); } int exitC = 0; var executedEvent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(_ => { try { var syntaxOk = commandProcessor.Execute(context, commandArgs); if (syntaxOk) { exitC = context.ExitCode; } else { exitC = 1; _log.Information("Usage of {command}:{newLine}{usage}", commandName, Environment.NewLine, commandProcessor.Usage); } executedEvent.Set(); } catch (Exception exc) { _log.Error(exc, "Error while executing command {command}.", commandName); exitC = -1; executedEvent.Set(); } }); executedEvent.WaitOne(1000); context.WaitForCompletion(); if (!string.IsNullOrWhiteSpace(context.Reason)) { _log.Error("Error during execution of command: {e}.", context.Reason); } if (context.Error != null) { _log.Error(context.Error, "Error during execution of command"); var details = new StringBuilder(); BuildFullException(context.Error, details); _log.Error("Details: {details}", details.ToString()); } exitCode = exitC == 0 ? context.ExitCode : exitC; return(true); }