public RealtimeUserCountResponse[] GetEndpointsRealtimeUserCount(int secondsBefore, int?size)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddDateRangeQuery(
                DateTime.Now.AddSeconds(-secondsBefore),
                DateTime.Now,
                f => f.Timestamp)
                        .Build();

            var aggregation = LogElasticsearchRepository.CreateAggregationBuilder()
                              .AddContainer()
                              .AddTermsAggregation("endpoints", f => f.Endpoint, size)
                              .Build()
                              .Build();

            var request = LogElasticsearchRepository.CreateSearchBuilder()
                          .SetSize(0)
                          .AddQuery(query)
                          .AddAggregation(aggregation)
                          .Build();

            var result = _LogElasticsearchRepository.Search(request);

            var buckets = result.Aggs.Terms("endpoints").Buckets;

            var list = (from b in buckets
                        select new RealtimeUserCountResponse
            {
                Endpoint = b.Key,
                UserCount = (long)b.DocCount / secondsBefore
            }).ToArray();

            return(list);
        }
Beispiel #2
0
        public string[] GetUsers(string endpoint, string companyName, string username, int?size)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddMatchPhraseQuery(companyName, f => f.CompanyName)
                        .AddPrefixMatchQuery(username, f => f.Username)
                        .AddMatchPhraseQuery(endpoint, f => f.Endpoint)
                        .Build();

            var aggregation = LogElasticsearchRepository.CreateAggregationBuilder()
                              .AddContainer()
                              .AddTermsAggregation("users", f => f.Username, size)
                              .Build()
                              .Build();

            var request = LogElasticsearchRepository.CreateSearchBuilder()
                          .SetSize(0)
                          .AddQuery(query)
                          .AddAggregation(aggregation)
                          .Build();

            var result = _LogElasticsearchRepository.Search(request);

            var buckets = result.Aggs.Terms("users").Buckets;

            var list = (from b in buckets select b.Key).ToArray();

            return(list);
        }
        public MetricsResponse[] GetEndpointMetrics(string companyName, string username, int?size, bool?ascending, DateTime?after, DateTime?before)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddDateRangeQuery(after, before, f => f.Timestamp)
                        .AddMatchPhraseQuery(companyName, f => f.CompanyName)
                        .AddMatchPhraseQuery(username, f => f.Username)
                        .Build();

            var aggregation = LogElasticsearchRepository.CreateAggregationBuilder()
                              .AddContainer()
                              .AddTermsAggregation("endpoints", f => f.Endpoint, size, "average-response-time", ascending)
                              .AddSubAggregation()
                              .AddContainer()
                              .AddMinAggregation("min-response-time", f => f.ResponseTime)
                              .Build()
                              .AddContainer()
                              .AddAverageAggregation("average-response-time", f => f.ResponseTime)
                              .Build()
                              .AddContainer()
                              .AddMaxAggregation("max-response-time", f => f.ResponseTime)
                              .Build()
                              .FinishSubAggregation()
                              .Build()
                              .Build();

            var request = LogElasticsearchRepository.CreateSearchBuilder()
                          .SetSize(0)
                          .AddQuery(query)
                          .AddAggregation(aggregation)
                          .Build();

            var result = _LogElasticsearchRepository.Search(request);

            var buckets = result.Aggs.Terms("endpoints").Buckets;

            var list = (from b in buckets
                        select new MetricsResponse
            {
                Key = b.Key,
                NumberOfRequests = (long)b.DocCount,
                MinResponseTime = (double)b.Min("min-response-time").Value,
                AverageResponseTime = (double)b.Average("average-response-time").Value,
                MaxResponseTime = (double)b.Max("max-response-time").Value,
            }).ToArray();

            return(list);
        }
        public long GetRealtimeUserCount(int secondsBefore)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddDateRangeQuery(
                DateTime.Now.AddSeconds(-secondsBefore),
                DateTime.Now,
                f => f.Timestamp)
                        .Build();

            var request = LogElasticsearchRepository.CreateCountBuilder()
                          .AddQuery(query)
                          .Build();

            var result = _LogElasticsearchRepository.Count(request);

            var count = result.Count / secondsBefore;

            return(count);
        }
Beispiel #5
0
        public HistogramResponse[] GetResponseTimesHistogram(string endpoint, TimeSpan interval, DateTime?after, DateTime?before)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddDateRangeQuery(after, before, f => f.CompanyName)
                        .AddMatchPhraseQuery(endpoint, f => f.Endpoint)
                        .Build();

            var aggregation = LogElasticsearchRepository.CreateAggregationBuilder()
                              .AddContainer()
                              .AddDateHistogram("histogram", f => f.Timestamp, interval)
                              .AddSubAggregation()
                              .AddContainer()
                              .AddAverageAggregation("average-response-time", f => f.ResponseTime)
                              .Build()
                              .FinishSubAggregation()
                              .Build()
                              .Build();

            var request = LogElasticsearchRepository.CreateSearchBuilder()
                          .SetSize(0)
                          .AddQuery(query)
                          .AddAggregation(aggregation)
                          .Build();

            var result = _LogElasticsearchRepository.Search(request);

            var buckets = result.Aggs.DateHistogram("histogram").Buckets;

            var list = (from b in buckets
                        select new HistogramResponse
            {
                Timestamp = b.Date,
                NumberOfRequests = b.DocCount,
                Average = (double)b.Average("average-response-time").Value
            }).ToArray();

            return(list);
        }
        public MetricsResponse GetSingleMetric(string companyName, string username, string endpoint, DateTime?after, DateTime?before)
        {
            var query = LogElasticsearchRepository.CreateQueryBuilder()
                        .AddDateRangeQuery(after, before, f => f.Timestamp)
                        .AddMatchPhraseQuery(endpoint, f => f.Endpoint)
                        .AddMatchPhraseQuery(companyName, f => f.CompanyName)
                        .AddMatchPhraseQuery(username, f => f.Username)
                        .Build();

            var aggregation = LogElasticsearchRepository.CreateAggregationBuilder()
                              .AddContainer()
                              .AddMinAggregation("min-response-time", f => f.ResponseTime)
                              .Build()
                              .AddContainer()
                              .AddAverageAggregation("average-response-time", f => f.ResponseTime)
                              .Build()
                              .AddContainer()
                              .AddMaxAggregation("max-response-time", f => f.ResponseTime)
                              .Build()
                              .Build();

            var request = LogElasticsearchRepository.CreateSearchBuilder()
                          .SetSize(0)
                          .AddQuery(query)
                          .AddAggregation(aggregation)
                          .Build();

            var result = _LogElasticsearchRepository.Search(request);

            return(new MetricsResponse
            {
                NumberOfRequests = result.HitsMetaData.Total,
                MinResponseTime = (double)result.Aggs.Min("min-response-time").Value,
                AverageResponseTime = (double)result.Aggs.Average("average-response-time").Value,
                MaxResponseTime = (double)result.Aggs.Max("max-response-time").Value,
            });
        }