Skip to content

Instantly share code, notes, and snippets.

@rgl
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgl/ebaa34b04550022377d3 to your computer and use it in GitHub Desktop.
Save rgl/ebaa34b04550022377d3 to your computer and use it in GitHub Desktop.
nesper group by prev
using com.espertech.esper.client;
using System;
using System.Threading;
namespace UseNesper
{
class PerformanceCounter
{
public string ServerName { get; set; }
public double Value { get; set; }
}
class Program
{
static void Main(string[] args)
{
var configuration = new Configuration();
configuration.AddEventType<PerformanceCounter>();
var engine = EPServiceProviderManager.GetProvider("Engine", configuration);
var statement = engine.EPAdministrator.CreateEPL(@"
select ServerName, Value - prev(1, Value) as Value
from PerformanceCounter.std:groupwin(ServerName).win:time_batch(5 seconds)
");
statement.Events += (sender, e) =>
{
var now = DateTime.Now;
Console.WriteLine("Batch:");
if (e.OldEvents != null)
{
foreach (var bean in e.OldEvents)
{
Console.WriteLine("{0} OldEvents: ServerName={1} Value={2}", now, bean.Get("ServerName"), bean.Get("Value") ?? "(null)");
}
}
if (e.NewEvents != null)
{
foreach (var bean in e.NewEvents)
{
Console.WriteLine("{0} NewEvents: ServerName={1} Value={2}", now, bean.Get("ServerName"), bean.Get("Value") ?? "(null)");
}
}
};
var connectionFailures = 0;
while (!Console.KeyAvailable)
{
var p = new PerformanceCounter
{
ServerName = "a",
Value = connectionFailures
};
Console.WriteLine("{0} Post Performance Counter Value={1}", DateTime.Now, connectionFailures);
engine.EPRuntime.SendEvent(p);
connectionFailures += 10;
Thread.Sleep(500);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment