diff options
author | Justin Clark-Casey (justincc) | 2014-03-19 00:28:57 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-03-19 00:28:57 +0000 |
commit | 1d0a9e521c57c95987008fd48b8a44e3a966fe54 (patch) | |
tree | 2781f34f6900fc4081931750f3011049494497e4 | |
parent | Add httpserver.<port>.QueuedPollResponses and httpserver.<port>.ProcessedPoll... (diff) | |
download | opensim-SC_OLD-1d0a9e521c57c95987008fd48b8a44e3a966fe54.zip opensim-SC_OLD-1d0a9e521c57c95987008fd48b8a44e3a966fe54.tar.gz opensim-SC_OLD-1d0a9e521c57c95987008fd48b8a44e3a966fe54.tar.bz2 opensim-SC_OLD-1d0a9e521c57c95987008fd48b8a44e3a966fe54.tar.xz |
Allow a snapshot of stats to be dumped to a file with a "stats save" command
-rw-r--r-- | OpenSim/Framework/Monitoring/StatsLogger.cs | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/OpenSim/Framework/Monitoring/StatsLogger.cs b/OpenSim/Framework/Monitoring/StatsLogger.cs index 1e4fa11..5822794 100644 --- a/OpenSim/Framework/Monitoring/StatsLogger.cs +++ b/OpenSim/Framework/Monitoring/StatsLogger.cs | |||
@@ -26,7 +26,10 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
29 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text; | ||
30 | using System.Timers; | 33 | using System.Timers; |
31 | using log4net; | 34 | using log4net; |
32 | 35 | ||
@@ -52,6 +55,15 @@ namespace OpenSim.Framework.Monitoring | |||
52 | "Control whether stats are being regularly recorded to a separate file.", | 55 | "Control whether stats are being regularly recorded to a separate file.", |
53 | "For debug purposes. Experimental.", | 56 | "For debug purposes. Experimental.", |
54 | HandleStatsRecordCommand); | 57 | HandleStatsRecordCommand); |
58 | |||
59 | console.Commands.AddCommand( | ||
60 | "General", | ||
61 | false, | ||
62 | "stats save", | ||
63 | "stats save <path>", | ||
64 | "Save stats snapshot to a file. If the file already exists, then the report is appended.", | ||
65 | "For debug purposes. Experimental.", | ||
66 | HandleStatsSaveCommand); | ||
55 | } | 67 | } |
56 | 68 | ||
57 | public static void HandleStatsRecordCommand(string module, string[] cmd) | 69 | public static void HandleStatsRecordCommand(string module, string[] cmd) |
@@ -76,6 +88,27 @@ namespace OpenSim.Framework.Monitoring | |||
76 | } | 88 | } |
77 | } | 89 | } |
78 | 90 | ||
91 | public static void HandleStatsSaveCommand(string module, string[] cmd) | ||
92 | { | ||
93 | ICommandConsole con = MainConsole.Instance; | ||
94 | |||
95 | if (cmd.Length != 3) | ||
96 | { | ||
97 | con.Output("Usage: stats save <path>"); | ||
98 | return; | ||
99 | } | ||
100 | |||
101 | string path = cmd[2]; | ||
102 | |||
103 | using (StreamWriter sw = new StreamWriter(path, true)) | ||
104 | { | ||
105 | foreach (string line in GetReport()) | ||
106 | sw.WriteLine(line); | ||
107 | } | ||
108 | |||
109 | MainConsole.Instance.OutputFormat("Stats saved to file {0}", path); | ||
110 | } | ||
111 | |||
79 | public static void Start() | 112 | public static void Start() |
80 | { | 113 | { |
81 | if (m_loggingTimer != null) | 114 | if (m_loggingTimer != null) |
@@ -97,12 +130,22 @@ namespace OpenSim.Framework.Monitoring | |||
97 | 130 | ||
98 | private static void Log(object sender, ElapsedEventArgs e) | 131 | private static void Log(object sender, ElapsedEventArgs e) |
99 | { | 132 | { |
100 | m_statsLog.InfoFormat("*** STATS REPORT AT {0} ***", DateTime.Now); | 133 | foreach (string line in GetReport()) |
134 | m_statsLog.Info(line); | ||
135 | |||
136 | m_loggingTimer.Start(); | ||
137 | } | ||
138 | |||
139 | private static List<string> GetReport() | ||
140 | { | ||
141 | List<string> lines = new List<string>(); | ||
142 | |||
143 | lines.Add(string.Format("*** STATS REPORT AT {0} ***", DateTime.Now)); | ||
101 | 144 | ||
102 | foreach (string report in StatsManager.GetAllStatsReports()) | 145 | foreach (string report in StatsManager.GetAllStatsReports()) |
103 | m_statsLog.Info(report); | 146 | lines.Add(report); |
104 | 147 | ||
105 | m_loggingTimer.Start(); | 148 | return lines; |
106 | } | 149 | } |
107 | } | 150 | } |
108 | } \ No newline at end of file | 151 | } \ No newline at end of file |