Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Datadog Reporting #41

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions onboard/DevcadeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

using Microsoft.Xna.Framework; // FIXME: Is this necessary for the client code?

Expand Down Expand Up @@ -126,11 +128,35 @@ private static void Chmod(string filePath, string permissions = "700", bool recu
notifyDownloadComplete(game);
}

public static void reportToDatadog(DevcadeGame game) {
// Create a new UdpClient
UdpClient udpClient = new UdpClient();

// Create a new IPEndPoint for the destination IP address and port number
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
MTFT-Games marked this conversation as resolved.
Show resolved Hide resolved
int port = 8125;
IPEndPoint endPoint = new IPEndPoint(ipAddress, port);

string gameName = game.name.Replace(' ', '_');
// Convert the message to a byte array
string message = $"devcade.game_launch.{gameName}:1|c";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(message);

// Send the message
udpClient.Send(bytes, bytes.Length, endPoint);

// Close the UdpClient
udpClient.Close();
}

private static void notifyDownloadComplete(DevcadeGame game) {
string gameName = game.name.Replace(' ', '_');
string path = $"/tmp/{gameName}.zip";
try {
Console.WriteLine($"Extracting {path}");
if (Directory.Exists($"/tmp/{gameName}")) {
Directory.Delete($"/tmp/{gameName}", true);
}
Directory.CreateDirectory($"/tmp/{gameName}");
ZipFile.ExtractToDirectory(path, $"/tmp/{gameName}");
} catch (Exception e) {
Expand All @@ -140,6 +166,7 @@ private static void Chmod(string filePath, string permissions = "700", bool recu
try {
string execPath = $"/tmp/{gameName}/publish/{gameName.Replace("_", " ")}";
Console.WriteLine($"Running {execPath}");
reportToDatadog(game);
Chmod(execPath, "+x");
Process proc = new() {
StartInfo = new ProcessStartInfo(execPath) {
Expand Down