Beispiel #1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            try
            {
                using var connection = new SqlConnection(_connectionString);

                await connection.OpenAsync(cancellationToken);

                var command = connection.CreateCommand();
                command.CommandText = "SELECT COUNT(*) FROM HMR_SERVICE_AREA";

                var count = await command.ExecuteScalarAsync(cancellationToken);

                var jobCount = Convert.ToInt32(count) + 1; //one job per service area + one job for resending email

                var stats     = _monitoringApi.GetStatistics();
                var statsJson = JsonSerializer.Serialize(stats);

                if (stats.Servers > 0 && stats.Recurring >= jobCount)
                {
                    return(HealthCheckResult.Healthy(statsJson));
                }
                else
                {
                    return(HealthCheckResult.Unhealthy(statsJson));
                }
            }
            catch (Exception ex)
            {
                return(new HealthCheckResult(context.Registration.FailureStatus, exception: ex));
            }
        }
        public string Get()
        {
            data.AppendLine("# Help Servers Count ");
            data.AppendLine("hangfire_servers_count " + api.GetStatistics().Servers.ToString());
            data.AppendLine("# Help Deleted Jobs Count");
            data.AppendLine("hangfire_deleted_jobs_total_count " + api.GetStatistics().Deleted.ToString());
            data.AppendLine("# Help Enqueued Jobs Count");
            data.AppendLine("hangfire_enqueued_jobs_total_count " + api.GetStatistics().Enqueued.ToString());
            data.AppendLine("# Help Failed Jobs Count");
            data.AppendLine("hangfire_failed_jobs_total_count " + api.GetStatistics().Failed.ToString());
            data.AppendLine("# Help Processing Jobs Count");
            data.AppendLine("hangfire_processing_jobs_total_count " + api.GetStatistics().Processing.ToString());
            data.AppendLine("# Help Queues Count");
            data.AppendLine("hangfire_queues_count " + api.GetStatistics().Queues.ToString());
            data.AppendLine("# Help Recurring Jobs Count");
            data.AppendLine("hangfire_recurring_jobs_count " + api.GetStatistics().Recurring.ToString());
            data.AppendLine("# Help Scheduled Jobs Count");
            data.AppendLine("hangfire_scheduled_jobs_total_count " + api.GetStatistics().Scheduled.ToString());
            data.AppendLine("# Help Succeeded Jobs List Count");
            data.AppendLine("hangfire_succeeded_jobs_total_count " + api.GetStatistics().Succeeded.ToString());

            data.AppendLine("# Help Failed Jobs By Dates Count");
            foreach (var item in api.FailedByDatesCount())
            {
                data.AppendLine("hangfire_failed_jobs_by_dates_count" + "{key=" + "\"" + item.Key.ToShortDateString() + "\"} " + item.Value);
            }

            data.AppendLine("# Help Succeeded Jobs By Dates Count");
            foreach (var item in api.SucceededByDatesCount())
            {
                data.AppendLine("hangfire_succeeded_jobs_by_dates_count" + "{key=" + "\"" + item.Key.ToShortDateString() + "\"} " + item.Value);
            }

            data.AppendLine("# Help Hourly Failed Jobs Count");
            foreach (var item in api.HourlyFailedJobs())
            {
                data.AppendLine("hangfire_hourly_failed_jobs_count" + "{key=" + "\"" + item.Key + "\"} " + item.Value);
            }

            data.AppendLine("# Help Hourly Succeeded Jobs Count");
            foreach (var item in api.HourlySucceededJobs())
            {
                data.AppendLine("hangfire_hourly_succeeded_jobs_count" + "{key=" + "\"" + item.Key + "\"} " + item.Value);
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            return(data.ToString());
        }
        public void Get_Statistics_Test()
        {
            var statistice = _monitoring.GetStatistics();

            Assert.Equal(1, statistice.PublishedSucceeded);
            Assert.Equal(0, statistice.PublishedFailed);
            Assert.Equal(0, statistice.ReceivedSucceeded);
            Assert.Equal(1, statistice.ReceivedFailed);
        }
Beispiel #4
0
 private void AppendTotalJobCounts(StringBuilder data)
 {
     data.AppendLine("# Help Deleted Jobs Count");
     data.AppendLine($"hangfire_deleted_jobs_total_count {api.GetStatistics().Deleted}");
     data.AppendLine("# Help Enqueued Jobs Count");
     data.AppendLine($"hangfire_enqueued_jobs_total_count {api.GetStatistics().Enqueued}");
     data.AppendLine("# Help Failed Jobs Count");
     data.AppendLine($"hangfire_failed_jobs_total_count {api.GetStatistics().Failed}");
     data.AppendLine("# Help Processing Jobs Count");
     data.AppendLine($"hangfire_processing_jobs_total_count {api.GetStatistics().Processing}");
     data.AppendLine("# Help Recurring Jobs Count");
     data.AppendLine($"hangfire_recurring_jobs_count {api.GetStatistics().Recurring}");
     data.AppendLine("# Help Scheduled Jobs Count");
     data.AppendLine($"hangfire_scheduled_jobs_total_count {api.GetStatistics().Scheduled}");
     data.AppendLine("# Help Succeeded Jobs List Count");
     data.AppendLine($"hangfire_succeeded_jobs_total_count {api.GetStatistics().Succeeded}");
 }
        private async Task Worker(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    await Task.Delay(_samplingInterval);

                    var hangfireStats = _hangfireApi.GetStatistics();

                    _telemetryClient.TrackMetric(new MetricTelemetry(MetricPrefix + "-enqueued", hangfireStats.Enqueued));
                    _telemetryClient.TrackMetric(new MetricTelemetry(MetricPrefix + "-scheduled", hangfireStats.Scheduled));
                    _telemetryClient.TrackMetric(new MetricTelemetry(MetricPrefix + "-failed", hangfireStats.Failed));
                    _telemetryClient.TrackMetric(new MetricTelemetry(MetricPrefix + "-processing", hangfireStats.Processing));
                    _telemetryClient.TrackMetric(new MetricTelemetry(MetricPrefix + "-servers", hangfireStats.Servers));
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex, "Writing additional telemetry failed");
                }
            }
        }