88#include "socket.h"
99#include "logging.h"
1010#include "slot.h"
11- #include "alloc.h"
1211
1312#define HOST_LEN 255
1413
@@ -34,19 +33,6 @@ static struct {
3433 double user ;
3534} used_cpu ;
3635
37- static struct dict slow_counts ; // node dsn => slow cmd counts
38-
39-
40- static void stats_free_slow_counts ()
41- {
42- struct dict_iter iter = DICT_ITER_INITIALIZER ;
43- DICT_FOREACH (& slow_counts , & iter ) {
44- cv_free (iter .value );
45- }
46-
47- dict_free (& slow_counts );
48- }
49-
5036static inline void stats_get_cpu_usage (struct stats * stats )
5137{
5238 struct rusage ru ;
@@ -191,7 +177,7 @@ void stats_send_node_info()
191177{
192178 struct bytes * value ;
193179
194- /* redis-node.127-0-0-1- 8000.bytes.{send,recv} */
180+ /* redis-node.127-0-0-1: 8000.bytes.{send,recv} */
195181 int len = HOST_LEN + 64 ;
196182 char name [len ];
197183
@@ -230,85 +216,6 @@ void stats_get(struct stats *stats)
230216 }
231217}
232218
233- static void stats_send_slow_log ()
234- {
235- if (config .slow_threshold < 0 )
236- return ;
237-
238- const char * fmt = "redis-node.%s.slow_query.%s" ;
239- const char * sum_fmt = "slow_query.%s" ;
240- extern struct cmd_item cmds [];
241- extern const size_t CMD_NUM ;
242-
243- struct connection * server ;
244- struct context * contexts = get_contexts ();
245-
246- {
247- struct dict_iter iter = DICT_ITER_INITIALIZER ;
248- DICT_FOREACH (& slow_counts , & iter ) {
249- memset (iter .value , 0 , CMD_NUM * sizeof (uint32_t ));
250- }
251- }
252-
253- uint32_t counts_sum [CMD_NUM ];
254- memset (counts_sum , 0 , sizeof (counts_sum ));
255-
256- for (size_t i = 0 ; i < config .thread ; i ++ ) {
257- TAILQ_FOREACH (server , & contexts [i ].servers , next ) {
258- const char * dsn = server -> info -> dsn ;
259- uint32_t * node_counts = NULL ;
260- for (size_t j = 0 ; j < CMD_NUM ; j ++ ) {
261- uint32_t count = ATOMIC_IGET (server -> info -> slow_cmd_counts [j ], 0 );
262- if (count == 0 ) continue ;
263-
264- if (!node_counts ) {
265- node_counts = (uint32_t * )dict_get (& slow_counts , dsn );
266- if (!node_counts ) {
267- node_counts = cv_calloc (CMD_NUM , sizeof (uint32_t ));
268- dict_set (& slow_counts , dsn , node_counts );
269- }
270- }
271- node_counts [j ] += count ;
272- counts_sum [j ] += count ;
273- }
274- }
275- }
276-
277- struct dict_iter iter = DICT_ITER_INITIALIZER ;
278- DICT_FOREACH (& slow_counts , & iter ) {
279- const char * dsn = iter .key ;
280- uint32_t * counts = (uint32_t * )iter .value ;
281-
282- char addr [ADDRESS_LEN ] = {0 };
283- strncpy (addr , dsn , ADDRESS_LEN );
284- for (size_t i = 0 ; i < ADDRESS_LEN ; i ++ ) {
285- if (addr [i ] == '.' || addr [i ] == ':' )
286- addr [i ] = '-' ;
287- }
288-
289- for (size_t i = 0 ; i < CMD_NUM ; i ++ ) {
290- if (counts [i ] == 0 ) continue ;
291-
292- const char * cmd = cmds [i ].cmd ;
293- int n = snprintf (NULL , 0 , fmt , addr , cmd );
294- char buf [n + 1 ];
295- snprintf (buf , sizeof (buf ), fmt , addr , cmd );
296- stats_send (buf , counts [i ]);
297- }
298- }
299-
300- for (size_t i = 0 ; i < CMD_NUM ; i ++ ) {
301- uint32_t sum = counts_sum [i ];
302- if (sum ) {
303- const char * cmd = cmds [i ].cmd ;
304- int n = snprintf (NULL , 0 , sum_fmt , cmd );
305- char buf [n + 1 ];
306- snprintf (buf , sizeof (buf ), sum_fmt , cmd );
307- stats_send (buf , sum );
308- }
309- }
310- }
311-
312219void * stats_daemon (void * data )
313220{
314221 /* Make the thread killable at any time can work reliably. */
@@ -319,7 +226,6 @@ void *stats_daemon(void *data)
319226 sleep (config .metric_interval );
320227 stats_send_simple ();
321228 stats_send_node_info ();
322- stats_send_slow_log ();
323229 LOG (DEBUG , "sending metrics" );
324230 }
325231 return NULL ;
@@ -344,8 +250,6 @@ int stats_init()
344250 if (hostname [i ] == '.' ) hostname [i ] = '-' ;
345251 }
346252
347- dict_init (& slow_counts );
348-
349253 LOG (INFO , "starting stats thread" );
350254 return thread_spawn (& stats_ctx , stats_daemon );
351255}
@@ -355,7 +259,6 @@ void stats_kill()
355259 int err ;
356260
357261 dict_free (& bytes_map );
358- stats_free_slow_counts ();
359262
360263 if (pthread_cancel (stats_ctx .thread ) == 0 ) {
361264 if ((err = pthread_join (stats_ctx .thread , NULL )) != 0 ) {
0 commit comments