Browse code

Merge 51b01c736abf746ff577963411b82c56c714721e into 417eb2a7052a9354712663cca9e3bc075a3f69c0

Julien Chavanton authored on 10/06/2021 10:08:42 • GitHub committed on 10/06/2021 10:08:42
Showing 4 changed files
... ...
@@ -114,7 +114,7 @@ failure_route[tryagain] {
114 114
                 The statsd server collects gauges under the stats.gauges prefix.
115 115
             </para>
116 116
             <example>
117
-                <title><function>statsd_set</function> usage</title>
117
+                <title><function>statsd_gauge</function> usage</title>
118 118
                 <programlisting format="linespecific">
119 119
 ...
120 120
 route [gauge_method]{
... ...
@@ -126,6 +126,29 @@ route [gauge_method]{
126 126
             </example>
127 127
         </section>
128 128
 
129
+        <section id="statsd.f.statsd_histogram">
130
+            <title>
131
+                <function moreinfo="none">statsd_histogram(key, value)</function>
132
+            </title>
133
+            <para>
134
+		    The histograms are a measure of time, but they are calculated at the server side.
135
+		    As the data exported by the client is the same, this is just an alias for the Timer type.
136
+            </para>
137
+            <para>
138
+                This function can be used in ALL ROUTES.
139
+            </para>
140
+            <para>
141
+                The statsd server collects histograms under the stats.histograms prefix.
142
+            </para>
143
+            <example>
144
+                <title><function>statsd_histogram</function> usage</title>
145
+                <programlisting format="linespecific">
146
+...
147
+    statsd_histogram("latency", 1000);
148
+...
149
+                </programlisting>
150
+            </example>
151
+        </section>
129 152
         <section id="statsd.f.statsd_start">
130 153
             <title>
131 154
                 <function moreinfo="none">statsd_start(key)</function>
... ...
@@ -91,6 +91,12 @@ bool statsd_gauge(char *key, char *value){
91 91
    return send_command(command);
92 92
 }
93 93
 
94
+bool statsd_histogram(char *key, char *value){
95
+   char command[254];
96
+   snprintf(command, sizeof command, "%s:%s|h\n", key, value);
97
+   return send_command(command);
98
+}
99
+
94 100
 bool statsd_count(char *key, char *value){
95 101
    char* end = 0;
96 102
    char command[254];
... ...
@@ -12,6 +12,7 @@ bool statsd_connect(void);
12 12
 bool send_command(char *command);
13 13
 bool statsd_set(char *key, char *value);
14 14
 bool statsd_gauge(char *key, char *value);
15
+bool statsd_histogram(char *key, char *value);
15 16
 bool statsd_count(char *key, char *value);
16 17
 bool statsd_timing(char *key, int value);
17 18
 bool statsd_init(char *ip, char *port);
... ...
@@ -34,6 +34,7 @@ MODULE_VERSION
34 34
 static int mod_init(void);
35 35
 void mod_destroy(void);
36 36
 static int func_gauge(struct sip_msg *msg, char *key, char* val);
37
+static int func_histogram(struct sip_msg *msg, char *key, char* val);
37 38
 static int func_set(struct sip_msg *msg, char *key, char* val);
38 39
 static int func_time_start(struct sip_msg *msg, char *key);
39 40
 static int func_time_end(struct sip_msg *msg, char *key);
... ...
@@ -50,6 +51,7 @@ static StatsdParams statsd_params= {};
50 51
 
51 52
 static cmd_export_t commands[] = {
52 53
 	{"statsd_gauge", (cmd_function)func_gauge, 2, 0, 0, ANY_ROUTE},
54
+	{"statsd_histogram", (cmd_function)func_histogram, 2, 0, 0, ANY_ROUTE},
53 55
 	{"statsd_start", (cmd_function)func_time_start, 1, 0, 0, ANY_ROUTE},
54 56
 	{"statsd_stop", (cmd_function)func_time_end, 1, 0, 0, ANY_ROUTE},
55 57
 	{"statsd_incr", (cmd_function)func_incr, 1, 0, 0, ANY_ROUTE},
... ...
@@ -117,11 +119,21 @@ static int func_gauge(struct sip_msg* msg, char* key, char* val)
117 119
     return statsd_gauge(key, val);
118 120
 }
119 121
 
122
+static int func_histogram(struct sip_msg* msg, char* key, char* val)
123
+{
124
+    return statsd_histogram(key, val);
125
+}
126
+
120 127
 static int ki_statsd_gauge(sip_msg_t* msg, str* key, str* val)
121 128
 {
122 129
     return statsd_gauge(key->s, val->s);
123 130
 }
124 131
 
132
+static int ki_statsd_histogram(sip_msg_t* msg, str* key, str* val)
133
+{
134
+    return statsd_histogram(key->s, val->s);
135
+}
136
+
125 137
 static int func_set(struct sip_msg* msg, char* key, char* val)
126 138
 {
127 139
     return statsd_set(key, val);
... ...
@@ -240,6 +252,11 @@ static sr_kemi_t sr_kemi_statsd_exports[] = {
240 252
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
241 253
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
242 254
 	},
255
+	{ str_init("statsd"), str_init("statsd_histogram"),
256
+		SR_KEMIP_INT, ki_statsd_histogram,
257
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
258
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
259
+	},
243 260
 	{ str_init("statsd"), str_init("statsd_start"),
244 261
 		SR_KEMIP_INT, ki_statsd_start,
245 262
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,