/// <summary> /// /// </summary> /// <returns></returns> public StatisticsDto GetStatistics() { return(UseConnection(ctx => { var stats = new StatisticsDto(); var countByStates = ctx.Job.Find(_ => _.StateName != null) .GroupBy(x => x.StateName) .Select(k => new { StateName = k.Key, Count = k.Count() }) .AsEnumerable().ToDictionary(kv => kv.StateName, kv => kv.Count); int GetCountIfExists(string name) => countByStates.ContainsKey(name) ? countByStates[name] : 0; stats.Enqueued = GetCountIfExists(EnqueuedState.StateName); stats.Failed = GetCountIfExists(FailedState.StateName); stats.Processing = GetCountIfExists(ProcessingState.StateName); stats.Scheduled = GetCountIfExists(ScheduledState.StateName); stats.Servers = ctx.Server.Count(); stats.Succeeded = GetCountIfExists(SucceededState.StateName); stats.Deleted = GetCountIfExists(DeletedState.StateName); stats.Recurring = ctx.StateDataSet.Count(_ => _.Key == "recurring-jobs"); stats.Queues = _queueProviders .SelectMany(x => x.GetJobQueueMonitoringApi(ctx).GetQueues()) .Count(); return stats; })); }
public StatisticsDto GetStatistics() { var sql = $@" select count(""Id"") from {_pubName} where ""StatusName"" = N'Succeeded'; select count(""Id"") from {_recName} where ""StatusName"" = N'Succeeded'; select count(""Id"") from {_pubName} where ""StatusName"" = N'Failed'; select count(""Id"") from {_recName} where ""StatusName"" = N'Failed';"; var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql, transaction: DbTransaction)) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public StatisticsDto getStatisticsData(int userid) { using (var command = _context.Database.GetDbConnection().CreateCommand()) { StatisticsDto data = new StatisticsDto(); command.CommandText = "exec sp_getcountodisplay " + userid; _context.Database.OpenConnection(); using (var reader = command.ExecuteReader()) { var opensurveycount = reader.GetOrdinal("opensurvey"); var closedcount = reader.GetOrdinal("closedsurvey"); var draft = reader.GetOrdinal("draft"); var totalresponse = reader.GetOrdinal("totalresponse"); while (reader.Read()) { data = new StatisticsDto() { OpenSurveys = reader.GetInt32(opensurveycount), ClosedSurveys = reader.GetInt32(closedcount), DraftSurveys = reader.GetInt32(draft), TotalResponse = reader.GetInt32(totalresponse) }; } } return(data); } }
public StatisticsDto GetStatistics() { var states = Data.GetEnumeration <JobDto>() .Where(j => j.StateName != null) .GroupBy(j => j.StateName) .ToDictionary(j => j.Key, j => j.Count()); Func <string, int> getCountIfExists = name => states.ContainsKey(name) ? states[name] : 0; var succeded = CounterUtilities.GetCombinedCounter("stats:succeeded"); var deleted = CounterUtilities.GetCombinedCounter("stats:deleted"); var recurringJobs = Data.GetEnumeration <SetDto>().Count(c => c.Key == "recurring-jobs"); var servers = Data.GetEnumeration <Dto.ServerDto>().Count(); var stats = new StatisticsDto { Enqueued = getCountIfExists(EnqueuedState.StateName), Failed = getCountIfExists(FailedState.StateName), Processing = getCountIfExists(ProcessingState.StateName), Scheduled = getCountIfExists(ScheduledState.StateName), Servers = servers, Succeeded = succeded, Deleted = deleted, Recurring = recurringJobs }; return(stats); }
public StatisticsDto GetStatistics() { var sql = $@" set transaction isolation level read committed; select count(Id) from {_pubName} with (nolock) where StatusName = N'Succeeded'; select count(Id) from {_recName} with (nolock) where StatusName = N'Succeeded'; select count(Id) from {_pubName} with (nolock) where StatusName = N'Failed'; select count(Id) from {_recName} with (nolock) where StatusName = N'Failed';"; var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql, DbTransaction)) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public StatisticsDto GetStatistics() { var sql = string.Format(@" set transaction isolation level read committed; select count(Id) from [{0}].Published with (nolock) where StatusName = N'Succeeded'; select count(Id) from [{0}].Received with (nolock) where StatusName = N'Succeeded'; select count(Id) from [{0}].Published with (nolock) where StatusName = N'Failed'; select count(Id) from [{0}].Received with (nolock) where StatusName = N'Failed'; select count(Id) from [{0}].Published with (nolock) where StatusName in (N'Processing',N'Scheduled',N'Enqueued'); select count(Id) from [{0}].Received with (nolock) where StatusName in (N'Processing',N'Scheduled',N'Enqueued');", _options.Schema); var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql)) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); stats.PublishedProcessing = multi.ReadSingle <int>(); stats.ReceivedProcessing = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public StatisticsDto GetStatistics() { var sql = $"WITH " + $"C1 AS( SELECT COUNT(\"Id\") AS PublishedSucceeded FROM {_pubName} WHERE \"StatusName\" = N'Succeeded')," + $"C2 AS(SELECT COUNT(\"Id\") AS ReceivedSucceeded FROM {_recName} WHERE \"StatusName\" = N'Succeeded')," + $"C3 AS(SELECT COUNT(\"Id\") AS PublishedFailed FROM {_pubName} WHERE \"StatusName\" = N'Failed')," + $"C4 AS(SELECT COUNT(\"Id\") AS ReceivedFailed FROM {_recName} WHERE \"StatusName\" = N'Failed') " + $"SELECT * FROM C1,C2,C3,C4"; StatisticsDto statistics; using (var connection = new OracleConnection(_options.ConnectionString)) { statistics = connection.ExecuteReader(sql, reader => { var statisticsDto = new StatisticsDto(); while (reader.Read()) { statisticsDto.PublishedSucceeded = reader.GetInt32(0); statisticsDto.ReceivedSucceeded = reader.GetInt32(1); statisticsDto.PublishedFailed = reader.GetInt32(2); statisticsDto.ReceivedFailed = reader.GetInt32(3); } return(statisticsDto); }); } return(statistics); }
public StatisticsDto GetStatistics() { var sql = $@" SELECT ( SELECT COUNT(Id) FROM {_pubName} WHERE StatusName = N'Succeeded' ) AS PublishedSucceeded, ( SELECT COUNT(Id) FROM {_recName} WHERE StatusName = N'Succeeded' ) AS ReceivedSucceeded, ( SELECT COUNT(Id) FROM {_pubName} WHERE StatusName = N'Failed' ) AS PublishedFailed, ( SELECT COUNT(Id) FROM {_recName} WHERE StatusName = N'Failed' ) AS ReceivedFailed;"; using var connection = new SqlConnection(_options.ConnectionString); var statistics = connection.ExecuteReader(sql, reader => { var statisticsDto = new StatisticsDto(); while (reader.Read()) { statisticsDto.PublishedSucceeded = reader.GetInt32(0); statisticsDto.ReceivedSucceeded = reader.GetInt32(1); statisticsDto.PublishedFailed = reader.GetInt32(2); statisticsDto.ReceivedFailed = reader.GetInt32(3); } return(statisticsDto); }); return(statistics); }
public StatisticsDto GetStatistics() { return(UseConnection(redis => { var stats = new StatisticsDto(); var queues = redis.SetMembers(Redis.Prefix + "queues"); var Tasks = new Task[queues.Length + 8]; var batch = redis.CreateBatch(); Tasks[0] = batch.SetLengthAsync(Redis.Prefix + "servers").ContinueWith(x => stats.Servers = x.Result); Tasks[1] = batch.SetLengthAsync(Redis.Prefix + "queues").ContinueWith(x => stats.Queues = x.Result); Tasks[2] = batch.SortedSetLengthAsync(Redis.Prefix + "schedule").ContinueWith(x => stats.Scheduled = x.Result); Tasks[3] = batch.SortedSetLengthAsync(Redis.Prefix + "processing").ContinueWith(x => stats.Processing = x.Result); Tasks[4] = batch.StringGetAsync(Redis.Prefix + "stats:succeeded").ContinueWith(x => stats.Succeeded = long.Parse(x.Result == RedisValue.Null ? "0" : (string)x.Result)); Tasks[5] = batch.SortedSetLengthAsync(Redis.Prefix + "failed").ContinueWith(x => stats.Failed = x.Result); Tasks[6] = batch.StringGetAsync(Redis.Prefix + "stats:deleted").ContinueWith(x => stats.Deleted = long.Parse(x.Result == RedisValue.Null ? "0" : (string)x.Result)); Tasks[7] = batch.SortedSetLengthAsync(Redis.Prefix + "recurring-jobs").ContinueWith(x => stats.Recurring = x.Result); long QueueItems = 0; int i = 8; foreach (var queue in queues) { Tasks[i++] = batch.ListLengthAsync(String.Format(Redis.Prefix + "queue:{0}", queue)).ContinueWith(x => Interlocked.Add(ref QueueItems, x.Result)); } batch.Execute(); Task.WaitAll(Tasks); stats.Enqueued = QueueItems; return stats; })); }
public StatisticsDto GetStatistics() { return(UseConnection(connection => { var stats = new StatisticsDto(); var countByStates = connection.Job .Find(Query <JobDto> .NE(_ => _.StateName, null)) .GroupBy(x => x.StateName) .ToDictionary(x => x.Key, x => x.Count()); Func <string, int> getCountIfExists = name => countByStates.ContainsKey(name) ? countByStates[name] : 0; stats.Enqueued = getCountIfExists(EnqueuedState.StateName); stats.Failed = getCountIfExists(FailedState.StateName); stats.Processing = getCountIfExists(ProcessingState.StateName); stats.Scheduled = getCountIfExists(ScheduledState.StateName); stats.Servers = connection.Server.Count(); stats.Succeeded = connection.Counter.Count(Query <CounterDto> .EQ(_ => _.Key, "stats:succeeded")); stats.Deleted = connection.Counter.Count(Query <CounterDto> .EQ(_ => _.Key, "stats:deleted")); stats.Recurring = connection.Set.Count(Query <SetDto> .EQ(_ => _.Key, "recurring-jobs")); stats.Queues = _queueProviders .SelectMany(x => x.GetJobQueueMonitoringApi(connection).GetQueues()) .Count(); return stats; })); }
public StatisticsDto GetStatistics() { var jobs = _repository.Set <JobModel>(); Func <string, int> count = name => { var counters = _repository.Set <CounterModel>(); return(counters.Where(v => v.Key == name).Sum(s => s.Value)); }; var stats = new StatisticsDto { Enqueued = jobs.Count(v => v.State?.Name == EnqueuedState.StateName), Failed = jobs.Count(v => v.State?.Name == FailedState.StateName), Processing = jobs.Count(v => v.State?.Name == ProcessingState.StateName), Scheduled = jobs.Count(v => v.State?.Name == ScheduledState.StateName), Servers = _repository.Set <ServerModel>().Count(), Succeeded = count("stats:succeeded"), Deleted = count("stats:deleted"), Recurring = _repository.Set <SetModel>().Count(v => v.Key == "recurring-jobs"), Queues = _storage.MonitoringApi.GetQueues().Count() }; return(stats); }
public void GetStatistics_ShouldReturnFailedCount() { const int expectedFailedCount = 2; StatisticsDto result = null; _storage.UseSession(connection => { for (var i = 0; i < 2; i++) { connection.Insert(new _Job { InvocationData = string.Empty, Arguments = string.Empty, CreatedAt = connection.Storage.UtcNow, StateName = "Failed" }); } connection.Flush(); result = _sut.GetStatistics(); }); Assert.Equal(expectedFailedCount, result.Failed); }
public StatisticsDto GetStatistics() { var sql = string.Format(@" select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Succeeded'; select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Succeeded'; select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Failed'; select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Failed';", _options.Schema); var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql)) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public void ExportHangfireStatistics_PublishesToPrometheus() { var expectedStatistics = new StatisticsDto() { Failed = 1, Deleted = 2, Enqueued = 3, Processing = 4, Recurring = 5, Scheduled = 6, Succeeded = 7 }; var expectedRetrySet = new HashSet <string> { "job1", "job2", "job3" }; _mockMonitoringApi.Setup(x => x.GetStatistics()).Returns(expectedStatistics); _mockStorageConnection.Setup(x => x.GetAllItemsFromSet("retries")).Returns(expectedRetrySet); _exporter.ExportHangfireStatistics(); var prometheusContent = GetPrometheusContent(); ExpectedMetricStrings(expectedStatistics, expectedRetrySet) .ForEach(ms => prometheusContent.Should().Contain(ms)); }
public void GetStatistics_ShouldReturnScheduledCount() { const int expectedScheduledCount = 3; StatisticsDto result = null; _storage.UseStatelessSession(connection => { for (var i = 0; i < 3; i++) { connection.Insert(new _Job { InvocationData = string.Empty, CreatedAt = connection.Storage.UtcNow, Arguments = string.Empty, StateName = "Scheduled" }); } //does nothing result = _sut.GetStatistics(); }); Assert.Equal(expectedScheduledCount, result.Scheduled); }
public StatisticsDto GetStatistics() { var sqlBuilder = new StringBuilder(); sqlBuilder.AppendLine("PRAGMA read_uncommitted = 1;") .AppendFormat("select count(`Id`) from `{0}` where `StatusName` = 'Succeeded';", _published) .AppendLine() .AppendFormat("select count(`Id`) from `{0}` where `StatusName` = 'Succeeded';", _received) .AppendLine() .AppendFormat("select count(`Id`) from `{0}` where `StatusName` = 'Failed';", _published) .AppendLine() .AppendFormat("select count(`Id`) from `{0}` where `StatusName` = 'Failed';", _received); var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sqlBuilder.ToString())) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public StatisticsDto GetStatistics() { var sql = string.Format(@" set transaction isolation level read committed; select count(Id) from `{0}.published` where StatusName = N'Succeeded'; select count(Id) from `{0}.received` where StatusName = N'Succeeded'; select count(Id) from `{0}.published` where StatusName = N'Failed'; select count(Id) from `{0}.received` where StatusName = N'Failed';", _prefix); var statistics = UseConnection(connection => { var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql)) { stats.PublishedSucceeded = multi.ReadSingle <int>(); stats.ReceivedSucceeded = multi.ReadSingle <int>(); stats.PublishedFailed = multi.ReadSingle <int>(); stats.ReceivedFailed = multi.ReadSingle <int>(); } return(stats); }); return(statistics); }
public StatisticsDto GetStatistics() { var sql = $"SELECT (SELECT COUNT(Id) FROM `{_pubName}` WHERE `StatusName` = 'Succeeded') AS PublishedSucceeded," + $" (SELECT COUNT(Id) FROM `{_recName}` WHERE `StatusName` = 'Succeeded') AS ReceivedSucceeded," + $" (SELECT COUNT(Id) FROM `{_pubName}` WHERE `StatusName` = 'Failed') AS PublishedFailed," + $" (SELECT COUNT(Id) FROM `{_recName}` WHERE `StatusName` = 'Failed') AS ReceivedFailed;"; StatisticsDto statistics; using (var connection = SqliteFactory.Instance.CreateConnection()) { connection.ConnectionString = _options.ConnectionString; statistics = connection.ExecuteReader(sql, reader => { var statisticsDto = new StatisticsDto(); while (reader.Read()) { statisticsDto.PublishedSucceeded = reader.GetInt32(0); statisticsDto.ReceivedSucceeded = reader.GetInt32(1); statisticsDto.PublishedFailed = reader.GetInt32(2); statisticsDto.ReceivedFailed = reader.GetInt32(3); } return(statisticsDto); }); } return(statistics); }
public void GetItDone() { var txtData = new TextData(); var installationId = "f113051f-ef10-4969-a2b1-e3c890506b4e"; var monitorNameFile = "SenseLogFileParserMonitor"; var monitorNameStats = "SenseStatisticsMonitor"; var date = DateTime.Now.AddMonths(-12); var gjallarhornDb = new GjallarhornDb(FileSystem.Singleton); gjallarhornDb.EnsureMonitorTableExists(monitorNameFile); gjallarhornDb.EnsureMonitorTableExists(monitorNameStats); Random random = new Random(); while (date < DateTime.Now) { date = date.AddHours(1); var dto = new FileMinerDto(); dto.LicenseSerialNo = "(fake LICENCE)"; dto.CollectionDateUtc = date; dto.IsMonthly = false; var data = new StatisticsDto { LogFileMinerData = dto, CollectionDateUtc = dto.CollectionDateUtc }; data.QLikSenseCalInfo = JsonConvert.DeserializeObject <QLikSenseCalInfo>(txtData.GetCalInfo()); data.InstallationId = "(fake)_" + installationId; dto.TotalUniqueActiveAppsList = new Dictionary <string, int>(); gjallarhornDb.SaveMonitorData(monitorNameFile, JsonConvert.SerializeObject(data)); if (date.Hour == 0) { var dtoDay = new FileMinerDto(); dtoDay.LicenseSerialNo = "(fake)"; dtoDay.CollectionDateUtc = date; dto.TotalUniqueActiveApps = random.Next(100); dto.TotalUniqueActiveUsers = random.Next(55); dto.SessionLengthAvgInMinutes = random.Next(100); dto.SessionLengthMedInMinutes = random.Next(50); var dataDay = new StatisticsDto { LogFileMinerData = dtoDay, CollectionDateUtc = dtoDay.CollectionDateUtc }; dataDay.InstallationId = "(fake)_" + installationId; dtoDay.TotalUniqueActiveAppsList = new Dictionary <string, int>(); dataDay.QlikSenseMachineInfos = JsonConvert.DeserializeObject <List <QlikSenseMachineInfo> >(txtData.GetMachineInfo()); dataDay.QlikSenseServiceInfo = JsonConvert.DeserializeObject <List <QlikSenseServiceInfo> >(txtData.GetServiceInfo()); dataDay.QlikSenseQrsAbout = JsonConvert.DeserializeObject <QlikSenseQrsAbout>(txtData.GetQrsAbout()); dataDay.QlikSenseAppListShort = JsonConvert.DeserializeObject <List <QlikSenseAppListShort> >(txtData.GetAppList()); gjallarhornDb.SaveMonitorData(monitorNameStats, JsonConvert.SerializeObject(dataDay)); } } }
public StatisticsDto GetStatistics() { return(UseConnection(redis => { var stats = new StatisticsDto(); var queues = redis.GetAllItemsFromSet("hangfire:queues"); using (var pipeline = redis.CreatePipeline()) { pipeline.QueueCommand( x => x.GetSetCount("hangfire:servers"), x => stats.Servers = x); pipeline.QueueCommand( x => x.GetSetCount("hangfire:queues"), x => stats.Queues = x); pipeline.QueueCommand( x => x.GetSortedSetCount("hangfire:schedule"), x => stats.Scheduled = x); pipeline.QueueCommand( x => x.GetSortedSetCount("hangfire:processing"), x => stats.Processing = x); pipeline.QueueCommand( x => x.GetValue("hangfire:stats:succeeded"), x => stats.Succeeded = long.Parse(x ?? "0")); pipeline.QueueCommand( x => x.GetSortedSetCount("hangfire:failed"), x => stats.Failed = x); pipeline.QueueCommand( x => x.GetValue("hangfire:stats:deleted"), x => stats.Deleted = long.Parse(x ?? "0")); pipeline.QueueCommand( x => x.GetSortedSetCount("hangfire:recurring-jobs"), x => stats.Recurring = x); foreach (var queue in queues) { var queueName = queue; pipeline.QueueCommand( x => x.GetListCount(String.Format("hangfire:queue:{0}", queueName)), x => stats.Enqueued += x); } pipeline.Flush(); } return stats; })); }
public StatisticsDto GetStatistics() { StatisticsDto resultStats = new StatisticsDto(); IMemcachedClient client = this.GetMemcachedClient(); ServerStats stats = client.Stats(); return(resultStats); }
public ActionResult Statistics() { StatisticsDto st = new StatisticsDto { HasMost = db.HasMost(), PriceSum = db.PriceSum(), Weightest = db.Weightest(), WeightSum = db.WeightSum() }; return(Json(st, JsonRequestBehavior.AllowGet)); }
public StatisticsDto GetStatistics() { var stats = new StatisticsDto { PublishedSucceeded = LiteDBStorage.PublishedMessages.Count(x => x.StatusName == StatusName.Succeeded), ReceivedSucceeded = LiteDBStorage.ReceivedMessages.Count(x => x.StatusName == StatusName.Succeeded), PublishedFailed = LiteDBStorage.PublishedMessages.Count(x => x.StatusName == StatusName.Failed), ReceivedFailed = LiteDBStorage.ReceivedMessages.Count(x => x.StatusName == StatusName.Failed) }; return(stats); }
public async Task <HttpResponseMessage> GetStatisticsAsync() { var id = userIdentityService.GetUserId(); StatisticsDto statistics = await taskService.GetUserStatisticsAsync(id); if (statistics == null) { const string errorMessage = "No user with this id in database."; return(Request.CreateResponse(HttpStatusCode.NoContent, errorMessage)); } return(Request.CreateResponse(HttpStatusCode.OK, statistics)); }
public StatisticsDto GetStatistics() { return(UseConnection(connection => { var sql = $@" SELECT ""statename"" ""State"", COUNT(""id"") ""Count"" FROM ""{_options.SchemaName}"".""job"" WHERE ""statename"" IS NOT NULL GROUP BY ""statename""; SELECT COUNT(*) FROM ""{_options.SchemaName}"".""server""; SELECT SUM(""value"") FROM ""{_options.SchemaName}"".""counter"" WHERE ""key"" = 'stats:succeeded'; SELECT SUM(""value"") FROM ""{_options.SchemaName}"".""counter"" WHERE ""key"" = 'stats:deleted'; SELECT COUNT(*) FROM ""{_options.SchemaName}"".""set"" WHERE ""key"" = 'recurring-jobs'; "; var stats = new StatisticsDto(); using (var multi = connection.QueryMultiple(sql)) { var countByStates = multi.Read().ToDictionary(x => x.State, x => x.Count); long GetCountIfExists(string name) => countByStates.ContainsKey(name) ? countByStates[name] : 0; stats.Enqueued = GetCountIfExists(EnqueuedState.StateName); stats.Failed = GetCountIfExists(FailedState.StateName); stats.Processing = GetCountIfExists(ProcessingState.StateName); stats.Scheduled = GetCountIfExists(ScheduledState.StateName); stats.Servers = multi.Read <long>().Single(); stats.Succeeded = multi.Read <long?>().SingleOrDefault() ?? 0; stats.Deleted = multi.Read <long?>().SingleOrDefault() ?? 0; stats.Recurring = multi.Read <long>().Single(); } stats.Queues = _queueProviders .SelectMany(x => x.GetJobQueueMonitoringApi(connection).GetQueues()) .Count(); return stats; })); }
private void CheckMontlySending(int logMonth) { var db = new GjallarhornDb(FileSystem.Singleton); //var logMinerData = new FileMinerDto(); //logMinerData.TotalUniqueActiveAppsList = new Dictionary<string,int>(); //logMinerData.TotalUniqueActiveUsersList = new Dictionary<string, int>(); //for (int i = 0; i < 100; i++) //{ // logMinerData.TotalUniqueActiveAppsList.Add(Guid.NewGuid().ToString(),1); // logMinerData.TotalUniqueActiveUsersList.Add(Guid.NewGuid().ToString(), 1); //} //db.AddToMontlyStats(logMinerData.TotalUniqueActiveAppsList,2019 , 5, MontlyStatsType.Apps); //db.AddToMontlyStats(logMinerData.TotalUniqueActiveUsersList, 2019, 5, MontlyStatsType.Users); var monthlyDebug = Settings.GetBool($"{MonitorName}.MonthlyDebug", false); var currMonthDb = db.CurrentMontlyRunInDb(); if ((currMonthDb < 0 || currMonthDb == logMonth) && monthlyDebug == false) { return; } //for sending debug every other day. if (DateTime.Now.Day % 2 == 0 && monthlyDebug) { return; } if (monthlyDebug && _debugMontlyDaySent == DateTime.Now.Day) { return; } var data = new StatisticsDto { LogFileMinerData = new FileMinerDto(), CollectionDateUtc = DateTime.UtcNow, InstallationId = _installationId }; data.LogFileMinerData.LicenseSerialNo = _licenseSerialNr; data.LogFileMinerData.IsMonthly = true; data.LogFileMinerData.TotalUniqueActiveApps = db.GetToMontlyStats(MontlyStatsType.Apps); data.LogFileMinerData.TotalUniqueActiveUsers = db.GetToMontlyStats(MontlyStatsType.Users); Notify($"{MonitorName} has analyzed the following system montly", new List <string> { JsonConvert.SerializeObject(data, Formatting.Indented) }, "-1"); db.ResetMontlyDbTable(); _debugMontlyDaySent = DateTime.Now.Day; }
public StatisticsDto GetStatistics(string id, DateRangeDto dataRange) { var expendirues = _expenditureRepository.GetExpendituresOfUserFromRange(id, dataRange.From, dataRange.To); var statisticsDto = new StatisticsDto { ExpidituresCount = expendirues.Count, SumOfExpenditures = expendirues.Sum(x => x.Amount), MostExpensiveExpenditures = _mapper.Map <List <ExpenditureDto> >(expendirues.OrderByDescending(x => x.Amount).Take(NUMBER_OF_MOST_EXPENSIVE_EXPENDITURES).ToList()) }; return(statisticsDto); }
public StatisticsDto GetStatistics() { var connection = GetConnection(); var stats = new StatisticsDto { PublishedSucceeded = connection.PublishedMessages.Count(x => x.StatusName == StatusName.Succeeded), ReceivedSucceeded = connection.ReceivedMessages.Count(x => x.StatusName == StatusName.Succeeded), PublishedFailed = connection.PublishedMessages.Count(x => x.StatusName == StatusName.Failed), ReceivedFailed = connection.ReceivedMessages.Count(x => x.StatusName == StatusName.Failed) }; return(stats); }
public StatisticsDto GetStatistics() { return(UseConnection(redis => { var stats = new StatisticsDto(); var queues = redis.SetMembers(_storage.GetRedisKey("queues")); var pipeline = redis.CreateBatch(); var tasks = new Task[queues.Length + 8]; tasks[0] = pipeline.SetLengthAsync(_storage.GetRedisKey("servers")) .ContinueWith(x => stats.Servers = x.Result, ContinuationOptions); tasks[1] = pipeline.SetLengthAsync(_storage.GetRedisKey("queues")) .ContinueWith(x => stats.Queues = x.Result, ContinuationOptions); tasks[2] = pipeline.SortedSetLengthAsync(_storage.GetRedisKey("schedule")) .ContinueWith(x => stats.Scheduled = x.Result, ContinuationOptions); tasks[3] = pipeline.SortedSetLengthAsync(_storage.GetRedisKey("processing")) .ContinueWith(x => stats.Processing = x.Result, ContinuationOptions); tasks[4] = pipeline.StringGetAsync(_storage.GetRedisKey("stats:succeeded")) .ContinueWith(x => stats.Succeeded = long.Parse(x.Result.HasValue ? (string)x.Result: "0"), ContinuationOptions); tasks[5] = pipeline.SortedSetLengthAsync(_storage.GetRedisKey("failed")) .ContinueWith(x => stats.Failed = x.Result, ContinuationOptions); tasks[6] = pipeline.StringGetAsync(_storage.GetRedisKey("stats:deleted")) .ContinueWith(x => stats.Deleted = long.Parse(x.Result.HasValue ? (string)x.Result : "0"), ContinuationOptions); tasks[7] = pipeline.SortedSetLengthAsync(_storage.GetRedisKey("recurring-jobs")) .ContinueWith(x => stats.Recurring = x.Result, ContinuationOptions); var enqueued = 0L; var i = 8; foreach (var queue in queues) { tasks[i++] = pipeline.ListLengthAsync(_storage.GetRedisKey($"queue:{queue}")) .ContinueWith(x => Interlocked.Add(ref enqueued, x.Result), ContinuationOptions); } pipeline.Execute(); pipeline.WaitAll(tasks); stats.Enqueued = enqueued; return stats; })); }
public StatisticsDto GetStatistics() { const string sql = @" SELECT statename ""State"", COUNT(*) ""Count"" FROM job WHERE statename IS NOT NULL GROUP BY statename; SELECT COUNT(*) FROM server; SELECT SUM(value) FROM counter WHERE key = 'stats:succeeded'; SELECT SUM(value) FROM counter WHERE key = 'stats:deleted'; SELECT COUNT(*) FROM set WHERE key = 'recurring-jobs'; "; var stats = new StatisticsDto(); using (var connectionHolder = _connectionProvider.AcquireConnection()) using (var gridReader = connectionHolder.Connection.QueryMultiple(sql)) { var countByStates = gridReader.Read().ToDictionary(x => x.State, x => x.Count); long GetCountIfExists(string name) => countByStates.ContainsKey(name) ? countByStates[name] : 0; stats.Enqueued = GetCountIfExists(EnqueuedState.StateName); stats.Failed = GetCountIfExists(FailedState.StateName); stats.Processing = GetCountIfExists(ProcessingState.StateName); stats.Scheduled = GetCountIfExists(ScheduledState.StateName); stats.Servers = gridReader.Read <long>().Single(); stats.Succeeded = gridReader.Read <long?>().SingleOrDefault() ?? 0; stats.Deleted = gridReader.Read <long?>().SingleOrDefault() ?? 0; stats.Recurring = gridReader.Read <long>().Single(); } stats.Queues = GetQueues().Count(); return(stats); }
public StatisticsDto GetStatistics() { StatisticsDto resultStats = new StatisticsDto(); IMemcachedClient client = this.GetMemcachedClient(); ServerStats stats = client.Stats(); return resultStats; }