Beispiel #1
0
        private async Task <List <AppMetric> > GetDbAppMetricsAsync()
        {
            List <AppMetric> dbMetrics =
                new List <AppMetric>();

            using (NpgsqlConnection conn = await OpenDbConnectionAsync(ConnectionString))
                using (NpgsqlCommand cmd = new NpgsqlCommand($"SELECT * from {TestOptions.DefaultMapping.MetricsTableName}", conn))
                {
                    using (NpgsqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (await rdr.ReadAsync())
                        {
                            AppMetricId mId = new AppMetricId(
                                rdr.GetString(rdr.GetOrdinal("metric_id")),
                                rdr.GetString(rdr.GetOrdinal("metric_category"))
                                );

                            AppMetric metric = new AppMetric(mId,
                                                             rdr.GetInt64(rdr.GetOrdinal("metric_value")));

                            dbMetrics.Add(metric);
                        }
                    }

                    await conn.CloseAsync();
                }

            return(dbMetrics);
        }
Beispiel #2
0
 public AppMetric QueryMetric(AppMetricId metricId)
 {
     return(AppMetricsCollection.JoinQueryMetric(metricId,
                                                 mTaskBuffer,
                                                 mTaskPoller,
                                                 mTaskQueueConsumer,
                                                 mTaskResultQueue,
                                                 mExecutionPerfMon,
                                                 AppMetricsCollection.JoinProviders(mWorkers)));
 }
        public long SumMetricValues(AppMetricsCollection[] collections, AppMetricId metricId)
        {
            long value = 0;

            foreach (AppMetricsCollection col in collections)
            {
                foreach (AppMetric m in col.CollectMetrics())
                {
                    if (m.Id.Equals(metricId))
                    {
                        value += m.Value;
                        break;
                    }
                }
            }

            return(value);
        }
        public void Test_CanCreateAppMetricsCollection_FromAppMetricIds_SpecificAppIds()
        {
            AppMetricId[] expectedMetricIds = new AppMetricId[]
            {
                AppMetricId.BufferMaxCount,
                AppMetricId.BufferMinCount,
                AppMetricId.BufferTimesEmptied,
                AppMetricId.BufferTimesFilled,
                AppMetricId.ListenerNotificationWaitTimeoutCount,
                AppMetricId.ListenerReconnectCount,
                AppMetricId.ListenerTaskNotificationCount
            };

            AppMetricsCollection metrics = new AppMetricsCollection(expectedMetricIds);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetricIds,
                                                             metrics);
        }
        public void Test_CanJoinWith()
        {
            Faker faker  = new Faker();
            long  value1 = faker.Random.Long(1, 1000);
            long  value2 = faker.Random.Long(1, 1000);

            AppMetricId metricId = faker.PickRandom(AppMetricId.BuiltInAppMetricIds);

            AppMetric metric1 = new AppMetric(metricId,
                                              value1);
            AppMetric metric2 = new AppMetric(metricId,
                                              value2);

            AppMetric metric = metric1.JoinWith(metric2);

            Assert.AreEqual(value1 + value2, metric.Value);
            Assert.AreNotSame(metric, metric1);
            Assert.AreNotSame(metric, metric2);
        }
Beispiel #6
0
 public AppMetric QueryMetric(AppMetricId metricId)
 {
     return(mMetrics.QueryMetric(metricId));
 }
 public static AppMetric RandomAppMetric(this Faker faker, AppMetricId id,
                                         long minValue = 0,
                                         long maxValue = long.MaxValue)
 {
     return(new AppMetric(id, faker.Random.Long(minValue, maxValue)));
 }
 public AppMetric QueryMetric(AppMetricId metricId)
 {
     return(AppMetricsCollection.JoinQueryMetric(metricId,
                                                 mMetrics,
                                                 mNotificationListener));
 }