snyder
metrics library for C++11
include/snyder/metrics_registry.h
00001 
00008 #ifndef INCLUDE_SNYDER_H_
00009 #define INCLUDE_SNYDER_H_
00010 
00011 #include <string>
00012 #include <map>
00013 #include <mutex>
00014 
00015 #include "snyder/version.h"
00016 
00017 namespace Snyder {
00018 
00024   static const std::string VERSION = SNYDER_VERSION;
00025 
00029   typedef std::map<std::string, uint64_t> MetricsStore;
00033   typedef struct MetricsSnapshot {
00037     MetricsStore counters;
00041     MetricsStore gauges;
00042   } MetricsSnapshot;
00043 
00048   class MetricsRegistry
00049   {
00050     public:
00051       MetricsRegistry();
00052       ~MetricsRegistry();
00053 
00054       // generic methods
00055       void Reset();
00056       MetricsSnapshot Snapshot();
00057 
00058       // Metrics tracking and retrieval methods
00059       // Counters
00060       int Increment(const std::string& name);
00061       int Increment(const std::string& name, uint64_t count);
00062       int Decrement(const std::string& name);
00063       int Decrement(const std::string& name, uint64_t count);
00064 
00065       MetricsStore GetCounters();
00066       void ResetCounters();
00067 
00068       // Gauges
00069       int Gauge(const std::string& name, uint64_t value);
00070 
00071       MetricsStore GetGauges();
00072       void ResetGauges();
00073 
00074     private:
00075       MetricsRegistry(const MetricsRegistry&) = delete;
00076       MetricsRegistry(MetricsRegistry&&) = delete;
00077       MetricsStore counterRegistry;
00078       MetricsStore gaugesRegistry;
00079       std::mutex counterMutex;
00080       std::mutex gaugesMutex;
00081   };
00082 
00083 }
00084 
00085 #endif  // INCLUDE_SNYDER_H_
 All Classes Functions Variables