aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Insights
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-23 08:44:31 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-23 08:44:31 +0300
commit02ae577faa0bd4938507061d603e4f9447e2b64f (patch)
tree7daf0e275338ec92e93bfca39f2d529d93858162 /Software/Visual_Studio/Tango.Insights
parent67770063ff1a1c5c522e3bc29f442c42eb6dc521 (diff)
downloadTango-02ae577faa0bd4938507061d603e4f9447e2b64f.tar.gz
Tango-02ae577faa0bd4938507061d603e4f9447e2b64f.zip
Fixed issue with insights file datetime utc.
added insights application exception/crash. added remote actions service. fixed issue with LiteDB hang on application start/exit. reduced insights listener empty frames.
Diffstat (limited to 'Software/Visual_Studio/Tango.Insights')
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsApplicationException.cs20
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsFile.cs17
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsListener.cs19
-rw-r--r--Software/Visual_Studio/Tango.Insights/InsightsManager.cs42
-rw-r--r--Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj1
5 files changed, 89 insertions, 10 deletions
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsApplicationException.cs b/Software/Visual_Studio/Tango.Insights/InsightsApplicationException.cs
new file mode 100644
index 000000000..193412ae8
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Insights/InsightsApplicationException.cs
@@ -0,0 +1,20 @@
+using LiteDB;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Insights
+{
+ public class InsightsApplicationException
+ {
+ [BsonId(true)]
+ [JsonIgnore]
+ public int Id { get; set; }
+ public DateTime Time { get; set; }
+ public String Exception { get; set; }
+ public bool IsApplicationCrash { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
index 4eba06035..2bcb2f761 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsFile.cs
@@ -6,22 +6,33 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.Core.Bson;
namespace Tango.Insights
{
public class InsightsFile
{
+ private static JsonSerializer _serializer;
+
+ static InsightsFile()
+ {
+ _serializer = new BsonUtcSerializer();
+ }
+
public List<InsightsFrame> Frames { get; set; }
public List<InsightsEvent> Events { get; set; }
public List<InsightsStatus> Statuses { get; set; }
+ public List<InsightsApplicationException> ApplicationExceptions { get; set; }
+
public InsightsFile()
{
Frames = new List<InsightsFrame>();
Events = new List<InsightsEvent>();
Statuses = new List<InsightsStatus>();
+ ApplicationExceptions = new List<InsightsApplicationException>();
}
public Stream ToStream()
@@ -35,8 +46,7 @@ namespace Tango.Insights
{
using (BsonWriter writer = new BsonWriter(ms))
{
- JsonSerializer serializer = new JsonSerializer();
- serializer.Serialize(writer, this);
+ _serializer.Serialize(writer, this);
ms.Position = 0;
return ms.ToArray();
}
@@ -52,8 +62,7 @@ namespace Tango.Insights
{
using (BsonReader reader = new BsonReader(stream))
{
- JsonSerializer serializer = new JsonSerializer();
- return serializer.Deserialize<InsightsFile>(reader);
+ return _serializer.Deserialize<InsightsFile>(reader);
}
}
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
index 6a9e7726b..f57753cfc 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsListener.cs
@@ -25,6 +25,7 @@ namespace Tango.Insights
private int _timerCount;
private int _deleteTicks;
private bool _writing;
+ private bool _emptyWritten;
public bool IsStarted { get; private set; }
public TimeSpan SamplingInterval { get; set; }
@@ -164,16 +165,21 @@ namespace Tango.Insights
queue.Clear();
frame = InsightsFrame.FromInsightsMonitors(monitorsAvg, DateTime.UtcNow.Subtract(SamplingInterval));
+ _emptyWritten = false;
+ _manager.InsertFrame(frame);
+ Debug.WriteLine("Insights frame inserted.");
}
else
{
- frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(SamplingInterval));
+ if (!_emptyWritten)
+ {
+ frame = InsightsFrame.CreateEmpty(DateTime.UtcNow.Subtract(SamplingInterval));
+ _emptyWritten = true;
+ _manager.InsertFrame(frame);
+ Debug.WriteLine("Insights empty frame inserted.");
+ }
}
- _manager.InsertFrame(frame);
-
- Debug.WriteLine("Insights frame inserted.");
-
_timerCount++;
if (_timerCount >= _deleteTicks)
@@ -185,6 +191,9 @@ namespace Tango.Insights
deleted = _manager.DeleteStatuses(maxDate);
Debug.WriteLine($"{deleted} insights machine statuses deleted.");
+
+ deleted = _manager.DeleteApplicationExceptions(maxDate);
+ Debug.WriteLine($"{deleted} insights application exceptions deleted.");
}
}
catch (Exception ex)
diff --git a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
index 73b74bff6..b187279b4 100644
--- a/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
+++ b/Software/Visual_Studio/Tango.Insights/InsightsManager.cs
@@ -15,6 +15,9 @@ namespace Tango.Insights
{
private const string INSIGHTS_COLLECTION = "Insights";
private const string STATUSES_COLLECTION = "Statuses";
+ private const string APPLICATION_EXCEPTIONS_COLLECTION = "ApplicationExceptions";
+
+ private bool _disposed;
private static InsightsManager _instance;
public static InsightsManager Default
@@ -39,6 +42,9 @@ namespace Tango.Insights
DatabasePath = databasePath;
Directory.CreateDirectory(Path.GetDirectoryName(DatabasePath));
_database = new LiteDatabase($"Filename={DatabasePath}");
+ _database.Pragma("TIMEOUT", 10); //Read Timeout
+ _database.Pragma("UTC_DATE", true); //Keep time as UTC when getting data
+ _database.Commit();
}
public virtual void Dispose()
@@ -47,6 +53,7 @@ namespace Tango.Insights
{
try
{
+ _disposed = true;
_database.Dispose();
_database = null;
}
@@ -69,18 +76,34 @@ namespace Tango.Insights
return _database.GetCollection<InsightsStatus>(STATUSES_COLLECTION);
}
+ private ILiteCollection<InsightsApplicationException> GetApplicationExceptionsCollection()
+ {
+ return _database.GetCollection<InsightsApplicationException>(APPLICATION_EXCEPTIONS_COLLECTION);
+ }
+
public virtual void InsertFrame(InsightsFrame frame)
{
+ if (_disposed) return;
+
var collection = GetInsightsCollection();
collection.Insert(frame);
}
public virtual void InsertStatus(InsightsStatus status)
{
+ if (_disposed) return;
var collection = GetStatusesCollection();
collection.Insert(status);
}
+ public virtual void InsertApplicationException(InsightsApplicationException appException)
+ {
+ if (_disposed) return;
+ var collection = GetApplicationExceptionsCollection();
+ appException.Time = appException.Time.Subtract(TimeSpan.FromSeconds(30));
+ collection.Insert(appException);
+ }
+
public virtual List<InsightsFrame> GetFrames(DateTime startUTC, DateTime endUTC)
{
var collection = GetInsightsCollection();
@@ -93,20 +116,36 @@ namespace Tango.Insights
return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList().OrderBy(x => x.Time).ToList();
}
+ public virtual List<InsightsApplicationException> GetApplicationExceptions(DateTime startUTC, DateTime endUTC)
+ {
+ var collection = GetApplicationExceptionsCollection();
+ return collection.Find(x => x.Time >= startUTC && x.Time <= endUTC).ToList().OrderBy(x => x.Time).ToList();
+ }
+
public virtual int DeleteFrames(DateTime maxDateUTC)
{
+ if (_disposed) return 0;
var collection = GetInsightsCollection();
return collection.DeleteMany(x => x.Time < maxDateUTC);
}
public virtual int DeleteStatuses(DateTime maxDateUTC)
{
+ if (_disposed) return 0;
var collection = GetStatusesCollection();
return collection.DeleteMany(x => x.Time < maxDateUTC);
}
+ public virtual int DeleteApplicationExceptions(DateTime maxDateUTC)
+ {
+ if (_disposed) return 0;
+ var collection = GetApplicationExceptionsCollection();
+ return collection.DeleteMany(x => x.Time < maxDateUTC);
+ }
+
public DateTime? GetFramesMinDate()
{
+ if (_disposed) return null;
var collection = GetInsightsCollection();
if (collection.Count() > 0)
@@ -133,9 +172,10 @@ namespace Tango.Insights
Description = x.Description
})
.ToList()
+ .Where(x => (EventTypes)x.EventCode != EventTypes.APPLICATION_EXCEPTION)
.Select(x => new InsightsEvent()
{
- Time = new DateTime(x.Time.Ticks, DateTimeKind.Utc),
+ Time = x.Time,
EventCode = x.EventCode,
Description = ((EventTypes)x.EventCode == EventTypes.JOB_FAILED ? x.Description : null)
})
diff --git a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
index 1e440a62c..ed136a8c6 100644
--- a/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
+++ b/Software/Visual_Studio/Tango.Insights/Tango.Insights.csproj
@@ -44,6 +44,7 @@
<Compile Include="..\Versioning\GlobalVersionInfo.cs">
<Link>GlobalVersionInfo.cs</Link>
</Compile>
+ <Compile Include="InsightsApplicationException.cs" />
<Compile Include="InsightsEvent.cs" />
<Compile Include="InsightsFile.cs" />
<Compile Include="InsightsHelper.cs" />