MetircsCollector.cs 634 B

12345678910111213141516171819202122232425
  1. using System.Collections.Concurrent;
  2. namespace AipGateway.AIP.Service.Metrics
  3. {
  4. public class MetircsCollector
  5. {
  6. private readonly ConcurrentDictionary<string, long> _metrics = new ConcurrentDictionary<string, long>();
  7. public void Increment(string metricName)
  8. {
  9. if (!_metrics.ContainsKey(metricName))
  10. {
  11. _metrics.TryAdd(metricName, 1);
  12. return;
  13. }
  14. _metrics[metricName]++;
  15. }
  16. public long GetValue(string metricName)
  17. {
  18. return _metrics.GetValueOrDefault(metricName, 0);
  19. }
  20. }
  21. }