/// <summary> /// Write the current round of stats to the log /// </summary> /// <param name="log">The logger to write to</param> public void WriteStatsToFile(ILogger log) { try { var statsContainer = new StatsContainer(); statsContainer.Add(GetStats()); var rawStats = statsContainer.GetStats(useGrouping: false, useMetadata: false); if (!_csv) { rawStats.Add("timestamp", DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)); log.Information("{@stats}", rawStats); } else { var writeHeader = false; var header = StatsCsvEncoder.GetHeader(rawStats); if (header != _lastWrittenCsvHeader) { _lastWrittenCsvHeader = header; writeHeader = true; } var line = StatsCsvEncoder.GetLine(rawStats); var timestamp = GetTimestamp(line); if (writeHeader) { log.Information(Environment.NewLine); log.Information(header); } log.Information(line); } } catch (Exception ex) { Log.Error(ex, "Error on regular stats collection."); } }
public void ReplyWith <T>(T message) where T : Message { var msg = message as MonitoringMessage.InternalStatsRequestResponse; if (msg != null) { _statsContainer.Add(msg.Stats); } }
private StatsContainer CollectStats() { var statsContainer = new StatsContainer(); try { statsContainer.Add(_systemStats.GetSystemStats()); _statsCollectionBus.Publish( new MonitoringMessage.InternalStatsRequest(new StatsCollectorEnvelope(statsContainer))); } catch (Exception ex) { Log.ErrorException(ex, "Error while collecting stats"); statsContainer = null; } return(statsContainer); }