-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a few default values to variables.
Updated Telemetry to QueueBackgroundWorkItem to improve user experience. Telemetry sends additional info, sends as json instead of CSV, but still anonymous data.
- Loading branch information
1 parent
7e0c2d4
commit 508c6fa
Showing
11 changed files
with
193 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
Imports System.Web.Hosting | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports System.Web.Script.Serialization | ||
|
||
Class Telemetry | ||
|
||
Private Metrics As New Dictionary(Of String, Object) | ||
|
||
Public Sub Add(key As String, value As Object) | ||
If Metrics.Keys.Contains(key) Then | ||
Metrics(key) = value 'update | ||
Else | ||
Metrics.Add(key, value) 'add | ||
End If | ||
|
||
End Sub | ||
|
||
Public Sub Clear(key As String) | ||
Metrics.Clear() | ||
End Sub | ||
Public Sub Remove(key As String) | ||
If Metrics.Keys.Contains(key) Then | ||
Metrics.Remove(key) | ||
End If | ||
End Sub | ||
Public Sub SendTelemetry() | ||
dlog.Trace("SendTelemetry") | ||
'sends whatever telemetry we have | ||
Dim cts As New CancellationTokenSource | ||
HostingEnvironment.QueueBackgroundWorkItem(Sub() AddMetricsAndSendTelemetry()) | ||
|
||
End Sub | ||
|
||
Public Sub AddIDs(DomainSid As String, DomainDNSRoot As String, ScriptID As String, UserID As String, Optional Permitted As Boolean = True) | ||
|
||
Dim oid As String = StringHash256(DomainSid & ";" & DomainDNSRoot.ToUpper()) | ||
Add("orgid", oid) | ||
Add("scriptid", StringHash256(oid & ";" & ScriptID.ToUpper())) | ||
Add("userid", StringHash256(oid & ";" & UserID.ToUpper())) | ||
Add("permitted", Permitted) | ||
|
||
End Sub | ||
|
||
Public Sub AddRuntime(SecondsRuntime As Single, Optional isOnload As Boolean = False) | ||
|
||
Dim RuntimeName = "runtimesec" | ||
If isOnload Then RuntimeName = "runtimesecOnload" | ||
Add(RuntimeName, (Math.Ceiling(SecondsRuntime * 10D) / 10D).ToString()) 'round up to 1 decimal | ||
|
||
End Sub | ||
|
||
Private Sub AddMetricsAndSendTelemetry() | ||
AddSystemMetrics() | ||
AddTimeMetrics() | ||
SubmitToAWSQueue(Metrics) | ||
|
||
End Sub | ||
|
||
Private Sub SubmitToAWSQueue(dictobj As Dictionary(Of String, Object)) | ||
Dim msg As String = ToJSON(dictobj) | ||
|
||
SubmitToAWSQueue(msg) | ||
End Sub | ||
|
||
Private Sub SubmitToAWSQueue(msg As String) | ||
If globalSettings(globalKeys.aws_enabled) = False Then Return 'disable in code | ||
|
||
Try | ||
'Dim cred As Amazon.Runtime.AWSCredentials = New Amazon.Runtime.AnonymousAWSCredentials | ||
dlog.Info("Sending Telemetry: " + msg) | ||
Dim cred As Amazon.Runtime.AWSCredentials = New Amazon.Runtime.BasicAWSCredentials(globalSettings(globalKeys.aws_key), globalSettings(globalKeys.aws_keysec)) | ||
|
||
Dim conf As New Amazon.SQS.AmazonSQSConfig | ||
conf.Timeout = New TimeSpan(0, 0, 5) | ||
conf.ServiceURL = globalSettings(globalKeys.aws_serviceUrl) | ||
|
||
Dim client As New Amazon.SQS.AmazonSQSClient(cred, conf) | ||
|
||
Dim req As New Amazon.SQS.Model.SendMessageRequest | ||
req.QueueUrl = globalSettings(globalKeys.aws_queueUrl) | ||
req.MessageBody = msg | ||
|
||
Dim resp As Amazon.SQS.Model.SendMessageResponse = client.SendMessage(req) | ||
Catch | ||
'if it errors, do nothing | ||
End Try | ||
|
||
|
||
|
||
End Sub | ||
|
||
Private Function ToJSON(obj As Object) As String | ||
|
||
Dim serializer As New JavaScriptSerializer() | ||
serializer.RecursionLimit = 2 | ||
Return serializer.Serialize(obj) | ||
|
||
End Function | ||
|
||
Private Sub AddTimeMetrics() | ||
|
||
Dim wints As DateTime = DateTime.UtcNow | ||
Dim ts As Integer = (wints - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds | ||
Dim version As String = "2" 'version of string format | ||
|
||
Add("wints", wints.ToString("yyyy-MM-dd hh:mm:ss")) | ||
Add("unixts", ts) | ||
Add("version", version) | ||
|
||
End Sub | ||
|
||
|
||
Private Sub AddSystemMetrics() | ||
|
||
Add("CPUCount", Environment.ProcessorCount) 'cpu count | ||
Dim mgmtobjs As System.Management.ManagementObjectCollection = New System.Management.ManagementObjectSearcher("Select MaxClockSpeed from Win32_Processor").Get() | ||
For Each mgmtobj In mgmtobjs | ||
Add("CPUMhz", mgmtobj("maxclockspeed")) | ||
Next | ||
Add("OS", My.Computer.Info.OSFullName) 'os details | ||
Add("RAM", Math.Round(My.Computer.Info.TotalPhysicalMemory / 1024 / 1024 / 1024, 1)) 'GB ram | ||
|
||
|
||
End Sub | ||
|
||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.