added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / sync / metrics.hpp
1 /*************************************************************************
2  *
3  * REALM CONFIDENTIAL
4  * __________________
5  *
6  *  [2011] - [2012] Realm Inc
7  *  All Rights Reserved.
8  *
9  * NOTICE:  All information contained herein is, and remains
10  * the property of Realm Incorporated and its suppliers,
11  * if any.  The intellectual and technical concepts contained
12  * herein are proprietary to Realm Incorporated
13  * and its suppliers and may be covered by U.S. and Foreign Patents,
14  * patents in process, and are protected by trade secret or copyright law.
15  * Dissemination of this information or reproduction of this material
16  * is strictly forbidden unless prior written permission is obtained
17  * from Realm Incorporated.
18  *
19  **************************************************************************/
20 #ifndef REALM_SYNC_METRICS_HPP
21 #define REALM_SYNC_METRICS_HPP
22
23 #if REALM_HAVE_DOGLESS
24 #  include <dogless.hpp>
25 #endif
26
27 namespace realm {
28 namespace sync {
29
30 // FIXME: Consider adding support for specification of sample rate. The Dogless
31 // API already supports this.
32 class Metrics {
33 public:
34     /// Increment the counter identified by the specified key.
35     virtual void increment(const char* key, int value = 1) = 0;
36
37     /// Send the timing identified by the specified key.
38     virtual void timing(const char* key, double value) = 0;
39
40     /// Set value of the guage identified by the specified key.
41     virtual void gauge(const char* key, double value) = 0;
42
43     /// Add the specified value to the guage identified by the specified
44     /// key. The value is allowed to be negative.
45     virtual void gauge_relative(const char* key, double value) = 0;
46
47     /// Allow the dogless library to send each metric to multiple endpoints, as
48     /// required
49     virtual void add_endpoint(const std::string& endpoint) = 0;
50
51     virtual ~Metrics() {}
52 };
53
54 #if REALM_HAVE_DOGLESS
55
56 class DoglessMetrics: public sync::Metrics {
57 public:
58     DoglessMetrics():
59         m_dogless(dogless::hostname_prefix("realm")) // Throws
60     {
61         m_dogless.loop_interval(1);
62     }
63
64     void increment(const char* key, int value = 1) override
65     {
66         const char* metric = key;
67         m_dogless.increment(metric, value); // Throws
68     }
69
70     void timing(const char* key, double value) override
71     {
72         const char* metric = key;
73         m_dogless.timing(metric, value); // Throws
74     }
75
76     void gauge(const char* key, double value) override
77     {
78         const char* metric = key;
79         m_gauges[key] = value;
80         m_dogless.gauge(metric, m_gauges[key]); // Throws
81     }
82
83     void gauge_relative(const char* key, double value) override
84     {
85         const char* metric = key;
86         m_gauges[key] += value;
87         m_dogless.gauge(metric, m_gauges[key]); // Throws
88     }
89
90     void add_endpoint(const std::string& endpoint) override
91     {
92         m_dogless.add_endpoint(endpoint);
93     }
94
95 private:
96     dogless::BufferedStatsd m_dogless;
97     std::map<std::string, double> m_gauges;
98 };
99
100 #endif
101
102 } // namespace sync
103 } // namespace realm
104
105 #endif // REALM_SYNC_METRICS_HPP