1 /*************************************************************************
6 * [2011] - [2012] Realm Inc
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.
19 **************************************************************************/
20 #ifndef REALM_SYNC_METRICS_HPP
21 #define REALM_SYNC_METRICS_HPP
23 #if REALM_HAVE_DOGLESS
24 # include <dogless.hpp>
30 // FIXME: Consider adding support for specification of sample rate. The Dogless
31 // API already supports this.
34 /// Increment the counter identified by the specified key.
35 virtual void increment(const char* key, int value = 1) = 0;
37 /// Send the timing identified by the specified key.
38 virtual void timing(const char* key, double value) = 0;
40 /// Set value of the guage identified by the specified key.
41 virtual void gauge(const char* key, double value) = 0;
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;
47 /// Allow the dogless library to send each metric to multiple endpoints, as
49 virtual void add_endpoint(const std::string& endpoint) = 0;
54 #if REALM_HAVE_DOGLESS
56 class DoglessMetrics: public sync::Metrics {
59 m_dogless(dogless::hostname_prefix("realm")) // Throws
61 m_dogless.loop_interval(1);
64 void increment(const char* key, int value = 1) override
66 const char* metric = key;
67 m_dogless.increment(metric, value); // Throws
70 void timing(const char* key, double value) override
72 const char* metric = key;
73 m_dogless.timing(metric, value); // Throws
76 void gauge(const char* key, double value) override
78 const char* metric = key;
79 m_gauges[key] = value;
80 m_dogless.gauge(metric, m_gauges[key]); // Throws
83 void gauge_relative(const char* key, double value) override
85 const char* metric = key;
86 m_gauges[key] += value;
87 m_dogless.gauge(metric, m_gauges[key]); // Throws
90 void add_endpoint(const std::string& endpoint) override
92 m_dogless.add_endpoint(endpoint);
96 dogless::BufferedStatsd m_dogless;
97 std::map<std::string, double> m_gauges;
105 #endif // REALM_SYNC_METRICS_HPP