Skip to content

Performance Monitoring

Giriş

Performance Monitoring (Performans İzleme), uygulamanın performans metriklerinin sürekli olarak izlenmesi ve analiz edilmesi sürecidir. .NET uygulamalarında performans sorunlarının tespiti, optimizasyon ve kapasite planlaması için kritik bir bileşendir.

Performance Monitoring'ın Önemi

  1. Performans Optimizasyonu
  2. Bottleneck tespiti
  3. Kaynak kullanımı analizi
  4. Response time takibi
  5. Throughput ölçümü

  6. Kullanıcı Deneyimi

  7. Uygulama yanıt süreleri
  8. Sayfa yükleme süreleri
  9. API latency
  10. Error rate

  11. Sistem Sağlığı

  12. CPU kullanımı
  13. Memory kullanımı
  14. Disk I/O
  15. Network trafiği

Performance Monitoring Araçları

  1. Application Insights
  2. Performans metrikleri
  3. Dependency tracking
  4. Exception monitoring
  5. Custom telemetri

  6. Prometheus + Grafana

  7. Time series veritabanı
  8. Zengin metrik toplama
  9. Güçlü görselleştirme
  10. Alerting

  11. New Relic

  12. APM (Application Performance Monitoring)
  13. Distributed tracing
  14. Real-time monitoring
  15. Custom dashboards

Performance Monitoring Kullanımı

  1. Application Insights Entegrasyonu

    // NuGet paketleri:
    // Microsoft.ApplicationInsights.AspNetCore
    // Microsoft.ApplicationInsights.PerfCounterCollector
    
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddApplicationInsightsTelemetryProcessor<CustomTelemetryProcessor>();
        }
    }
    
    public class CustomTelemetryProcessor : ITelemetryProcessor
    {
        private readonly ITelemetryProcessor _next;
    
        public CustomTelemetryProcessor(ITelemetryProcessor next)
        {
            _next = next;
        }
    
        public void Process(ITelemetry item)
        {
            if (item is RequestTelemetry request)
            {
                request.Properties["CustomProperty"] = "Value";
            }
            _next.Process(item);
        }
    }
    

  2. Prometheus Entegrasyonu

    // NuGet paketleri:
    // prometheus-net
    // prometheus-net.AspNetCore
    
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddPrometheusMetrics();
        }
    
        public void Configure(IApplicationBuilder app)
        {
            app.UseMetricServer();
            app.UseHttpMetrics();
        }
    }
    
    public class PerformanceMetrics
    {
        private readonly Counter _requestCounter;
        private readonly Histogram _responseTimeHistogram;
    
        public PerformanceMetrics()
        {
            _requestCounter = Metrics.CreateCounter("http_requests_total", "Total HTTP requests");
            _responseTimeHistogram = Metrics.CreateHistogram("http_response_time_seconds", "HTTP response time");
        }
    
        public void TrackRequest(string path, double duration)
        {
            _requestCounter.Inc();
            _responseTimeHistogram.Observe(duration, new[] { path });
        }
    }
    

  3. Custom Performance Monitoring

    public class PerformanceMonitor
    {
        private readonly ILogger _logger;
        private readonly Stopwatch _stopwatch;
    
        public PerformanceMonitor(ILogger<PerformanceMonitor> logger)
        {
            _logger = logger;
            _stopwatch = new Stopwatch();
        }
    
        public async Task<T> MonitorOperationAsync<T>(string operationName, Func<Task<T>> operation)
        {
            _stopwatch.Restart();
            try
            {
                var result = await operation();
                _stopwatch.Stop();
    
                _logger.LogInformation("Operation {OperationName} completed in {Duration}ms", 
                    operationName, _stopwatch.ElapsedMilliseconds);
    
                return result;
            }
            catch (Exception ex)
            {
                _stopwatch.Stop();
                _logger.LogError(ex, "Operation {OperationName} failed after {Duration}ms", 
                    operationName, _stopwatch.ElapsedMilliseconds);
                throw;
            }
        }
    }
    

  4. Resource Monitoring

    public class ResourceMonitor
    {
        private readonly ILogger _logger;
        private readonly PerformanceCounter _cpuCounter;
        private readonly PerformanceCounter _memoryCounter;
    
        public ResourceMonitor(ILogger<ResourceMonitor> logger)
        {
            _logger = logger;
            _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            _memoryCounter = new PerformanceCounter("Memory", "Available MBytes");
        }
    
        public void LogResourceUsage()
        {
            var cpuUsage = _cpuCounter.NextValue();
            var availableMemory = _memoryCounter.NextValue();
    
            _logger.LogInformation("CPU Usage: {CpuUsage}%, Available Memory: {AvailableMemory}MB", 
                cpuUsage, availableMemory);
        }
    }
    

Performance Monitoring Best Practices

  1. Metrik Tasarımı
  2. Anlamlı metrik isimleri
  3. Doğru metrik türleri
  4. Context bilgileri
  5. Sampling stratejileri

  6. Performans

  7. Hafif metrik toplama
  8. Batch işlemler
  9. Async operasyonlar
  10. Buffer yönetimi

  11. Güvenlik

  12. Hassas veri filtreleme
  13. Erişim kontrolü
  14. Data retention
  15. Audit logging

  16. Monitoring

  17. Alert kuralları
  18. Dashboard tasarımı
  19. Trend analizi
  20. Capacity planning

Mülakat Soruları

