mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-10 01:59:03 +02:00
alternate stats tracker
Rust program keeps stopping for some reason
This commit is contained in:
parent
f2a0a48f0a
commit
cadaa22fe1
22
utils/ga-page-view/ga-page-view.sln
Normal file
22
utils/ga-page-view/ga-page-view.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.15
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ga-page-view", "ga-page-view\ga-page-view.csproj", "{AF43FA92-7812-40A4-839C-F9D9BEE3894F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AF43FA92-7812-40A4-839C-F9D9BEE3894F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF43FA92-7812-40A4-839C-F9D9BEE3894F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF43FA92-7812-40A4-839C-F9D9BEE3894F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF43FA92-7812-40A4-839C-F9D9BEE3894F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
72
utils/ga-page-view/ga-page-view/Program.cs
Normal file
72
utils/ga-page-view/ga-page-view/Program.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
|
||||
namespace ga_page_view
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static BatchBlock<string> _queue = new BatchBlock<string>(20);
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var mt = startSvc();
|
||||
mt.Wait();
|
||||
}
|
||||
|
||||
private static async Task startSvc()
|
||||
{
|
||||
var c = await ConnectionMultiplexer.ConnectAsync("localhost");
|
||||
await c.GetSubscriber().SubscribeAsync("ga-page-view", (a, b) =>
|
||||
{
|
||||
_queue.Post(b.ToString());
|
||||
});
|
||||
|
||||
Console.WriteLine("Connected to redis");
|
||||
await sendStats();
|
||||
}
|
||||
|
||||
private static async Task sendStats()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var r = await _queue.ReceiveAsync();
|
||||
if (r != null)
|
||||
{
|
||||
Console.WriteLine("Sending stats..");
|
||||
await SendData(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static async Task SendData(string[] payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
var req = (HttpWebRequest)WebRequest.Create("https://www.google-analytics.com/batch");
|
||||
req.Method = "POST";
|
||||
using (StreamWriter sw = new StreamWriter(await req.GetRequestStreamAsync()))
|
||||
{
|
||||
await sw.WriteAsync(string.Join("\r\n", payload));
|
||||
}
|
||||
|
||||
var rsp = (HttpWebResponse)await req.GetResponseAsync();
|
||||
if (rsp.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(rsp.GetResponseStream()))
|
||||
{
|
||||
Console.WriteLine($"Got error reponse from analytics: {await sr.ReadToEndAsync()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error sending stats {ex.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
utils/ga-page-view/ga-page-view/ga-page-view.csproj
Normal file
12
utils/ga-page-view/ga-page-view/ga-page-view.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user