static void Main(string[] args) { var db1Metrics = new Metrics(); //var docsTimedCounterPerSec = db1Metrics.TimedCounter("db1", "docs new indexed/sec", "new Indexed Documents"); //for (int i = 0; i < 100; i++) //{ // docsTimedCounterPerSec.Mark(); // Thread.Sleep(10); //} //Console.WriteLine(docsTimedCounterPerSec.CurrentValue); var RequestsPerSecondHistogram = db1Metrics.Histogram("db1", "Request Per Second Histogram"); var RequestsPerSecondCounter = db1Metrics.TimedCounter("db1", "Request Per Second Counter","Request"); for (int i = 0; i < 100; i++) { RequestsPerSecondCounter.Mark(); RequestsPerSecondHistogram.Update((long)RequestsPerSecondCounter.CurrentValue); Thread.Sleep(10); } StringBuilder sb = new StringBuilder(); double[] res; var perc = RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999); res = perc; RequestsPerSecondHistogram.LogJson(sb,perc); Console.WriteLine(sb); Console.WriteLine(RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999)); // RequestsPerSecondHistogram.Update((long)documentDatabase.WorkContext.MetricsCounters.RequestsPerSecondCounter.CurrentValue); //?? }
/** * Broken out from the Run() method for unit testing */ public IRequest TransformMetrics(IRequest request, Metrics metrics, long timestamp) { foreach (var dictEntry in metrics.All) { if (dictEntry.Value is CounterMetric) { LogCounter(request, dictEntry.Key, (CounterMetric)dictEntry.Value, timestamp); } else if (dictEntry.Value is HistogramMetric) { LogHistogram(request, dictEntry.Key, (HistogramMetric)dictEntry.Value, timestamp); } else if (dictEntry.Value is MeterMetric) { LogMeter(request, dictEntry.Key, (MeterMetric)dictEntry.Value, timestamp); } else if (dictEntry.Value is TimerMetric) { LogTimer(request, dictEntry.Key, (TimerMetric)dictEntry.Value, timestamp); } else if (dictEntry.Value is GaugeMetric) { LogGauge(request, dictEntry.Key, (GaugeMetric)dictEntry.Value, timestamp); } else { Log.InfoFormat("Unknown metric type {}, not sending", dictEntry.Value.GetType()); } } return request; }
public static void MenuStarted() { if (!beenSetup) Setup(); metrics = new Metrics(); }
public static void Can_use_gauge_metric() { var queue = new Queue<int>(); var metrics = new Metrics(); var gauge = metrics.Gauge(typeof(GaugeTests), "Can_use_gauge_metric", () => queue.Count); queue.Enqueue(5); Assert.AreEqual(1, gauge.Value); }
public void SetUp() { _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<CachedData, string>("", _lookupKey); _contextCache = null; _response = null; _cachedItem = new CachedData(); _previousMetrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics(); }
public SqlReplicationMetricsCountersManager(Metrics dbMetrics, SqlReplicationConfig sqlReplicationConfig) { this.dbMetrics = dbMetrics; this.sqlReplicationConfig = sqlReplicationConfig; SqlReplicationBatchSizeMeter = dbMetrics.Meter("metrics", "SqlReplication Batch docs/min for " + sqlReplicationConfig.Name, "SQLReplication docs/min Counter", TimeUnit.Minutes); SqlReplicationBatchSizeHistogram = dbMetrics.Histogram("metrics", "SqlReplication Batch histogram for " + sqlReplicationConfig.Name); SqlReplicationDurationHistogram = dbMetrics.Histogram("metrics", "SQLReplication duration Histogram for " + sqlReplicationConfig.Name); TablesMetrics = new ConcurrentDictionary<string, SqlReplicationTableMetrics>(); }
public SqlReplicationTableMetrics(string tableName, SqlReplicationConfig cfg, Metrics dbMetrics) { this.dbMetrics = dbMetrics; Config = cfg; TableName = tableName; deleteMeterName = "SqlReplication Deletes/min for table :" + TableName + " in replication: " + Config.Name; insertMeterName = "SqlReplication Inserts/min for table :" + TableName + " in replication: " + Config.Name; }
public DataDogReporter(Metrics metrics, ITransport transport, IMetricNameFormatter formatter, IDictionary<string, string> globalTags, string[] path) : base(new TextMessageWriter(), metrics) { _metrics = metrics; _globalTags = globalTags; _path = path; _transport = transport; _nameFormatter = formatter; }
private void expandMetrics(Metrics metrics) { if(metrics != null) { _top = _top < metrics.Top ? _top : metrics.Top; _right = _right > metrics.Right ? _right : metrics.Right; _bottom = _bottom > metrics.Bottom ? _bottom : metrics.Bottom; _left = _left < metrics.Left ? _left : metrics.Left; } }
public void Can_load_all_metrics() { var metrics = new Metrics(); metrics.Clear(); var machineMetrics = new MachineMetrics(); machineMetrics.InstallAll(); Assert.IsTrue(metrics.All.Count > 0); }
public void MeasurePerformance() { var metrics = new Metrics(); var timer = metrics.Timer(GetType(), "test", TimeUnit.Seconds, TimeUnit.Seconds); for (var i = 0; i < 10; i++) { var amount = timer.Time(() => PerformReview().Result); } Assert.Less(timer.Mean, 90.0); }
public DataDogReporter(Metrics metrics, ITransport transport, IMetricNameFormatter formatter, string environment, string host, string[] path) : base(new TextMessageWriter(), metrics) { _metrics = metrics; _path = path; _transport = transport; _nameFormatter = formatter; _globalTags = new Dictionary<string, string>(); _globalTags.Add(ENVIRONMENT_TAG, environment); _globalTags.Add(HOST_TAG, host); }
public void ScanCallback(Key key, Record record) { Metrics metrics; if (!setMap.TryGetValue(key.setName, out metrics)) { metrics = new Metrics(); } metrics.count++; metrics.total++; setMap[key.setName] = metrics; }
public void Can_load_all_metrics() { var metrics = new Metrics(); metrics.Clear(); var machineMetrics = new MachineMetrics(metrics); machineMetrics.Install(); #if !COREFX Assert.IsTrue(metrics.All.Count > 0); #endif }
private void RegisterMetrics() { _metrics = new Metrics(); var counter = _metrics.Counter(typeof(CounterTests), "Can_run_with_known_counters_counter"); counter.Increment(100); var queue = new Queue<int>(); _metrics.Gauge(typeof(GaugeTests), "Can_run_with_known_counters_gauge", () => queue.Count); queue.Enqueue(1); queue.Enqueue(2); }
public void ManualTimerTestBasic() { var metrics = new Metrics(); var timer = metrics.ManualTimer(typeof(TimerTests), "|ManualTimertest", TimeUnit.Milliseconds, TimeUnit.Milliseconds); for (int i = 0; i < 10; i++) { timer.RecordElapsedMillis(250); } Assert.AreEqual(250d, timer.Mean, 5); // made-up delta values that "seems" right Assert.AreEqual(1d, timer.StdDev, 1); }
public void Can_serialize_metrics_with_changes() { var metrics = new Metrics(); var name = new MetricName(typeof(MeterTests), "Can_serialize_metrics_with_changes"); var meter = metrics.Meter(typeof(MeterTests), "Can_serialize_metrics_with_changes", "test", TimeUnit.Seconds); Assert.IsNotNull(metrics.All[name], "Metric not found in central registry"); meter.Mark(3); var reporter = new JsonReportFormatter(metrics); var json = reporter.GetSample(); Console.WriteLine(json); }
public SqlReplicationMetricsCountersManager(Metrics dbMetrics, SqlReplicationConfig sqlReplicationConfig) { this.dbMetrics = dbMetrics; this.sqlReplicationConfig = sqlReplicationConfig; meterName = "SqlReplication Batch docs/min for " + sqlReplicationConfig.Name; SqlReplicationBatchSizeMeter = dbMetrics.Meter(MeterContext, meterName, "SQLReplication docs/min Counter", TimeUnit.Minutes); MetricsTicker.Instance.AddMeterMetric(SqlReplicationBatchSizeMeter); SqlReplicationBatchSizeHistogram = dbMetrics.Histogram("metrics", "SqlReplication Batch histogram for " + sqlReplicationConfig.Name); SqlReplicationDurationHistogram = dbMetrics.Histogram("metrics", "SQLReplication duration Histogram for " + sqlReplicationConfig.Name); TablesMetrics = new ConcurrentDictionary<string, SqlReplicationTableMetrics>(); ReplicationPerformanceStats = new ConcurrentQueue<SqlReplicationPerformanceStats>(); }
static void Main(string[] args) { //var fileNames = new[] { "problem_0.json", "problem_2.json", "problem_3.json", "problem_5.json", "problem_7.json", "problem_8.json", "problem_9.json", "problem_10.json", "problem_11.json", "problem_15.json", "problem_16.json"}; var fileNames = new[] { "problem_16.json"}; var maxMetrics = new Metrics(new [] {0, 0}, 0, 0, 0, 0,0); for (MetricConst.KilledRows = 200; MetricConst.KilledRows <= 200; MetricConst.KilledRows += 100) for (MetricConst.RowPowerFactor = 0.9; MetricConst.RowPowerFactor <= 0.9; MetricConst.RowPowerFactor += 0.1) for (MetricConst.NewHolesCount = 100; MetricConst.NewHolesCount <= 100; MetricConst.NewHolesCount += 100) for (MetricConst.JoinedCellsCount = 50; MetricConst.JoinedCellsCount <= 50; MetricConst.JoinedCellsCount += 10) for (MetricConst.DownCellsCount = 20; MetricConst.DownCellsCount <= 20; MetricConst.DownCellsCount += 20) { var score = 0; int[] scores = new int[fileNames.Length]; for (int i = 0; i < fileNames.Length; i++ ) { var fileName = fileNames[i]; var f = new StreamReader(fileName); var s = f.ReadToEnd(); var inputData = JsonConvert.DeserializeObject<InputData>(s); var gameData = new GameData(inputData, new ArgParser(new string[0])); int sidScore = 0; for (int seedIdx = 0; seedIdx < gameData.InputData.sourceSeeds.Length; ++seedIdx) //for (int seedIdx = 0; seedIdx < 3; ++seedIdx) { int seed = gameData.InputData.sourceSeeds[seedIdx]; sidScore += new Algo1(gameData).Run(seed).Score; } scores[i] = sidScore / gameData.InputData.sourceSeeds.Length; score += scores[i]; } Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}, N: {2}, J: {3}, D: {4}", MetricConst.KilledRows, MetricConst.RowPowerFactor, MetricConst.NewHolesCount, MetricConst.JoinedCellsCount, MetricConst.DownCellsCount); //Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}", MetricConst.KilledRows, MetricConst.RowPowerFactor); string ss = ""; for (int j = 0; j < fileNames.Length; j++) ss += fileNames[j] + ": " + scores[j] + ". "; Console.WriteLine(ss + "Total: " + score + "\n"); if (score > maxMetrics.Score) maxMetrics = new Metrics(scores, MetricConst.KilledRows, MetricConst.RowPowerFactor, MetricConst.NewHolesCount, MetricConst.JoinedCellsCount, MetricConst.DownCellsCount); } Console.WriteLine("Max"); Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}, N: {2}, J: {3} , D: {4}", maxMetrics.KilledRows, maxMetrics.RowPowerFactor, maxMetrics.NewHolesCount, maxMetrics.JointCellsCount, maxMetrics.DownCellsCount); //Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}", maxMetrics.KilledRows, maxMetrics.RowPowerFactor); string st = ""; for (int j = 0; j < fileNames.Length; j++) st += fileNames[j] + ": " + maxMetrics.Scores[j] + ". "; Console.WriteLine(st + "Total: " + maxMetrics.Score + "\n"); }
static void Main(string[] args) { try { var metrics = new Metrics(); //DataDogReporterConfigModel dataDogReporterConfigModel = new DataDogReporterConfigModel("appdev", 8125, "ApplicationName", "DomainName", "Development"); ITransport transport = new UdpTransport.Builder().WithPort(8125) .WithStatsdHost("appdev") .Build(); string host = "hostName"; string environment = "testEnv"; string[] path = { "ApplicationName", "DomainName" }; //IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); var reporter = new DataDogReporter(metrics, transport, formatter, environment, host, path); reporter.Start(5, TimeUnit.Seconds); CounterMetric counter = metrics.Counter("test", "CounterMetric"); HistogramMetric histogramMetric = metrics.Histogram("test", "HistogramMetric"); GaugeMetric gaugeMetric = metrics.Gauge("test", "GaugeMetric", GetNumberOfUsersLoggedIn); var rand = new Random(); int runs = 0; while (runs < 1000) { System.Console.WriteLine("Loop " + (runs++) + " of 1000"); counter.Increment(); counter.Increment(); counter.Increment(); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); Thread.Sleep(5000); } } catch(Exception e) { throw; } }
public void CallbackTimerTestBasic() { var metrics = new Metrics(); var timer = metrics.CallbackTimer(typeof(TimerTests), "CallbackTimertest", TimeUnit.Milliseconds, TimeUnit.Milliseconds); for (int i = 0; i < 10; i++) { var ctx = timer.Time(); Thread.Sleep(250); ctx.Stop(); } Assert.AreEqual(250d, timer.Mean, 5); // made-up delta values that "seems" right Assert.AreEqual(1d, timer.StdDev, 1); }
public void updateMetrics(Metrics m) { if (beenAchieved) return; bool metAllSoFar = true; foreach(Requirement req in requirements) { if (!req.compare(m)) metAllSoFar = false; } if (metAllSoFar) { // Completed beenAchieved = true; Achieved(); } }
public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var complexity = new Metrics(c.Node.SyntaxTree).GetComplexity(c.Node); if (complexity > Maximum) { c.ReportDiagnostic(Diagnostic.Create(Rule, c.Node.GetLocation(), Maximum, complexity)); } }, SyntaxKind.ConstructorDeclaration, SyntaxKind.DestructorDeclaration, SyntaxKind.MethodDeclaration, SyntaxKind.OperatorDeclaration, SyntaxKind.GetAccessorDeclaration, SyntaxKind.SetAccessorDeclaration, SyntaxKind.AddAccessorDeclaration, SyntaxKind.RemoveAccessorDeclaration); }
public void HistogramPercentages() { Metrics metrics = new Metrics(); HistogramMetric histogramMetric = metrics.Histogram("test", "HealthMetrics.Test.HistogramMetrics"); for (int x = 1; x <= 100; x++) { histogramMetric.Update(x); } double[] percentials = { 0.75, 0.99, 0.999 }; double[] results = histogramMetric.Percentiles(percentials); Assert.IsNotNull(results); Assert.AreEqual(3, results.Length); Assert.AreEqual(75, results[0], 1); Assert.AreEqual(99, results[1], 1); Assert.AreEqual(99, results[2], 1); }
public RequestTypeMetricsMiddleware(AppOptions appOptions) { _service = appOptions.Service; _totalRequests = Metrics.CreateCounter("total_requests", "Number of HTTP requests.", "method", "service"); }
public void Dispose() { Cache.TryDispose(); Metrics.TryDispose(); }
static async Task <int> MainAsync(IConfigurationRoot configuration) { string logLevel = configuration.GetValue($"{Logger.RuntimeLogLevelEnvKey}", "info"); Logger.SetLogLevel(logLevel); // Set the LoggerFactory used by the Routing code. if (configuration.GetValue("EnableRoutingLogging", false)) { Routing.LoggerFactory = Logger.Factory; } EdgeHubCertificates certificates = await EdgeHubCertificates.LoadAsync(configuration).ConfigureAwait(false); bool clientCertAuthEnabled = configuration.GetValue(Constants.ConfigKey.EdgeHubClientCertAuthEnabled, false); Hosting hosting = Hosting.Initialize(configuration, certificates.ServerCertificate, new DependencyManager(configuration, certificates.ServerCertificate, certificates.TrustBundle), clientCertAuthEnabled); IContainer container = hosting.Container; ILogger logger = container.Resolve <ILoggerFactory>().CreateLogger("EdgeHub"); logger.LogInformation("Starting Edge Hub"); LogLogo(logger); LogVersionInfo(logger); logger.LogInformation("Loaded server certificate with expiration date of {0}", certificates.ServerCertificate.NotAfter.ToString("o")); // EdgeHub and CloudConnectionProvider have a circular dependency. So need to Bind the EdgeHub to the CloudConnectionProvider. IEdgeHub edgeHub = await container.Resolve <Task <IEdgeHub> >(); ICloudConnectionProvider cloudConnectionProvider = await container.Resolve <Task <ICloudConnectionProvider> >(); cloudConnectionProvider.BindEdgeHub(edgeHub); // EdgeHub cloud proxy and DeviceConnectivityManager have a circular dependency, // so the cloud proxy has to be set on the DeviceConnectivityManager after both have been initialized. var deviceConnectivityManager = container.Resolve <IDeviceConnectivityManager>(); IConnectionManager connectionManager = await container.Resolve <Task <IConnectionManager> >(); (deviceConnectivityManager as DeviceConnectivityManager)?.SetConnectionManager(connectionManager); // Register EdgeHub credentials var edgeHubCredentials = container.ResolveNamed <IClientCredentials>("EdgeHubCredentials"); ICredentialsCache credentialsCache = await container.Resolve <Task <ICredentialsCache> >(); await credentialsCache.Add(edgeHubCredentials); // Initializing configuration logger.LogInformation("Initializing configuration"); IConfigSource configSource = await container.Resolve <Task <IConfigSource> >(); ConfigUpdater configUpdater = await container.Resolve <Task <ConfigUpdater> >(); await configUpdater.Init(configSource); if (!Enum.TryParse(configuration.GetValue("AuthenticationMode", string.Empty), true, out AuthenticationMode authenticationMode) || authenticationMode != AuthenticationMode.Cloud) { ConnectionReauthenticator connectionReauthenticator = await container.Resolve <Task <ConnectionReauthenticator> >(); connectionReauthenticator.Init(); } (CancellationTokenSource cts, ManualResetEventSlim completed, Option <object> handler) = ShutdownHandler.Init(ShutdownWaitPeriod, logger); Metrics.BuildMetricsCollector(configuration); using (IProtocolHead protocolHead = await GetEdgeHubProtocolHeadAsync(logger, configuration, container, hosting).ConfigureAwait(false)) using (var renewal = new CertificateRenewal(certificates, logger)) { await protocolHead.StartAsync(); await Task.WhenAny(cts.Token.WhenCanceled(), renewal.Token.WhenCanceled()); logger.LogInformation("Stopping the protocol heads..."); await Task.WhenAny(protocolHead.CloseAsync(CancellationToken.None), Task.Delay(TimeSpan.FromSeconds(10), CancellationToken.None)); logger.LogInformation("Protocol heads stopped."); } completed.Set(); handler.ForEach(h => GC.KeepAlive(h)); logger.LogInformation("Shutdown complete."); return(0); }
public void defaults_to_null_statsd_to_not_blow_up_when_configure_is_not_called() { Metrics.Counter("stat"); }
/// <summary> /// Generate the exposure plot using the python libraries. /// </summary> public override string Render() { var longBacktestFrame = Metrics.Exposure(_backtestPortfolios, OrderDirection.Buy); var shortBacktestFrame = Metrics.Exposure(_backtestPortfolios, OrderDirection.Sell); var longLiveFrame = Metrics.Exposure(_livePortfolios, OrderDirection.Buy); var shortLiveFrame = Metrics.Exposure(_livePortfolios, OrderDirection.Sell); var backtestFrame = longBacktestFrame.Join(shortBacktestFrame) .FillMissing(Direction.Forward) .FillMissing(0.0); var liveFrame = longLiveFrame.Join(shortLiveFrame) .FillMissing(Direction.Forward) .FillMissing(0.0); longBacktestFrame = Frame.CreateEmpty <DateTime, Tuple <SecurityType, OrderDirection> >(); shortBacktestFrame = Frame.CreateEmpty <DateTime, Tuple <SecurityType, OrderDirection> >(); longLiveFrame = Frame.CreateEmpty <DateTime, Tuple <SecurityType, OrderDirection> >(); shortLiveFrame = Frame.CreateEmpty <DateTime, Tuple <SecurityType, OrderDirection> >(); foreach (var key in backtestFrame.ColumnKeys) { longBacktestFrame[key] = backtestFrame[key].SelectValues(x => x < 0 ? 0 : x); shortBacktestFrame[key] = backtestFrame[key].SelectValues(x => x > 0 ? 0 : x); } foreach (var key in liveFrame.ColumnKeys) { longLiveFrame[key] = liveFrame[key].SelectValues(x => x < 0 ? 0 : x); shortLiveFrame[key] = liveFrame[key].SelectValues(x => x > 0 ? 0 : x); } longBacktestFrame = longBacktestFrame.DropSparseColumnsAll(); shortBacktestFrame = shortBacktestFrame.DropSparseColumnsAll(); longLiveFrame = longLiveFrame.DropSparseColumnsAll(); shortLiveFrame = shortLiveFrame.DropSparseColumnsAll(); var base64 = ""; using (Py.GIL()) { var time = backtestFrame.RowKeys.ToList().ToPython(); var longSecurities = longBacktestFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython(); var shortSecurities = shortBacktestFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython(); var longData = longBacktestFrame.ColumnKeys.Select(x => longBacktestFrame[x].Values.ToList().ToPython()).ToPython(); var shortData = shortBacktestFrame.ColumnKeys.Select(x => shortBacktestFrame[x].Values.ToList().ToPython()).ToPython(); var liveTime = liveFrame.RowKeys.ToList().ToPython(); var liveLongSecurities = longLiveFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython(); var liveShortSecurities = shortLiveFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython(); var liveLongData = longLiveFrame.ColumnKeys.Select(x => longLiveFrame[x].Values.ToList().ToPython()).ToPython(); var liveShortData = shortLiveFrame.ColumnKeys.Select(x => shortLiveFrame[x].Values.ToList().ToPython()).ToPython(); base64 = Charting.GetExposure( time, longSecurities, shortSecurities, longData, shortData, liveTime, liveLongSecurities, liveShortSecurities, liveLongData, liveShortData ); } return(base64); }
public async Task CreateMetrics(Metrics metrics) { var insertOperation = TableOperation.Insert(metrics); await _studentsTable.ExecuteAsync(insertOperation); }
/// <summary> /// Gets metric by key /// </summary> public Option <Types.Metric> Metric(string name) => Metrics.FirstOrDefault(m => m.Name == name) ?? Option <Types.Metric> .None;
public async Task LabelNormal(Metrics type) { // Arrange var context = _serviceProvider.GetRequiredService <IDataContext>(); var metric = (await context.Metrics.AddAsync(new Metric { Type = type.AsInt(), Source = "smth.com" })).Entity; await context.AutoLabels.AddRangeAsync(new List <AutoLabel> { new AutoLabel { Id = AutoLabels.Normal.AsInt() }, new AutoLabel { Id = AutoLabels.Critical.AsInt() }, new AutoLabel { Id = AutoLabels.Warning.AsInt() }, }); switch (type) { case Metrics.CpuLoad: await context.NumericDataPoints.AddRangeAsync( new NumericDataPoint { Value = 23, Metric = metric }, new NumericDataPoint { Value = 65, Metric = metric }, new NumericDataPoint { Value = 43, Metric = metric }, new NumericDataPoint { Value = 45, Metric = metric }, new NumericDataPoint { Value = 34, Metric = metric } ); break; case Metrics.Health: await context.HealthReports.AddRangeAsync( DiscrepancyServiceTest.GenerateHealthReport(true, metric), DiscrepancyServiceTest.GenerateHealthReport(true, metric), DiscrepancyServiceTest.GenerateHealthReport(true, metric), DiscrepancyServiceTest.GenerateHealthReport(true, metric), DiscrepancyServiceTest.GenerateHealthReport(true, metric) ); break; case Metrics.Ping: await context.PingSettings.AddAsync( new PingSetting { ServerUrl = "https://smth.com", MaxResponseTime = new TimeSpan(0, 0, 0, 0, 1000), MaxFailures = 5 } ); await context.PingDataPoints.AddRangeAsync( new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 432), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 750), Metric = metric }, new PingDataPoint { Success = false, ResponseTime = new TimeSpan(0, 0, 0, 0, 70), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 876), Metric = metric }, new PingDataPoint { Success = false, ResponseTime = new TimeSpan(0, 0, 0, 0, 345), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 750), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 850), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 50), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 740), Metric = metric }, new PingDataPoint { Success = true, ResponseTime = new TimeSpan(0, 0, 0, 0, 234), Metric = metric, Timestamp = DateTime.UtcNow.AddSeconds(5), // make sure it is the most recent data point } ); break; } await context.SaveChangesAsync(); var expectedLabel = AutoLabels.Normal; // Act var cachedMetric = await new CacheService(context, new Mock <ILogger <CacheService> >().Object) .CacheMetricAsync(metric); // Assert Assert.Equal(expectedLabel.AsInt(), cachedMetric.AutoLabel.Id); }
public Result OnStartup(UIControlledApplication application) { //if (Utils.b_exportTools) return Result.Succeeded; try { m_startTime = DateTime.Now; Assembly exeAssembly = Assembly.GetExecutingAssembly(); string assemblyPath = exeAssembly.Location; string arcadisTab = Utils.k_arcadisMainTab; Metrics.AppendLog("\r\nLoading Export Panel"); Metrics.AppendLog("Toolbar Tab: " + arcadisTab); Metrics.AppendLog("Assembly Path: " + assemblyPath); Metrics.AppendLog("Load time: " + m_startTime.ToString()); ToolbarTab toolTab = null; foreach (ToolbarTab tab in Utils.s_arcadisRibbon.Tabs) { if (arcadisTab.Equals(tab.TabName)) { toolTab = tab; break; } } //Export Panel //----------------------- RibbonPanel panel; try { panel = application.CreateRibbonPanel(arcadisTab, Utils.k_exportPanel); } catch { return(Result.Cancelled); } if (null == panel) { return(Result.Failed); } ToolbarPanel toolPanel = new ToolbarPanel(panel.Name, panel, "Export_Panel.dll"); toolTab.Panels.Add(toolPanel); string strCommand = "Export_Panel.ExportData_Command"; Bitmap bitmap = Properties.Resources.ExportData; Bitmap bitmapHelp = null; string helpURL = "https://help.autodesk.com/view/RVT/2020/ENU/?guid=GUID-35DE66AB-6EF5-48C0-B477-F3B1B120F18A"; ContextualHelp contextHelp = new ContextualHelp(ContextualHelpType.Url, helpURL); string longDesc = "Long help description for command button. Can include a long descriptive text with and an optional image."; Utils.CreateCommand(panel, toolPanel, "Export Data", "Export Data", assemblyPath, strCommand, bitmap, "Export Data.", bitmapHelp, longDesc, contextHelp); strCommand = "Export_Panel.ExportExcel_Command"; bitmap = Properties.Resources.ExportExcel; Utils.CreateCommand(panel, toolPanel, "Export Excel", "Export Excel", assemblyPath, strCommand, bitmap, "Export to Excel.", bitmapHelp, longDesc, contextHelp); strCommand = "Export_Panel.ExportPCF_Command"; bitmap = Properties.Resources.ExportPCF; Utils.CreateCommand(panel, toolPanel, "Export PCF", "Export PCF", assemblyPath, strCommand, bitmap, "Export to PCF", bitmapHelp, longDesc, contextHelp); return(Result.Succeeded); } catch (Exception ex) { Autodesk.Revit.UI.TaskDialog.Show("Exception creating command button", ex.Message); Metrics.AppendLog("Exception Creating Toolbars: \r\n" + ex.Message); return(Result.Failed); } }
private void ValidateVertexCache() { if (this.vertTextCache != null && this.vertIconsCache != null && this.vertCountCache != null && this.metricsCache != null && !this.updateVertexCache) { // No need to update. return; } this.updateVertexCache = false; int fontNum = this.fonts != null ? this.fonts.Length : 0; // Setting up buffers { int countCacheLen = 1 + fontNum; if (this.vertCountCache == null || this.vertCountCache.Length != countCacheLen) this.vertCountCache = new int[countCacheLen]; int iconVertCount = this.iconCount * 4; if (this.vertIconsCache == null || this.vertIconsCache.Length < iconVertCount) this.vertIconsCache = new VertexC1P3T2[iconVertCount]; this.vertCountCache[0] = iconVertCount; if (this.vertTextCache == null || this.vertTextCache.Length != fontNum) this.vertTextCache = new VertexC1P3T2[fontNum][]; for (int i = 0; i < this.vertTextCache.Length; i++) { int textVertCount = this.fontGlyphCount.Length > i ? this.fontGlyphCount[i] * 4 : 0; this.vertCountCache[i + 1] = textVertCount; if (this.vertTextCache[i] == null || this.vertTextCache[i].Length < textVertCount) this.vertTextCache[i] = new VertexC1P3T2[textVertCount]; } } // Rendering { RenderState state = new RenderState(this); Element elem; int[] vertTextLen = new int[fontNum]; int vertIconLen = 0; while ((elem = state.NextElement()) != null) { if (elem is TextElement && state.Font != null) { TextElement textElem = elem as TextElement; VertexC1P3T2[] textElemVert = null; int count = state.Font.EmitTextVertices( state.CurrentElemText, ref textElemVert, state.CurrentElemOffset.X, state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine, state.Color); Array.Copy(textElemVert, 0, this.vertTextCache[state.FontIndex], state.CurrentElemTextVertexIndex, count); vertTextLen[state.FontIndex] = state.CurrentElemTextVertexIndex + count; } else if (elem is IconElement) { IconElement iconElem = elem as IconElement; Icon icon = iconElem.IconIndex >= 0 && iconElem.IconIndex < this.icons.Length ? this.icons[iconElem.IconIndex] : new Icon(); Vector2 iconOffset = icon.offset; Vector2 iconSize = icon.size; Rect iconUvRect = icon.uvRect; this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.X = state.CurrentElemOffset.X + iconOffset.X; this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y; this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Pos.Z = 0; this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].Color = state.Color; this.vertIconsCache[state.CurrentElemIconVertexIndex + 0].TexCoord = iconUvRect.TopLeft; this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.X = state.CurrentElemOffset.X + iconSize.X + iconOffset.X; this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine - iconSize.Y + iconOffset.Y; this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Pos.Z = 0; this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].Color = state.Color; this.vertIconsCache[state.CurrentElemIconVertexIndex + 1].TexCoord = iconUvRect.TopRight; this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.X = state.CurrentElemOffset.X + iconSize.X + iconOffset.X; this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine + iconOffset.Y; this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Pos.Z = 0; this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].Color = state.Color; this.vertIconsCache[state.CurrentElemIconVertexIndex + 2].TexCoord = iconUvRect.BottomRight; this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.X = state.CurrentElemOffset.X + iconOffset.X; this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Y = state.CurrentElemOffset.Y + state.LineBaseLine + iconOffset.Y; this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Pos.Z = 0; this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].Color = state.Color; this.vertIconsCache[state.CurrentElemIconVertexIndex + 3].TexCoord = iconUvRect.BottomLeft; vertIconLen = state.CurrentElemIconVertexIndex + 4; } } this.vertCountCache[0] = vertIconLen; for (int i = 0; i < fontNum; i++) this.vertCountCache[i + 1] = vertTextLen[i]; } // Updating the metrics cache { Vector2 size = Vector2.Zero; List<Rect> lineBounds = new List<Rect>(16); List<Rect> elementBounds = new List<Rect>(this.elements.Length); RenderState state = new RenderState(this); Element elem; Vector2 elemSize; Vector2 elemOffset; int lastElemIndex = -1; int lastLineIndex = 0; bool elemIndexChanged = true; bool lineChanged = true; bool hasBounds; while ((elem = state.NextElement()) != null) { if (elem is TextElement && state.Font != null) { TextElement textElem = elem as TextElement; elemSize = state.Font.MeasureText(state.CurrentElemText); elemOffset = new Vector2(state.CurrentElemOffset.X, state.CurrentElemOffset.Y + state.LineBaseLine - state.Font.BaseLine); } else if (elem is IconElement && this.icons != null) { IconElement iconElem = elem as IconElement; bool iconValid = iconElem.IconIndex > 0 && iconElem.IconIndex < this.icons.Length; elemSize = iconValid ? this.icons[iconElem.IconIndex].size : Vector2.Zero; elemOffset = new Vector2(state.CurrentElemOffset.X, state.CurrentElemOffset.Y + state.LineBaseLine - elemSize.Y); } else { elemSize = Vector2.Zero; elemOffset = Vector2.Zero; } hasBounds = elemSize != Vector2.Zero; if (elemIndexChanged) elementBounds.Add(Rect.Empty); if (hasBounds && elementBounds[elementBounds.Count - 1] == Rect.Empty) elementBounds[elementBounds.Count - 1] = new Rect(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y); else if (hasBounds) elementBounds[elementBounds.Count - 1] = elementBounds[elementBounds.Count - 1].ExpandedToContain(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y); if (lineChanged) lineBounds.Add(Rect.Empty); if (hasBounds && lineBounds[lineBounds.Count - 1] == Rect.Empty) lineBounds[lineBounds.Count - 1] = new Rect(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y); else if (hasBounds) lineBounds[lineBounds.Count - 1] = lineBounds[lineBounds.Count - 1].ExpandedToContain(elemOffset.X, elemOffset.Y, elemSize.X, elemSize.Y); size.X = Math.Max(size.X, elemOffset.X + elemSize.X); size.Y = Math.Max(size.Y, elemOffset.Y + elemSize.Y); elemIndexChanged = lastElemIndex != state.CurrentElemIndex; lineChanged = lastLineIndex != state.CurrentLineIndex; lastElemIndex = state.CurrentElemIndex; lastLineIndex = state.CurrentLineIndex; } this.metricsCache = new Metrics(size, lineBounds, elementBounds); } }
public FaultRuningCommand() { Metrics.Reset(); ConfigSetForTest.MetricsHealthSnapshotIntervalInMilliseconds = 1; }
public MainWindowVM(MainWindow mainWindow, MainSettings settings) { ConverterRegistration.Register(); MainWindow = mainWindow; Settings = settings; Installer = new Lazy <InstallerVM>(() => new InstallerVM(this)); Compiler = new Lazy <CompilerVM>(() => new CompilerVM(this)); SettingsPane = new Lazy <SettingsVM>(() => new SettingsVM(this)); Gallery = new Lazy <ModListGalleryVM>(() => new ModListGalleryVM(this)); ModeSelectionVM = new ModeSelectionVM(this); ModListContentsVM = new Lazy <ModListContentsVM>(() => new ModListContentsVM(this)); UserInterventionHandlers = new UserInterventionHandlers(this); // Set up logging Utils.LogMessages .ObserveOn(RxApp.TaskpoolScheduler) .ToObservableChangeSet() .Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler) .Where(l => l.Count > 0) .FlattenBufferResult() .ObserveOnGuiThread() .Bind(Log) .Subscribe() .DisposeWith(CompositeDisposable); Utils.LogMessages .Where(a => a is IUserIntervention or CriticalFailureIntervention) .ObserveOnGuiThread() .SelectTask(async msg => { try { await UserInterventionHandlers.Handle(msg); } catch (Exception ex) when(ex.GetType() != typeof(TaskCanceledException)) { Utils.Error(ex, $"Error while handling user intervention of type {msg?.GetType()}"); try { if (msg is IUserIntervention { Handled: false } intervention) { intervention.Cancel(); } } catch (Exception cancelEx) { Utils.Error(cancelEx, $"Error while cancelling user intervention of type {msg?.GetType()}"); } } }) .Subscribe() .DisposeWith(CompositeDisposable); if (IsStartingFromModlist(out var path)) { Installer.Value.ModListLocation.TargetPath = path; NavigateTo(Installer.Value); } else { // Start on mode selection NavigateTo(ModeSelectionVM); } try { var assembly = Assembly.GetExecutingAssembly(); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); Consts.CurrentMinimumWabbajackVersion = Version.Parse(fvi.FileVersion); VersionDisplay = $"v{fvi.FileVersion}"; Utils.Log($"Wabbajack Version: {fvi.FileVersion}"); Task.Run(() => Metrics.Send("started_wabbajack", fvi.FileVersion)).FireAndForget(); Task.Run(() => Metrics.Send("started_sha", ThisAssembly.Git.Sha)); } catch (Exception ex) { Utils.Error(ex); VersionDisplay = "ERROR"; } CopyVersionCommand = ReactiveCommand.Create(() => { Clipboard.SetText($"Wabbajack {VersionDisplay}\n{ThisAssembly.Git.Sha}"); }); OpenSettingsCommand = ReactiveCommand.Create( canExecute: this.WhenAny(x => x.ActivePane) .Select(active => !SettingsPane.IsValueCreated || !object.ReferenceEquals(active, SettingsPane.Value)), execute: () => NavigateTo(SettingsPane.Value)); }
public async Task <object> GetUpdates([FromRoute(Name = "branch")] string updateBranch, [FromQuery(Name = "version")] string urlVersion, [FromQuery(Name = "os")] OperatingSystem operatingSystem, [FromQuery(Name = "runtime")] Runtime runtime, [FromQuery(Name = "runtimeVer")] string urlRuntimeVersion, [FromQuery(Name = "arch")] Architecture arch, [FromQuery(Name = "active")] bool activeInstall = true) { Response.Headers[HeaderNames.CacheControl] = GetCacheControlHeader(DateTime.UtcNow); // Check given version if (!Version.TryParse(urlVersion, out var version)) { return(new { ErrorMessage = "Invalid version number specified." }); } var userAgentInfo = new UserAgentInfo(Request.Headers["User-Agent"].ToString()); // Dont' send metrics for dev/debug instances if (version.Major < 10) { var remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress; Metrics.Write("userstats", new Dictionary <string, object> { { "source", remoteIpAddress } }, new Dictionary <string, string> { { "program", _project }, { "requestApp", userAgentInfo.App ?? "Unknown" }, { "branch", updateBranch }, { "version", urlVersion }, { "os", operatingSystem.ToString() }, { "osName", userAgentInfo.Name ?? "Unknown" }, { "osVersion", userAgentInfo.OsVersion ?? "Unknown" }, { "runtime", runtime.ToString() }, { "runtimeVersion", urlRuntimeVersion }, { "arch", arch.ToString() }, { "activeinstall", activeInstall.ToString() } }); } var files = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, false, 1, urlVersion, urlRuntimeVersion); var updateFile = files.FirstOrDefault(); if (updateFile == null) { return(new UpdatePackageContainer { Available = false }); } var update = updateFile.Update.Value; // Compare given version and update version var updateVersion = new Version(update.Version); if (updateVersion.CompareTo(version) <= 0) { return(new UpdatePackageContainer { Available = false }); } // Get the update changes UpdateChanges updateChanges = null; if (update.New.Count != 0 || update.Fixed.Count != 0) { updateChanges = new UpdateChanges { New = update.New, Fixed = update.Fixed }; } return(new UpdatePackageContainer { Available = true, UpdatePackage = new UpdatePackage { Version = update.Version, ReleaseDate = update.ReleaseDate, Filename = updateFile.Filename, Url = updateFile.Url, Changes = updateChanges, Hash = updateFile.Hash, Branch = update.Branch.ToString().ToLower(), Runtime = updateFile.Runtime.ToString().ToLower() } }); }
public MetricsGauge(string name, string description, List <string> labelNames, List <string> defaultLabelValues) : base(labelNames, defaultLabelValues) { this.gauge = Metrics.CreateGauge(name, description, labelNames.ToArray()); }
/// <summary> /// Starts the controller. /// </summary> /// <param name="k8s">The <see cref="IKubernetes"/> client to use.</param> /// <returns>The tracking <see cref="Task"/>.</returns> public static async Task StartAsync(IKubernetes k8s) { Covenant.Requires <ArgumentNullException>(k8s != null, nameof(k8s)); if (NeonHelper.IsLinux) { // Ensure that the [/var/run/neonkube/node-tasks] folder exists on the node. var scriptPath = Path.Combine(Node.HostMount, $"tmp/node-agent-folder-{NeonHelper.CreateBase36Uuid()}.sh"); var script = $@"#!/bin/bash set -euo pipefail # Ensure that the nodetask runtime folders exist and have the correct permissions. if [ ! -d {hostNeonRunFolder} ]; then mkdir -p {hostNeonRunFolder} chmod 700 {hostNeonRunFolder} fi if [ ! -d {hostNeonTasksFolder} ]; then mkdir -p {hostNeonTasksFolder} chmod 700 {hostNeonTasksFolder} fi # Remove this script. rm $0 "; File.WriteAllText(scriptPath, NeonHelper.ToLinuxLineEndings(script)); try { (await Node.BashExecuteCaptureAsync(scriptPath)).EnsureSuccess(); } finally { NeonHelper.DeleteFile(scriptPath); } } // Load the configuration settings. var leaderConfig = new LeaderElectionConfig( k8s, @namespace: KubeNamespace.NeonSystem, leaseName: $"{Program.Service.Name}.nodetask-{Node.Name}", identity: Pod.Name, promotionCounter: Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_promoted", "Leader promotions"), demotionCounter: Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_demoted", "Leader demotions"), newLeaderCounter: Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_newLeader", "Leadership changes")); var options = new ResourceManagerOptions() { IdleInterval = Program.Service.Environment.Get("NODETASK_IDLE_INTERVAL", TimeSpan.FromSeconds(60)), ErrorMinRequeueInterval = Program.Service.Environment.Get("NODETASK_ERROR_MIN_REQUEUE_INTERVAL", TimeSpan.FromSeconds(15)), ErrorMaxRetryInterval = Program.Service.Environment.Get("NODETASK_ERROR_MAX_REQUEUE_INTERVAL", TimeSpan.FromSeconds(60)), IdleCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_idle", "IDLE events processed."), ReconcileCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_reconcile", "RECONCILE events processed."), DeleteCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_delete", "DELETED events processed."), IdleErrorCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_idle_error", "Failed NodeTask IDLE event processing."), ReconcileErrorCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_reconcile_error", "Failed NodeTask RECONCILE event processing."), DeleteErrorCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_delete_error", "Failed NodeTask DELETE event processing."), StatusModifyErrorCounter = Metrics.CreateCounter($"{Program.Service.MetricsPrefix}nodetask_statusmodify_error", "Failed NodeTask STATUS-MODIFY events processing.") }; resourceManager = new ResourceManager <V1NeonNodeTask, NodeTaskController>( k8s, options: options, filter: NodeTaskFilter, leaderConfig: leaderConfig); await resourceManager.StartAsync(); }
public override bool compare(Metrics m) { return comparison.compare(m.levels); }
public async Task <IActionResult> GetSystemMetrics([FromQuery] MetricsFilterDTO queryParameters) { try { if (string.IsNullOrWhiteSpace(queryParameters.Timeframe)) { throw new ArgumentNullException("Timeframe"); } var metrics = new Metrics(); metrics.Timeframe = queryParameters.Timeframe; // Build base queryable var queryable = await BuildQueryableAsync(queryParameters.Timeframe); // If not metrics to return if (queryable == null || queryable.Count() == 0) { return(NoContent()); } // Pull reviewed/unreviewed metrics from querable var reviewed = MetadataProcessors.GetReviewed(queryable); metrics.Reviewed = reviewed.ReviewedCount; metrics.Unreviewed = reviewed.UnreviewedCount; // Pull results metrics from queryable var results = MetadataProcessors.GetResults(queryable); metrics.ConfirmedDetection = results.ConfirmedCount; metrics.FalseDetection = results.FalseCount; metrics.UnknownDetection = results.UnknownCount; // Pull comments from queryable metrics.ConfirmedComments = MetadataProcessors.GetComments(queryable, "yes"); metrics.UnconfirmedComments = MetadataProcessors.GetComments(queryable, "no"); metrics.UnconfirmedComments.AddRange(MetadataProcessors.GetComments(queryable, "don't know")); metrics.UnconfirmedComments = metrics.UnconfirmedComments.OrderByDescending(x => x.Timestamp).ToList(); // Pull tags from queryable metrics.Tags = MetadataProcessors.GetTags(queryable); return(Ok(metrics)); } catch (ArgumentNullException ex) { var details = new ProblemDetails() { Detail = ex.Message }; return(BadRequest(details)); } catch (Exception ex) { var details = new ProblemDetails() { Title = ex.GetType().ToString(), Detail = ex.Message }; return(StatusCode(StatusCodes.Status500InternalServerError, details)); } }
private void Execute() { var volatileCache = new DictionaryVolatileCache(_cacheKey, _cachedItem); var cache = TestHelpers.GetCache(volatileCache: volatileCache); _contextCache = cache.GetContextCache(); _response = cache.Get<CachedData>(_lookupKey); _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics(); }
static BodyConverter() { var path = UltimaFileManager.GetFilePath("bodyconv.def"); if (path == null) { return; } ArrayList list1 = new ArrayList(), list2 = new ArrayList(), list3 = new ArrayList(), list4 = new ArrayList(); int max1 = 0, max2 = 0, max3 = 0, max4 = 0; using (var ip = new StreamReader(path)) { string line; var totalDataRead = 0; while ((line = ip.ReadLine()) != null) { totalDataRead += line.Length; if ((line = line.Trim()).Length == 0 || line.StartsWith("#") || line.StartsWith("\"#")) { continue; } // string[] split = line.Split('\t'); var split = Regex.Split(line, @"\t|\s+", RegexOptions.IgnoreCase); var original = System.Convert.ToInt32(split[0]); var anim2 = System.Convert.ToInt32(split[1]); if (split.Length < 3 || !int.TryParse(split[2], out int anim3)) { anim3 = -1; } if (split.Length < 4 || !int.TryParse(split[3], out int anim4)) { anim4 = -1; } if (split.Length < 5 || !int.TryParse(split[4], out int anim5)) { anim5 = -1; } if (anim2 != -1) { if (anim2 == 68) { anim2 = 122; } if (original > max1) { max1 = original; } list1.Add(original); list1.Add(anim2); } if (anim3 != -1) { if (original > max2) { max2 = original; } list2.Add(original); list2.Add(anim3); } if (anim4 != -1) { if (original > max3) { max3 = original; } list3.Add(original); list3.Add(anim4); } if (anim5 != -1) { if (original > max4) { max4 = original; } list4.Add(original); list4.Add(anim5); } } Metrics.ReportDataRead(totalDataRead); } _table1 = new int[max1 + 1]; _table2 = new int[max2 + 1]; _table3 = new int[max3 + 1]; _table4 = new int[max4 + 1]; for (var i = 0; i < _table1.Length; ++i) { _table1[i] = -1; } for (var i = 0; i < list1.Count; i += 2) { _table1[(int)list1[i]] = (int)list1[i + 1]; } for (var i = 0; i < _table2.Length; ++i) { _table2[i] = -1; } for (var i = 0; i < list2.Count; i += 2) { _table2[(int)list2[i]] = (int)list2[i + 1]; } for (var i = 0; i < _table3.Length; ++i) { _table3[i] = -1; } for (var i = 0; i < list3.Count; i += 2) { _table3[(int)list3[i]] = (int)list3[i + 1]; } for (var i = 0; i < _table4.Length; ++i) { _table4[i] = -1; } for (var i = 0; i < list4.Count; i += 2) { _table4[(int)list4[i]] = (int)list4[i + 1]; } }
/// <summary> /// Reset metrics and dimensions /// </summary> public void ResetMetricsAndDimensions() { Metrics.Clear(); Dimensions.Clear(); }
public async Task <ExecutionResult> ExecuteAsync(ExecutionOptions config) { var metrics = new Metrics(); metrics.Start(config.OperationName); config.Schema.FieldNameConverter = config.FieldNameConverter; var result = new ExecutionResult { Query = config.Query }; try { if (!config.Schema.Initialized) { using (metrics.Subject("schema", "Initializing schema")) { config.FieldMiddleware.ApplyTo(config.Schema); config.Schema.Initialize(); } } var document = config.Document; using (metrics.Subject("document", "Building document")) { if (document == null) { document = _documentBuilder.Build(config.Query); } } result.Document = document; var operation = GetOperation(config.OperationName, document); result.Operation = operation; metrics.SetOperationName(operation?.Name); if (config.ComplexityConfiguration != null) { using (metrics.Subject("document", "Analyzing complexity")) _complexityAnalyzer.Validate(document, config.ComplexityConfiguration); } IValidationResult validationResult; using (metrics.Subject("document", "Validating document")) { validationResult = _documentValidator.Validate( config.Query, config.Schema, document, config.ValidationRules, config.UserContext); } foreach (var listener in config.Listeners) { await listener.AfterValidationAsync( config.UserContext, validationResult, config.CancellationToken) .ConfigureAwait(false); } if (validationResult.IsValid) { var context = BuildExecutionContext( config.Schema, config.Root, document, operation, config.Inputs, config.UserContext, config.CancellationToken, metrics); if (context.Errors.Any()) { result.Errors = context.Errors; return(result); } using (metrics.Subject("execution", "Executing operation")) { foreach (var listener in config.Listeners) { await listener.BeforeExecutionAsync(config.UserContext, config.CancellationToken).ConfigureAwait(false); } var task = ExecuteOperationAsync(context).ConfigureAwait(false); foreach (var listener in config.Listeners) { await listener.BeforeExecutionAwaitedAsync(config.UserContext, config.CancellationToken).ConfigureAwait(false); } result.Data = await task; foreach (var listener in config.Listeners) { await listener.AfterExecutionAsync(config.UserContext, config.CancellationToken).ConfigureAwait(false); } } if (context.Errors.Any()) { result.Errors = context.Errors; } } else { result.Data = null; result.Errors = validationResult.Errors; } return(result); } catch (Exception exc) { if (result.Errors == null) { result.Errors = new ExecutionErrors(); } result.Data = null; result.Errors.Add(new ExecutionError(exc.Message, exc)); return(result); } finally { result.Perf = metrics.Finish().ToArray(); } }
public MetricsTests() { _registry = Metrics.NewCustomRegistry(); _metrics = Metrics.WithCustomRegistry(_registry); }
public async Task Invoke_Should_Be_Successful() { Metrics.SuppressDefaultMetrics(); PrometheusMiddleware prometheusMiddleware = new PrometheusMiddleware( _requestDelegateMock.Object, _iLoggerMock.Object, _iQueueServiceMock.Object, _iTopicServiceMock.Object, _iSubscriptionServiceMock.Object, _iOptionsMock.Object, _iServicebusNamespace.Object); var context = new DefaultHttpContext(); context.Request.Path = "/metrics"; _iQueueServiceMock.Setup(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>())).ReturnsAsync(new List <GaugeModel>() { new GaugeModel() { Name = "Queue", Help = "Queue Help", Labels = new [] { "env" }, LabelValues = new [] { "dev" }, Value = 200 } }); _iSubscriptionServiceMock.Setup(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>())).ReturnsAsync(new List <GaugeModel>() { new GaugeModel() { Name = "Subscription", Help = "Subscription Help", Labels = new [] { "env" }, LabelValues = new [] { "dev" }, Value = 300 } }); _iTopicServiceMock.Setup(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>())).ReturnsAsync(new List <GaugeModel>() { new GaugeModel() { Name = "Topic", Help = "Topic Help", Labels = new [] { "env" }, LabelValues = new [] { "dev" }, Value = 400 } }); await prometheusMiddleware.Invoke(context); var lines = await GetMetrics(); Assert.Contains(lines, s => s == "Queue{env=\"dev\"} 200"); Assert.Contains(lines, s => s == "Subscription{env=\"dev\"} 300"); Assert.Contains(lines, s => s == "Topic{env=\"dev\"} 400"); Assert.Contains(lines, s => s == "azureservicebusexporter_up 1"); Assert.Contains(lines, s => s.StartsWith("scrape_duration_milliseconds ")); _iQueueServiceMock.Verify(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>()), Times.Once); _iSubscriptionServiceMock.Verify(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>()), Times.Once); _iTopicServiceMock.Verify(x => x.CreateMetricsAsync(It.IsAny <IServiceBusNamespace>()), Times.Once); }
public async Task <IActionResult> GetMetrics() { var report = await Metrics.Report(); return(Content(report, "text/plain")); }
public async Task LabelCritical(Metrics type) { // Arrange var context = _serviceProvider.GetRequiredService <IDataContext>(); var metric = (await context.Metrics.AddAsync(new Metric { Type = type.AsInt(), Source = "smth.com" })).Entity; await context.AutoLabels.AddRangeAsync(new List <AutoLabel> { new AutoLabel { Id = AutoLabels.Normal.AsInt() }, new AutoLabel { Id = AutoLabels.Critical.AsInt() }, new AutoLabel { Id = AutoLabels.Warning.AsInt() }, }); switch (type) { case Metrics.CpuLoad: await context.NumericDataPoints.AddRangeAsync( new NumericDataPoint { Value = 90, Metric = metric }, new NumericDataPoint { Value = 92, Metric = metric }, new NumericDataPoint { Value = 88, Metric = metric }, new NumericDataPoint { Value = 89, Metric = metric }, new NumericDataPoint { Value = 100, Metric = metric } ); break; case Metrics.Health: await context.HealthReports.AddRangeAsync( DiscrepancyServiceTest.GenerateHealthReport(true, metric), DiscrepancyServiceTest.GenerateHealthReport(false, metric), DiscrepancyServiceTest.GenerateHealthReport(false, metric), DiscrepancyServiceTest.GenerateHealthReport(false, metric), DiscrepancyServiceTest.GenerateHealthReport(false, metric) ); break; case Metrics.Ping: await context.PingSettings.AddAsync( new PingSetting { ServerUrl = "https://smth.com", MaxFailures = 5 } ); await context.PingDataPoints.AddRangeAsync( new PingDataPoint { Success = true, Metric = metric }, new PingDataPoint { Success = true, Metric = metric }, new PingDataPoint { Success = false, Metric = metric }, new PingDataPoint { Success = true, Metric = metric }, new PingDataPoint { Success = false, Metric = metric }, new PingDataPoint { Success = false, Metric = metric }, new PingDataPoint { Success = true, Metric = metric }, new PingDataPoint { Success = false, Metric = metric }, new PingDataPoint { Success = false, Metric = metric }, new PingDataPoint { Success = true, Metric = metric } ); break; } await context.SaveChangesAsync(); var expectedLabel = AutoLabels.Critical; // Act var cachedMetric = await new CacheService(context, new Mock <ILogger <CacheService> >().Object) .CacheMetricAsync(metric); // Assert Assert.Equal(expectedLabel.AsInt(), cachedMetric.AutoLabel.Id); }
public Result OnShutdown(UIControlledApplication application) { Metrics.AppendLog("Export Panel Shutdown"); return(Result.Succeeded); }
public abstract bool compare(Metrics m);
public IterativeDeepeningSearch() { iterationMetrics = new Metrics(); iterationMetrics.set(METRIC_NODES_EXPANDED, 0); iterationMetrics.set(PATH_COST, 0); }
public void ComputeMetrics() { Metrics = new Metrics(); Metrics.Initialize (Keys); Metrics.SegmentMotion(1); for (int arm = 0; arm < 2; arm++) { Metrics.Weight(arm); Metrics.Space(arm); Metrics.Time(arm); Metrics.Flow(arm); Metrics.Emote(arm); } Metrics.Posture(); }
static async Task <int> MainAsync(IConfigurationRoot configuration) { string logLevel = configuration.GetValue($"{Logger.RuntimeLogLevelEnvKey}", "info"); Logger.SetLogLevel(logLevel); // Set the LoggerFactory used by the Routing code. if (configuration.GetValue("EnableRoutingLogging", false)) { Routing.LoggerFactory = Logger.Factory; } ILogger logger = Logger.Factory.CreateLogger("EdgeHub"); EdgeHubCertificates certificates = await EdgeHubCertificates.LoadAsync(configuration, logger); bool clientCertAuthEnabled = configuration.GetValue(Constants.ConfigKey.EdgeHubClientCertAuthEnabled, false); string sslProtocolsConfig = configuration.GetValue(Constants.ConfigKey.SslProtocols, string.Empty); SslProtocols sslProtocols = SslProtocolsHelper.Parse(sslProtocolsConfig, DefaultSslProtocols, logger); logger.LogInformation($"Enabling SSL protocols: {sslProtocols.Print()}"); IDependencyManager dependencyManager = new DependencyManager(configuration, certificates.ServerCertificate, certificates.TrustBundle, sslProtocols); Hosting hosting = Hosting.Initialize(configuration, certificates.ServerCertificate, dependencyManager, clientCertAuthEnabled, sslProtocols); IContainer container = hosting.Container; logger.LogInformation("Initializing Edge Hub"); LogLogo(logger); LogVersionInfo(logger); logger.LogInformation($"OptimizeForPerformance={configuration.GetValue("OptimizeForPerformance", true)}"); logger.LogInformation($"MessageAckTimeoutSecs={configuration.GetValue("MessageAckTimeoutSecs", 30)}"); logger.LogInformation("Loaded server certificate with expiration date of {0}", certificates.ServerCertificate.NotAfter.ToString("o")); var metricsProvider = container.Resolve <IMetricsProvider>(); Metrics.InitWithAspNet(metricsProvider, logger); // Note this requires App.UseMetricServer() to be called in Startup.cs // Init V0 Metrics MetricsV0.BuildMetricsCollector(configuration); // EdgeHub and CloudConnectionProvider have a circular dependency. So need to Bind the EdgeHub to the CloudConnectionProvider. IEdgeHub edgeHub = await container.Resolve <Task <IEdgeHub> >(); ICloudConnectionProvider cloudConnectionProvider = await container.Resolve <Task <ICloudConnectionProvider> >(); cloudConnectionProvider.BindEdgeHub(edgeHub); // EdgeHub cloud proxy and DeviceConnectivityManager have a circular dependency, // so the cloud proxy has to be set on the DeviceConnectivityManager after both have been initialized. var deviceConnectivityManager = container.Resolve <IDeviceConnectivityManager>(); IConnectionManager connectionManager = await container.Resolve <Task <IConnectionManager> >(); (deviceConnectivityManager as DeviceConnectivityManager)?.SetConnectionManager(connectionManager); // Register EdgeHub credentials var edgeHubCredentials = container.ResolveNamed <IClientCredentials>("EdgeHubCredentials"); ICredentialsCache credentialsCache = await container.Resolve <Task <ICredentialsCache> >(); await credentialsCache.Add(edgeHubCredentials); // Initializing configuration logger.LogInformation("Initializing configuration"); IConfigSource configSource = await container.Resolve <Task <IConfigSource> >(); ConfigUpdater configUpdater = await container.Resolve <Task <ConfigUpdater> >(); await configUpdater.Init(configSource); if (!Enum.TryParse(configuration.GetValue("AuthenticationMode", string.Empty), true, out AuthenticationMode authenticationMode) || authenticationMode != AuthenticationMode.Cloud) { ConnectionReauthenticator connectionReauthenticator = await container.Resolve <Task <ConnectionReauthenticator> >(); connectionReauthenticator.Init(); } TimeSpan shutdownWaitPeriod = TimeSpan.FromSeconds(configuration.GetValue("ShutdownWaitPeriod", DefaultShutdownWaitPeriod)); (CancellationTokenSource cts, ManualResetEventSlim completed, Option <object> handler) = ShutdownHandler.Init(shutdownWaitPeriod, logger); using (IProtocolHead protocolHead = await GetEdgeHubProtocolHeadAsync(logger, configuration, container, hosting)) using (var renewal = new CertificateRenewal(certificates, logger)) { try { await protocolHead.StartAsync(); await Task.WhenAny(cts.Token.WhenCanceled(), renewal.Token.WhenCanceled()); } catch (Exception ex) { logger.LogError($"Error starting protocol heads: {ex.Message}"); } logger.LogInformation("Stopping the protocol heads..."); await protocolHead.CloseAsync(CancellationToken.None); logger.LogInformation("Protocol heads stopped."); await CloseDbStoreProviderAsync(container); } completed.Set(); handler.ForEach(h => GC.KeepAlive(h)); logger.LogInformation("Shutdown complete."); return(0); }
public void throws_when_configured_with_a_null_configuration() { Assert.Throws <ArgumentNullException>(() => Metrics.Configure(null)); }
/// <summary> /// Initializes a new instance of the <see cref="KustoResponseParser"/> class. /// </summary> /// <param name="logger">ILogger object for logging.</param> /// <param name="outputBackendQuery">Outputs the backend query during parse.</param> /// <param name="metricsHistograms">The instance of the class to record metrics.</param> public KustoResponseParser(ILogger <KustoResponseParser> logger, bool outputBackendQuery, Metrics metricsHistograms) { Logger = logger; this.metricsHistograms = metricsHistograms; this.outputBackendQuery = outputBackendQuery; }
public void RemoveMetric(Metric v) { _service.RemoveMetric(v.ID); Metrics.Remove(v); v.Instance.Metrics.Remove(v); }
public void TearDown() { Metrics.Clear(); }
public MetricsTopicSource(Metrics metrics, Metrics.Types metricType) { this.metrics = metrics; this.metricType = metricType; }
private void LoadCurrentState() { var sources = _service.GetSources(); var instances = _service.GetInstances(); var metrics = _service.GetMetrics(); var groups = _service.GetGroups(); Sources.Edit(innerCache => { var items = sources.Select(x => new Source { ID = x.ID, Name = x.Name, Instances = new ObservableCollection <Instance>() }); innerCache.Clear(); innerCache.AddOrUpdate(items); innerCache.AddOrUpdate(_unknownSource); }); Instances.Edit(innerCache => { var items = instances.Select(x => { var source = Sources.Lookup((short)x.SourceID).ValueOr(() => _unknownSource); var instance = new Instance { ID = x.ID, Name = x.Name, Source = source, Metrics = new ObservableCollection <Metric>() }; source.Instances.Add(instance); return(instance); }); innerCache.Clear(); innerCache.AddOrUpdate(items); innerCache.AddOrUpdate(_unknownInstance); }); InstancesWithoutGroup.Edit(innerCache => { var idsInGroup = groups .SelectMany(x => x.Instances) .Distinct(); var idsWithoutGroup = instances .Select(x => x.ID) .Except(idsInGroup); var items = idsWithoutGroup.Select(id => Instances.Lookup(id).Value); innerCache.Clear(); innerCache.AddOrUpdate(items); }); Metrics.Edit(innerCache => { var items = metrics.Select(x => { var instance = Instances.Lookup(x.InstanceID).ValueOr(() => _unknownInstance); var metric = new Metric { ID = x.ID, Name = x.Name, Instance = instance, Aggregation = x.Aggregation }; instance.Metrics.Add(metric); return(metric); }); innerCache.Clear(); innerCache.AddOrUpdate(items); }); Groups.Edit(innerCache => { var items = groups.Select(x => new Group { ID = x.ID, IsDefault = x.IsDefault, Name = x.Name, Instances = new ObservableCollection <Instance>(x.Instances .Select(v => Instances.Lookup(v).ValueOrDefault()) .Where(v => v != null)) }); innerCache.Clear(); innerCache.AddOrUpdate(items); }); SourceItems.Edit(innerCache => { var itemsInGroup = Groups.Items .SelectMany( x => x.Instances, (g, i) => CreateSourceItem(i, g)) .ToList(); var itemsWithoutGroup = InstancesWithoutGroup.Items .Select(i => CreateSourceItem(i)); innerCache.Clear(); innerCache.AddOrUpdate(itemsInGroup); innerCache.AddOrUpdate(itemsWithoutGroup); }); }