Temel Sorular

  1. Performance Monitoring nedir ve neden önemlidir?
  2. Cevap: Performance Monitoring, uygulamanın performans metriklerinin sürekli olarak izlenmesi ve analiz edilmesi sürecidir. Performans sorunlarının tespiti, optimizasyon ve kapasite planlaması için kritiktir.

  3. Popüler Performance Monitoring araçları nelerdir?

  4. Cevap:

    • Application Insights
    • Prometheus + Grafana
    • New Relic
    • Datadog
    • Dynatrace
  5. Performance Monitoring'ın temel bileşenleri nelerdir?

  6. Cevap:

    • Metrik toplama
    • Veri depolama
    • Görselleştirme
    • Alerting
    • Analiz
  7. APM nedir?

  8. Cevap: APM (Application Performance Monitoring), uygulama performansının end-to-end izlenmesi ve yönetilmesi için kullanılan araçlar ve teknikler bütünüdür.

  9. Bottleneck nedir?

  10. Cevap: Bottleneck, sistemin performansını sınırlayan ve darboğaz oluşturan bileşen veya kaynaktır.

Teknik Sorular

  1. Application Insights nasıl yapılandırılır?
  2. Cevap:

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddApplicationInsightsTelemetryProcessor<CustomTelemetryProcessor>();
        }
    }
    

  3. Prometheus metrikleri nasıl tanımlanır?

  4. Cevap:

    public class PerformanceMetrics
    {
        private readonly Counter _requestCounter;
        private readonly Histogram _responseTimeHistogram;
    
        public PerformanceMetrics()
        {
            _requestCounter = Metrics.CreateCounter("http_requests_total", "Total HTTP requests");
            _responseTimeHistogram = Metrics.CreateHistogram("http_response_time_seconds", "HTTP response time");
        }
    
        public void TrackRequest(string path, double duration)
        {
            _requestCounter.Inc();
            _responseTimeHistogram.Observe(duration, new[] { path });
        }
    }
    

  5. Custom performance monitoring nasıl yapılır?

  6. Cevap:

    public class PerformanceMonitor
    {
        private readonly ILogger _logger;
        private readonly Stopwatch _stopwatch;
    
        public PerformanceMonitor(ILogger<PerformanceMonitor> logger)
        {
            _logger = logger;
            _stopwatch = new Stopwatch();
        }
    
        public async Task<T> MonitorOperationAsync<T>(string operationName, Func<Task<T>> operation)
        {
            _stopwatch.Restart();
            try
            {
                var result = await operation();
                _stopwatch.Stop();
    
                _logger.LogInformation("Operation {OperationName} completed in {Duration}ms", 
                    operationName, _stopwatch.ElapsedMilliseconds);
    
                return result;
            }
            catch (Exception ex)
            {
                _stopwatch.Stop();
                _logger.LogError(ex, "Operation {OperationName} failed after {Duration}ms", 
                    operationName, _stopwatch.ElapsedMilliseconds);
                throw;
            }
        }
    }
    

  7. Resource monitoring nasıl yapılır?

  8. Cevap:

    public class ResourceMonitor
    {
        private readonly ILogger _logger;
        private readonly PerformanceCounter _cpuCounter;
        private readonly PerformanceCounter _memoryCounter;
    
        public ResourceMonitor(ILogger<ResourceMonitor> logger)
        {
            _logger = logger;
            _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            _memoryCounter = new PerformanceCounter("Memory", "Available MBytes");
        }
    
        public void LogResourceUsage()
        {
            var cpuUsage = _cpuCounter.NextValue();
            var availableMemory = _memoryCounter.NextValue();
    
            _logger.LogInformation("CPU Usage: {CpuUsage}%, Available Memory: {AvailableMemory}MB", 
                cpuUsage, availableMemory);
        }
    }
    

  9. Performance alerting nasıl yapılandırılır?

  10. Cevap:
    public class PerformanceAlert
    {
        private readonly ILogger _logger;
        private readonly double _threshold;
    
        public PerformanceAlert(ILogger<PerformanceAlert> logger, double threshold)
        {
            _logger = logger;
            _threshold = threshold;
        }
    
        public void CheckPerformance(double metricValue, string metricName)
        {
            if (metricValue > _threshold)
            {
                _logger.LogWarning("Performance alert: {MetricName} exceeded threshold. Value: {Value}", 
                    metricName, metricValue);
            }
        }
    }
    

İleri Seviye Sorular

  1. Performance Monitoring performans optimizasyonu nasıl yapılır?
  2. Cevap:

    • Hafif metrik toplama
    • Batch işlemler
    • Async operasyonlar
    • Buffer yönetimi
    • Sampling stratejileri
  3. Performance Monitoring güvenliği nasıl sağlanır?

  4. Cevap:

    • Hassas veri filtreleme
    • Erişim kontrolü
    • Data retention
    • Audit logging
    • Encryption
  5. Performance Monitoring ile capacity planning nasıl yapılır?

  6. Cevap:

    • Trend analizi
    • Resource utilization
    • Growth projection
    • Scaling strategies
    • Cost optimization
  7. Performance Monitoring ile distributed tracing nasıl entegre edilir?

  8. Cevap:

    • Correlation ID
    • Context propagation
    • Span ve trace yönetimi
    • End-to-end tracing
    • Performance analysis
  9. Performance Monitoring ile anomaly detection nasıl yapılır?

  10. Cevap:
    • Statistical analysis
    • Machine learning
    • Pattern recognition
    • Threshold optimization
    • Alert management