public void TestPollingInterval() { var loggerMock = new Mock <IAnimalFactLogger>(); loggerMock.Setup(l => l.WriteAsync(It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>())).Verifiable(); var logger = loggerMock.Object; var animalFactsMock = new Mock <IAnimalFacts>(); animalFactsMock.Setup(a => a.GetRandomFactAsync(It.IsAny <string>())).ReturnsAsync(() => new AnimalFact()).Verifiable(); var facts = animalFactsMock.Object; var poller = new PollingEngine(logger, facts); poller.Start(new PollingConfiguration { Amount = 1, Animal = "cat", Interval = 1 }); Task.Delay(TimeSpan.FromSeconds(2)).Wait(); poller.Stop(); loggerMock.Verify(l => l.WriteAsync(It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>()), Times.AtLeast(2)); animalFactsMock.Verify(a => a.GetRandomFactAsync(It.IsAny <string>()), Times.AtLeast(2)); }
public IEnumerable <string> GetHAProxyCounterKeys(string nodeKey) { var node = PollingEngine.GetNode("HAProxy", nodeKey) as HAProxyNode; if (node == null) { return(Enumerable.Empty <string>()); } return(node.Counters.Select(x => x.Key).OrderBy(x => x)); }
public override void Handle() { var node = PollingEngine.GetNode("HAProxy", Node_Name) as HAProxyNode; if (node != null) { node.Count("Client IP: " + Client_IP, this); node.Count("URL: " + this.GetUnique_HTTP_Request_URL(), this); } }
public ActionResult PollAll(string type, string key) { if (type.IsNullOrEmpty() || key.IsNullOrEmpty()) { return(ContentNotFound()); } PollingEngine.Poll(type, key); return(Json(new { success = true })); }
public ActionResult Poll(Guid?id) { if (!id.HasValue) { return(ContentNotFound()); } var success = PollingEngine.Poll(id.Value); return(Json(new { success })); }
public ActionResult Poll(string type, string key, Guid?id) { if (!type.HasValue() || !key.HasValue()) { return(ContentNotFound()); } var success = PollingEngine.Poll(type, key, id); return(Json(new { success })); }
public ActionResult PollDown() { try { PollingEngine.PollAllAsync(true); return(Json(true)); } catch (Exception e) { return(JsonError("Error polling all nodes: " + e.Message)); } }
public ActionResult JsonNodes(string type, string uniqueKey, Guid?guid = null) { if (type.IsNullOrEmpty()) { return(JsonError("type is missing")); } if (uniqueKey.IsNullOrEmpty()) { return(JsonError("uniqueKey is missing")); } try { var pollResult = PollingEngine.Poll(type, uniqueKey, guid, sync: true); return(Json(pollResult)); } catch (Exception e) { return(JsonError("Error polling node: " + e.Message)); } }
public ActionResult Debug() { var sb = new StringBuilder() .AppendFormat("Request IP: {0}\n", Current.RequestIP) .AppendFormat("Request User: {0}\n", Current.User.AccountName) .AppendFormat("Request Roles: {0}\n", Current.User.RawRoles) .AppendLine() .AppendLine("Headers:"); foreach (string k in Request.Headers.Keys) { sb.AppendFormat(" {0}: {1}\n", k, Request.Headers[k]); } var ps = PollingEngine.GetPollingStatus(); sb.AppendLine() .AppendLine("Polling Info:") .AppendLine(ps.GetPropertyNamesAndValues()); return(TextPlain(sb)); }
public async Task <ActionResult> PollNodes(string type, string[] key, Guid?guid = null) { if (type.IsNullOrEmpty()) { return(JsonError("type is missing")); } if (!(key?.Any() ?? false)) { return(JsonError("key is missing")); } try { var polls = key.Select(k => PollingEngine.PollAsync(type, k, guid)); var results = await Task.WhenAll(polls).ConfigureAwait(false); return(Json(results.Aggregate(true, (current, r) => current & r))); } catch (Exception e) { return(JsonError("Error polling node: " + e.Message)); } }
public ActionResult Debug() { var sb = StringBuilderCache.Get() .AppendLine("Request Info") .Append(" IP: ").AppendLine(Current.RequestIP) .Append(" User: "******" Roles: ").AppendLine(Current.User.Role.ToString()) .AppendLine() .AppendLine("Headers"); foreach (string k in Request.Headers.Keys) { sb.AppendFormat(" {0}: {1}\n", k, Request.Headers[k]); } var ps = PollingEngine.GetPollingStatus(); sb.AppendLine() .AppendLine("Polling Info") .AppendLine(ps.GetPropertyNamesAndValues(prefix: " ")); return(TextPlain(sb.ToStringRecycle())); }
protected void Application_Start() { // disable the X-AspNetMvc-Version: header MvcHandler.DisableMvcResponseHeader = true; AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); RegisterBundles(BundleTable.Bundles); //BundleTable.EnableOptimizations = true; SetupMiniProfiler(); Exceptional.Exceptional.Settings.GetCustomData = GetCustomErrorData; TaskScheduler.UnobservedTaskException += (sender, args) => Current.LogException(args.Exception); // enable custom model binder ModelBinders.Binders.DefaultBinder = new ProfiledModelBinder(); // When settings change, reload the app pool Current.Settings.OnChanged += HttpRuntime.UnloadAppDomain; PollingEngine.Configure(t => HostingEnvironment.QueueBackgroundWorkItem(_ => t())); }
Task <MiniProfiler> IAsyncStorage.LoadAsync(Guid id) => LoadAsync(id) ?? Task.FromResult(PollingEngine.GetCache(id)?.Profiler);
protected void Application_End() { PollingEngine.StopPolling(); }
public NodeStatusViewModel GetNodeStatus(string nodeType, string nodeKey, bool?includeData = false) { var node = PollingEngine.GetNode(HttpUtility.UrlDecode(nodeType), HttpUtility.UrlDecode(nodeKey)); return(GetNodeStatusViewModel(node, includeData)); }
MiniProfiler IStorage.Load(Guid id) => Load(id) ?? PollingEngine.GetCache(id)?.Profiler;
private void OnShutdown() { PollingEngine.StopPolling(); }