CUBRID Engine  latest
broker_monitor.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * broker_monitor.c -
22  */
23 
24 #ident "$Id$"
25 
26 #if !defined(WINDOWS)
27 #define __STDC_FORMAT_MACROS
28 #include <inttypes.h>
29 #endif
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <signal.h>
34 #include <time.h>
35 #include <string.h>
36 #include <stdarg.h>
37 #include <assert.h>
38 
39 #if defined(WINDOWS)
40 #include <winsock2.h>
41 #include <windows.h>
42 #include <conio.h>
43 #else
44 #if defined(AIX)
45 #define _BOOL
46 #include <curses.h>
47 #else
48 #include <curses.h>
49 #endif
50 #endif
51 
52 #if defined(WINDOWS)
53 #include <sys/timeb.h>
54 #else
55 #include <sys/types.h>
56 #include <regex.h>
57 #include <sys/time.h>
58 #endif
59 
60 #include "cubrid_getopt.h"
61 #include "porting.h"
62 #include "cas_common.h"
63 #include "broker_config.h"
64 #include "broker_shm.h"
65 #include "broker_util.h"
66 #include "broker_process_size.h"
67 #include "porting.h"
68 #if !defined(WINDOWS)
69 #include "broker_process_info.h"
70 #endif
71 #include "cas_util.h"
72 #include "shard_shm.h"
73 #include "shard_metadata.h"
74 #include "util_func.h"
75 
76 #if defined (SUPPRESS_STRLEN_WARNING)
77 #define strlen(s1) ((int) strlen(s1))
78 #endif /* defined (SUPPRESS_STRLEN_WARNING) */
79 
80 #define DEFAULT_CHECK_PERIOD 300 /* seconds */
81 #define MAX_APPL_NUM 100
82 
83 #define FIELD_DELIMITER ' '
84 
85 #define FIELD_WIDTH_BROKER_NAME 20
86 #define FIELD_WIDTH_AS_ID 10
87 
88 #define BROKER_MONITOR_FLAG_MASK 0x01
89 #define SHARDDB_MONITOR_FLAG_MASK 0x02
90 #define PROXY_MONITOR_FLAG_MASK 0x04
91 #define METADATA_MONITOR_FLAG_MASK 0x08
92 #define CLIENT_MONITOR_FLAG_MASK 0x10
93 #define UNUSABLE_DATABASES_FLAG_MASK 0x20
94 
95 #if defined(WINDOWS) && !defined(PRId64)
96 #define PRId64 "lld"
97 #endif
98 
99 typedef enum
100 {
111  FIELD_THREAD, /* = 10 */
131  FIELD_STATUS, /* = 30 */
141  FIELD_RESTART, /* = 40 */
150 } FIELD_NAME;
151 
152 typedef enum
153 {
160 } FIELD_TYPE;
161 
162 typedef enum
163 {
168 } MONITOR_TYPE;
169 
170 typedef enum
171 {
174 } FIELD_ALIGN;
175 
177 {
179  unsigned int width;
180  char title[256];
182 };
183 
186  {FIELD_PID, 5, "PID", FIELD_RIGHT_ALIGN},
187  {FIELD_PSIZE, 7, "PSIZE", FIELD_RIGHT_ALIGN},
188  {FIELD_PORT, 5, "PORT", FIELD_RIGHT_ALIGN},
189  {FIELD_APPL_SERVER_NUM_TOTAL, 5, "", FIELD_RIGHT_ALIGN},
190  {FIELD_APPL_SERVER_NUM_CLIENT_WAIT, 6, "W", FIELD_RIGHT_ALIGN},
191  {FIELD_APPL_SERVER_NUM_BUSY, 6, "B", FIELD_RIGHT_ALIGN},
192  {FIELD_APPL_SERVER_NUM_CLIENT_WAIT_IN_SEC, 6, "", FIELD_RIGHT_ALIGN},
193  {FIELD_APPL_SERVER_NUM_BUSY_IN_SEC, 6, "", FIELD_RIGHT_ALIGN},
194  {FIELD_JOB_QUEUE_ID, 4, "JQ", FIELD_RIGHT_ALIGN},
195  {FIELD_THREAD, 4, "THR", FIELD_RIGHT_ALIGN},
196  {FIELD_CPU_USAGE, 6, "CPU", FIELD_RIGHT_ALIGN},
197  {FIELD_CPU_TIME, 6, "CTIME", FIELD_RIGHT_ALIGN},
198  {FIELD_TPS, 20, "TPS", FIELD_RIGHT_ALIGN},
199  {FIELD_QPS, 20, "QPS", FIELD_RIGHT_ALIGN},
200  {FIELD_NUM_OF_SELECT_QUERIES, 8, "SELECT", FIELD_RIGHT_ALIGN},
201  {FIELD_NUM_OF_INSERT_QUERIES, 8, "INSERT", FIELD_RIGHT_ALIGN},
202  {FIELD_NUM_OF_UPDATE_QUERIES, 8, "UPDATE", FIELD_RIGHT_ALIGN},
203  {FIELD_NUM_OF_DELETE_QUERIES, 8, "DELETE", FIELD_RIGHT_ALIGN},
204  {FIELD_NUM_OF_OTHERS_QUERIES, 8, "OTHERS", FIELD_RIGHT_ALIGN},
205  /*
206  * 5: width of long transaction count
207  * 1: delimiter(/)
208  * 4: width of long transaction time
209  * output example :
210  * [long transaction count]/[long transaction time]
211  * 10/60.0
212  * */
213  {FIELD_LONG_TRANSACTION, 5 + 1 + 4, "LONG-T", FIELD_RIGHT_ALIGN},
214  /*
215  * 5: width of long query count
216  * 1: delimiter(/)
217  * 4: width of long query time
218  * output example :
219  * [long query count]/[long query time]
220  * 10/60.0
221  * */
222  {FIELD_LONG_QUERY, 5 + 1 + 4, "LONG-Q", FIELD_RIGHT_ALIGN},
223  {FIELD_ERROR_QUERIES, 13, "ERR-Q", FIELD_RIGHT_ALIGN},
224  {FIELD_UNIQUE_ERROR_QUERIES, 13, "UNIQUE-ERR-Q", FIELD_RIGHT_ALIGN},
225  {FIELD_CANCELED, 10, "CANCELED", FIELD_RIGHT_ALIGN},
226  {FIELD_ACCESS_MODE, 13, "ACCESS_MODE", FIELD_RIGHT_ALIGN},
227  {FIELD_SQL_LOG, 9, "SQL_LOG", FIELD_RIGHT_ALIGN},
228  {FIELD_NUMBER_OF_CONNECTION, 9, "#CONNECT", FIELD_RIGHT_ALIGN},
229  {FIELD_ID, FIELD_WIDTH_AS_ID, "ID", FIELD_RIGHT_ALIGN},
230  {FIELD_LQS, 10, "LQS", FIELD_RIGHT_ALIGN},
231  {FIELD_STATUS, 12, "STATUS", FIELD_LEFT_ALIGN},
232  {FIELD_LAST_ACCESS_TIME, 19, "LAST ACCESS TIME", FIELD_RIGHT_ALIGN},
233  {FIELD_DB_NAME, 16, "DB", FIELD_RIGHT_ALIGN},
234  {FIELD_HOST, 16, "HOST", FIELD_RIGHT_ALIGN},
235  {FIELD_LAST_CONNECT_TIME, 19, "LAST CONNECT TIME", FIELD_RIGHT_ALIGN},
236  {FIELD_CLIENT_IP, 15, "CLIENT IP", FIELD_RIGHT_ALIGN},
237  {FIELD_CLIENT_VERSION, 19, "CLIENT VERSION", FIELD_RIGHT_ALIGN},
238  {FIELD_SQL_LOG_MODE, 15, "SQL_LOG_MODE", FIELD_RIGHT_ALIGN},
239  {FIELD_TRANSACTION_STIME, 19, "TRANSACTION STIME", FIELD_RIGHT_ALIGN},
240  {FIELD_CONNECT, 9, "#CONNECT", FIELD_RIGHT_ALIGN},
241  {FIELD_RESTART, 9, "#RESTART", FIELD_RIGHT_ALIGN},
242  {FIELD_REQUEST, 20, "#REQUEST", FIELD_RIGHT_ALIGN},
243  {FIELD_SHARD_ID, 10, "SHARD_ID", FIELD_RIGHT_ALIGN},
244  {FIELD_PROXY_ID, 10, "PROXY_ID", FIELD_RIGHT_ALIGN},
245  {FIELD_SHARD_Q_SIZE, 7, "SHARD-Q", FIELD_RIGHT_ALIGN},
246  {FIELD_STMT_POOL_RATIO, 20, "STMT-POOL-RATIO(%)", FIELD_RIGHT_ALIGN},
247  {FIELD_NUMBER_OF_CONNECTION_REJECTED, 9, "#REJECT", FIELD_RIGHT_ALIGN},
248  {FIELD_UNUSABLE_DATABASES, 100, "UNUSABLE_DATABASES", FIELD_LEFT_ALIGN}
249 };
250 
251 /* structure for appl monitoring */
254 {
257  INT64 qps;
258  INT64 lqs;
259 };
260 
261 /* structure for broker monitoring */
264 {
265  UINT64 num_tx;
266  UINT64 num_qx;
267  UINT64 num_lt;
268  UINT64 num_lq;
269  UINT64 num_eq;
270  UINT64 num_eq_ui;
272  UINT64 tps;
273  UINT64 qps;
274  UINT64 lts;
275  UINT64 lqs;
276  UINT64 eqs_ui;
277  UINT64 eqs;
278  UINT64 its;
285  UINT64 num_request;
286  UINT64 num_connect;
290  UINT64 num_busy;
292  UINT64 num_restart;
297 };
298 
301 {
302  int shard_id;
303 
307 };
308 
311 {
312  INT64 num_range_queries_requested[SHARD_KEY_RANGE_MAX];
313 };
314 
315 static void str_to_screen (const char *msg);
316 static void print_newline ();
317 static int get_char (void);
318 static void print_usage (void);
319 static int get_args (int argc, char *argv[], char *br_vector);
320 static void print_job_queue (T_MAX_HEAP_NODE *);
321 static void ip2str (unsigned char *ip, char *ip_str);
322 static void time2str (const time_t t, char *str);
323 
324 static void print_monitor_header (MONITOR_TYPE mnt_type);
325 static void set_monitor_items (BR_MONITORING_ITEM * mnt_items, T_BROKER_INFO * br_info, T_SHM_APPL_SERVER * shm_appl,
326  T_SHM_PROXY * shm_proxy, MONITOR_TYPE mnt_type);
327 static void print_monitor_items (BR_MONITORING_ITEM * mnt_items_cur, BR_MONITORING_ITEM * mnt_items_old,
328  int num_mnt_items, double elapsed_time, T_BROKER_INFO * br_info_p,
330 
331 static void appl_info_display (T_SHM_APPL_SERVER * shm_appl, T_APPL_SERVER_INFO * as_info_p, int br_index, int as_index,
332  APPL_MONITORING_ITEM * appl_mnt_old, time_t current_time, double elapsed_time);
333 static int appl_monitor (char *br_vector, double elapsed_time);
334 static int brief_monitor (char *br_vector, MONITOR_TYPE mnt_type, double elapsed_time);
335 
336 #ifdef GET_PSINFO
337 static void time_format (int t, char *time_str);
338 #endif
339 static void print_appl_header (bool use_pdh_flag);
340 static int print_title (char *buf_p, int buf_offset, FIELD_NAME name, const char *new_title_p);
341 static void print_value (FIELD_NAME name, const void *value, FIELD_TYPE type);
343 static const char *get_access_mode_string (T_ACCESS_MODE_VALUE mode, int replica_only_flag);
345 static const char *get_status_string (T_APPL_SERVER_INFO * as_info_p, char appl_server);
346 static void get_cpu_usage_string (char *buf_p, float usage);
347 
348 
349 #if defined(WINDOWS)
350 static void move (int x, int y);
351 static void refresh ();
352 static void clear ();
353 static void clrtobot ();
354 static void clrtoeol ();
355 static void endwin ();
356 #endif
357 
358 static int metadata_monitor (double elapsed_time);
359 static int client_monitor (void);
360 static int unusable_databases_monitor (void);
361 
363 static bool display_job_queue = false;
364 static int refresh_sec = 0;
365 static int last_access_sec = 0;
366 static bool tty_mode = false;
367 static bool full_info_flag = false;
368 static int state_interval = 1;
370 
371 static unsigned int monitor_flag = 0;
372 
373 #if defined(WINDOWS)
374 HANDLE h_console;
375 CONSOLE_SCREEN_BUFFER_INFO scr_info;
376 #endif
377 static void
378 str_to_screen (const char *msg)
379 {
380 #ifdef WINDOWS
381  DWORD size;
382  (void) WriteConsole (h_console, msg, strlen (msg), &size, NULL);
383 #else
384  (void) addstr (msg);
385 #endif
386 }
387 
388 static void
389 str_out (const char *fmt, ...)
390 {
391  va_list ap;
392  char out_buf[1024];
393 
394  va_start (ap, fmt);
395  if (refresh_sec > 0 && !tty_mode)
396  {
397  vsprintf (out_buf, fmt, ap);
398  str_to_screen (out_buf);
399  }
400  else
401  {
402  vprintf (fmt, ap);
403  }
404  va_end (ap);
405 }
406 
407 static void
409 {
410  if (refresh_sec > 0 && !tty_mode)
411  {
412  clrtoeol ();
413  str_to_screen ("\n");
414  }
415  else
416  {
417  printf ("\n");
418  }
419 }
420 
421 static int
422 get_char (void)
423 {
424 #ifdef WINDOWS
425  int i;
426  for (i = 0; i < refresh_sec * 10; i++)
427  {
428  if (shm_br != NULL && shm_br->magic == 0)
429  {
430  return 0;
431  }
432 
433  if (_kbhit ())
434  {
435  return _getch ();
436  }
437  else
438  {
439  SLEEP_MILISEC (0, 100);
440  }
441  }
442  return 0;
443 #else
444  return getch ();
445 #endif
446 }
447 
448 
449 int
450 main (int argc, char **argv)
451 {
452  T_BROKER_INFO br_info[MAX_BROKER_NUM];
453  int num_broker, master_shm_id;
454  int err, i;
455  char *br_vector;
456 #if defined(WINDOWS)
457 #else
458  WINDOW *win;
459 #endif
460  time_t time_old, time_cur;
461  double elapsed_time;
462 
463  if (argc == 2 && strcmp (argv[1], "--version") == 0)
464  {
465  fprintf (stderr, "VERSION %s\n", makestring (BUILD_NUMBER));
466  return 3;
467  }
468 
469  err = broker_config_read (NULL, br_info, &num_broker, &master_shm_id, NULL, 0, NULL, NULL, NULL);
470  if (err < 0)
471  {
472  return 2;
473  }
474 
475  ut_cd_work_dir ();
476 
477  shm_br = (T_SHM_BROKER *) uw_shm_open (master_shm_id, SHM_BROKER, SHM_MODE_MONITOR);
478  if (shm_br == NULL)
479  {
480  /* This means we have to launch broker */
481  fprintf (stdout, "master shared memory open error[0x%x]\r\n", master_shm_id);
482  return 1;
483  }
484  if (shm_br->num_broker < 1 || shm_br->num_broker > MAX_BROKER_NUM)
485  {
486  PRINT_AND_LOG_ERR_MSG ("broker configuration error\r\n");
487  return 3;
488  }
489 
490  br_vector = (char *) malloc (shm_br->num_broker);
491  if (br_vector == NULL)
492  {
493  PRINT_AND_LOG_ERR_MSG ("memory allocation error\r\n");
494  return 3;
495  }
496  for (i = 0; i < shm_br->num_broker; i++)
497  {
498  br_vector[i] = 0;
499  }
500 
501  if (get_args (argc, argv, br_vector) < 0)
502  {
503  free (br_vector);
504  return 3;
505  }
506 
507  if (refresh_sec > 0 && !tty_mode)
508  {
509 #if defined(WINDOWS)
510  h_console = GetStdHandle (STD_OUTPUT_HANDLE);
511  if (h_console == NULL)
512  {
513  refresh_sec = 0;
514  }
515  if (!GetConsoleScreenBufferInfo (h_console, &scr_info))
516  {
517  scr_info.dwSize.X = 80;
518  scr_info.dwSize.Y = 50;
519  }
520 // FillConsoleOutputCharacter(h_console, ' ', scr_info.dwSize.X * scr_info.dwSize.Y, top_left_pos, &size);
521 #else
522  win = initscr ();
523  timeout (refresh_sec * 1000);
524  noecho ();
525 #endif
526  }
527 
528  (void) time (&time_old);
529  time_old--;
530 
531  while (1)
532  {
533  (void) time (&time_cur);
534  elapsed_time = difftime (time_cur, time_old);
535 
536  if (refresh_sec > 0 && !tty_mode)
537  {
538  move (0, 0);
539  refresh ();
540  }
541 
542  if (shm_br == NULL || shm_br->magic == 0)
543  {
544  if (shm_br)
545  {
546  uw_shm_detach (shm_br);
547  }
548 
549  shm_br = (T_SHM_BROKER *) uw_shm_open (master_shm_id, SHM_BROKER, SHM_MODE_MONITOR);
550  }
551  else
552  {
554  {
555  if ((monitor_flag & ~BROKER_MONITOR_FLAG_MASK) != 0)
556  {
557  print_newline ();
558  }
559  brief_monitor (br_vector, MONITOR_T_BROKER, elapsed_time);
560  }
561 
563  {
564  if ((monitor_flag & ~SHARDDB_MONITOR_FLAG_MASK) != 0)
565  {
566  print_newline ();
567  str_out ("<SHARD INFO>");
568  print_newline ();
569  }
570  brief_monitor (br_vector, MONITOR_T_SHARDDB, elapsed_time);
571  }
572 
574  {
575  if ((monitor_flag & ~PROXY_MONITOR_FLAG_MASK) != 0)
576  {
577  print_newline ();
578  str_out ("<PROXY INFO>");
579  print_newline ();
580  }
581  brief_monitor (br_vector, MONITOR_T_PROXY, elapsed_time);
582  }
583 
585  {
586  if ((monitor_flag & ~METADATA_MONITOR_FLAG_MASK) != 0)
587  {
588  print_newline ();
589  str_out ("<SHARD METADATA INFO>");
590  print_newline ();
591  }
592  metadata_monitor (elapsed_time);
593  }
594 
596  {
597  if ((monitor_flag & ~CLIENT_MONITOR_FLAG_MASK) != 0)
598  {
599  print_newline ();
600  str_out ("<CLIENT INFO>");
601  print_newline ();
602  }
603  client_monitor ();
604  }
605 
607  {
608  if ((monitor_flag & ~UNUSABLE_DATABASES_FLAG_MASK) != 0)
609  {
610  print_newline ();
611  }
613  }
614 
615  if (monitor_flag == 0)
616  {
617  appl_monitor (br_vector, elapsed_time);
618  }
619  }
620 
621  if (refresh_sec > 0 && !tty_mode)
622  {
623  int in_ch = 0;
624 
625  refresh ();
626  clrtobot ();
627  move (0, 0);
628  refresh ();
629  in_ch = get_char ();
630 
631 #if defined (WINDOWS)
632  if (shm_br != NULL && shm_br->magic == 0)
633  {
634  uw_shm_detach (shm_br);
635  shm_br = NULL;
636  }
637 #endif
638  if (in_ch == 'q')
639  {
640  break;
641  }
642  else if (in_ch == ' ' || in_ch == '\r' || in_ch == '\n' || in_ch == ' ')
643  {
644  clear ();
645  refresh ();
646  }
647  }
648  else if (refresh_sec > 0)
649  {
650  for (i = 0; i < 10; i++)
651  {
652 #if defined (WINDOWS)
653  if (shm_br != NULL && shm_br->magic == 0)
654  {
655  uw_shm_detach (shm_br);
656  shm_br = NULL;
657  }
658 #endif
659  SLEEP_MILISEC (0, refresh_sec * 100);
660  }
661  fflush (stdout);
662  }
663  else
664  {
665  break;
666  }
667 
668  if (elapsed_time > 0)
669  {
670  time_old = time_cur;
671  }
672  } /* end of while(1) */
673 
674  if (shm_br != NULL)
675  {
676  uw_shm_detach (shm_br);
677  }
678 
679  if (refresh_sec > 0 && !tty_mode)
680  {
681  endwin ();
682  }
683 
684  return 0;
685 }
686 
687 static void
689 {
690  printf ("broker_monitor [-b] [-q] [-t] [-s <sec>] [-S] [-P] [-m] [-c] [-u] [-f] [<expr>]\n");
691  printf ("\t<expr> part of broker name or SERVICE=[ON|OFF]\n");
692  printf ("\t-q display job queue\n");
693  printf ("\t-m display shard statistics information\n");
694  printf ("\t-c display client information\n");
695  printf ("\t-u display unusable database server\n");
696  printf ("\t-b brief mode (show broker info)\n");
697  printf ("\t-S brief mode (show sharddb info)\n");
698  printf ("\t-P brief mode (show proxy info)\n");
699  printf ("\t-s refresh time in sec\n");
700  printf ("\t-f full info\n");
701 }
702 
703 static int
704 get_args (int argc, char *argv[], char *br_vector)
705 {
706  int c, j;
707  int status;
708  bool br_name_opt_flag = false;
709 #if !defined(WINDOWS)
710  regex_t re;
711 #endif
712 
713  char optchars[] = "hbqts:l:fmcSPu";
714 
715  display_job_queue = false;
716  refresh_sec = 0;
717  last_access_sec = 0;
718  full_info_flag = false;
719  state_interval = 1;
721  while ((c = getopt (argc, argv, optchars)) != EOF)
722  {
723  switch (c)
724  {
725  case 't':
726  tty_mode = true;
727  break;
728  case 'q':
729  display_job_queue = true;
730  break;
731  case 's':
732  refresh_sec = atoi (optarg);
733  break;
734  case 'b':
736  break;
737  case 'l':
739  if (state_interval < 1)
740  {
741  state_interval = 1;
742  }
743  break;
744  case 'f':
745  full_info_flag = true;
746  break;
747  case 'm':
749  break;
750  case 'c':
752  break;
753  case 'S':
755  break;
756  case 'P':
758  break;
759  case 'u':
761  break;
762  case 'h':
763  case '?':
764  print_usage ();
765  return -1;
766  }
767  }
768 
769  for (; optind < argc; optind++)
770  {
771  if (br_name_opt_flag == false)
772  {
773  if (strncasecmp (argv[optind], "SERVICE=", strlen ("SERVICE=")) == 0)
774  {
775  char *value_p;
776  value_p = argv[optind] + strlen ("SERVICE=");
777  if (strcasecmp (value_p, "ON") == 0)
778  {
780  break;
781  }
782  else if (strcasecmp (value_p, "OFF") == 0)
783  {
785  break;
786  }
787  else
788  {
789  print_usage ();
790  return -1;
791  }
792  }
793  }
794 
795  br_name_opt_flag = true;
796 #if !defined(WINDOWS)
797  if (regcomp (&re, argv[optind], 0) != 0)
798  {
799  fprintf (stderr, "%s\r\n", argv[optind]);
800  return -1;
801  }
802 #endif
803  for (j = 0; j < shm_br->num_broker; j++)
804  {
805 #if defined(WINDOWS)
806  status = (strstr (shm_br->br_info[j].name, argv[optind]) != NULL) ? 0 : 1;
807 #else
808  status = regexec (&re, shm_br->br_info[j].name, 0, NULL, 0);
809 #endif
810  if (status == 0)
811  {
812  br_vector[j] = 1;
813  }
814  }
815 #if !defined(WINDOWS)
816  regfree (&re);
817 #endif
818  }
819 
820  if (br_name_opt_flag == false)
821  {
822  for (j = 0; j < shm_br->num_broker; j++)
823  br_vector[j] = 1;
824  }
825 
826  return 0;
827 }
828 
829 static void
831 {
832  T_MAX_HEAP_NODE item;
833  char first_flag = 1;
834  char outbuf[1024];
835 
836  while (1)
837  {
838  char ip_str[64];
839  char time_str[64];
840 
841  if (max_heap_delete (job_queue, &item) < 0)
842  break;
843 
844  if (first_flag)
845  {
846  sprintf (outbuf, "%5s %s%9s%13s%13s", "ID", "PRIORITY", "IP", "TIME", "REQUEST");
847  str_out ("%s", outbuf);
848  print_newline ();
849  first_flag = 0;
850  }
851 
852  ip2str (item.ip_addr, ip_str);
853  time2str (item.recv_time, time_str);
854  sprintf (outbuf, "%5d%7d%17s%10s %s:%s", item.id, item.priority, ip_str, time_str, item.script, item.prg_name);
855  str_out ("%s", outbuf);
856  print_newline ();
857  }
858  if (!first_flag)
859  print_newline ();
860 }
861 
862 static void
863 ip2str (unsigned char *ip, char *ip_str)
864 {
865  sprintf (ip_str, "%d.%d.%d.%d", (unsigned char) ip[0], (unsigned char) ip[1], (unsigned char) ip[2],
866  (unsigned char) ip[3]);
867 }
868 
869 static void
870 time2str (const time_t t, char *str)
871 {
872  struct tm s_tm;
873 
874  if (localtime_r (&t, &s_tm) == NULL)
875  {
876  *str = '\0';
877  return;
878  }
879  sprintf (str, "%02d:%02d:%02d", s_tm.tm_hour, s_tm.tm_min, s_tm.tm_sec);
880 }
881 
882 static void
884  APPL_MONITORING_ITEM * appl_mnt_old, time_t current_time, double elapsed_time)
885 {
886  UINT64 qps;
887  UINT64 lqs;
888  int col_len;
889  time_t tran_start_time;
890  char ip_str[16];
891  int as_id;
892  int proxy_id = 0;
893  int shard_id = 0;
894 #if !defined (WINDOWS)
895  int psize;
896 #endif
897 #if defined (GET_PSINFO) || defined (WINDOWS)
898  char buf[256];
899 #endif
900  int shard_flag = shm_appl->shard_flag;
901 
902  if (shm_appl->shard_flag == ON)
903  {
904  proxy_id = as_info_p->proxy_id + 1;
905  shard_id = as_info_p->shard_id;
906  as_id = as_info_p->shard_cas_id + 1;
907  }
908  else
909  {
910  as_id = as_index + 1;
911  }
912 
913  if (as_info_p->service_flag != SERVICE_ON)
914  {
915  return;
916  }
917 
918  if (last_access_sec > 0)
919  {
920  if (as_info_p->uts_status != UTS_STATUS_BUSY || current_time - as_info_p->last_access_time < last_access_sec)
921  {
922  return;
923  }
924 
925  if (as_info_p->uts_status == UTS_STATUS_BUSY && IS_APPL_SERVER_TYPE_CAS (shm_br->br_info[br_index].appl_server)
926  && as_info_p->con_status == CON_STATUS_OUT_TRAN)
927  {
928  return;
929  }
930  }
931 
932  col_len = 0;
933 
934  if (shard_flag == ON)
935  {
936  char as_id_str[FIELD_WIDTH_AS_ID];
937 
938  if (snprintf (as_id_str, sizeof (as_id_str), "%d-%d-%d", proxy_id, shard_id, as_id) < 0)
939  {
940  return;
941  }
942 
943  print_value (FIELD_ID, as_id_str, FIELD_T_STRING);
944  }
945  else
946  {
947  print_value (FIELD_ID, &as_id, FIELD_T_INT);
948  }
949  print_value (FIELD_PID, &as_info_p->pid, FIELD_T_INT);
950  if (elapsed_time > 0)
951  {
952  qps = (as_info_p->num_queries_processed - appl_mnt_old->num_query_processed) / elapsed_time;
953  lqs = (as_info_p->num_long_queries - appl_mnt_old->num_long_query) / elapsed_time;
954  appl_mnt_old->num_query_processed = as_info_p->num_queries_processed;
955  appl_mnt_old->num_long_query = as_info_p->num_long_queries;
956  appl_mnt_old->qps = qps;
957  appl_mnt_old->lqs = lqs;
958  }
959  else
960  {
961  qps = appl_mnt_old->qps;
962  lqs = appl_mnt_old->lqs;
963  }
964 
967 #if defined(WINDOWS)
968  print_value (FIELD_PORT, &(as_info_p->as_port), FIELD_T_INT);
969 #endif
970 #if defined(WINDOWS)
971  if (shm_appl->use_pdh_flag == TRUE)
972  {
973  print_value (FIELD_PSIZE, &(as_info_p->pdh_workset), FIELD_T_INT);
974  }
975 #else
976  psize = getsize (as_info_p->pid);
978 #endif
979  print_value (FIELD_STATUS, get_status_string (as_info_p, shm_br->br_info[br_index].appl_server), FIELD_T_STRING);
980 
981 #ifdef GET_PSINFO
982  get_psinfo (as_info_p->pid, &proc_info);
983 
984  get_cpu_usage_string (buf, proc_info.pcpu);
986 
987  time_format (proc_info.cpu_time, time_str);
989 #elif WINDOWS
990  if (shm_appl->use_pdh_flag == TRUE)
991  {
992  get_cpu_usage_string (buf, as_info_p->pdh_pct_cpu);
994  }
995 #endif
996 
997  if (full_info_flag)
998  {
1000  if (as_info_p->database_name[0] != '\0')
1001  {
1005  }
1006  else
1007  {
1008  print_value (FIELD_DB_NAME, (char *) "-", FIELD_T_STRING);
1009  print_value (FIELD_HOST, (char *) "-", FIELD_T_STRING);
1011  }
1012 
1013  print_value (FIELD_CLIENT_IP, ut_get_ipv4_string (ip_str, sizeof (ip_str), as_info_p->cas_clt_ip),
1014  FIELD_T_STRING);
1016 
1017  if (as_info_p->cur_sql_log_mode != shm_appl->sql_log_mode)
1018  {
1020  FIELD_T_STRING);
1021  }
1022  else
1023  {
1025  }
1026 
1027  tran_start_time = as_info_p->transaction_start_time;
1028  if (tran_start_time != (time_t) 0)
1029  {
1030  print_value (FIELD_TRANSACTION_STIME, &tran_start_time, FIELD_T_TIME);
1031  }
1032  else
1033  {
1035  }
1038  }
1039  print_newline ();
1040  if (as_info_p->uts_status == UTS_STATUS_BUSY)
1041  {
1042  str_out ("SQL: %s", as_info_p->log_msg);
1043  print_newline ();
1044  }
1045 }
1046 
1047 static int
1048 appl_monitor (char *br_vector, double elapsed_time)
1049 {
1050  T_MAX_HEAP_NODE job_queue[JOB_QUEUE_MAX_SIZE + 1];
1052  int i, j, k, appl_offset;
1053  int shard_flag;
1054 
1055  static APPL_MONITORING_ITEM *appl_mnt_olds = NULL;
1056 
1057  time_t current_time;
1058 #ifdef GET_PSINFO
1059  T_PSINFO proc_info;
1060  char time_str[32];
1061 #endif
1062 
1063  if (appl_mnt_olds == NULL)
1064  {
1065  int n = 0;
1066  for (i = 0; i < shm_br->num_broker; i++)
1067  {
1068  n += shm_br->br_info[i].appl_server_max_num;
1069  }
1070 
1071  appl_mnt_olds = (APPL_MONITORING_ITEM *) calloc (sizeof (APPL_MONITORING_ITEM), n);
1072  if (appl_mnt_olds == NULL)
1073  {
1074  return -1;
1075  }
1076  memset ((char *) appl_mnt_olds, 0, sizeof (APPL_MONITORING_ITEM) * n);
1077  }
1078 
1079  for (i = 0; i < shm_br->num_broker; i++)
1080  {
1081  if (br_vector[i] == 0)
1082  {
1083  continue;
1084  }
1085 
1087  {
1088  continue;
1089  }
1090 
1091  str_out ("%% %s", shm_br->br_info[i].name);
1092 
1093  if (shm_br->br_info[i].service_flag == SERVICE_ON)
1094  {
1095  shm_appl =
1098  if (shm_appl == NULL)
1099  {
1100  str_out ("%s", "shared memory open error");
1101  print_newline ();
1102  }
1103  else
1104  {
1105  shard_flag = shm_appl->shard_flag;
1106  print_newline ();
1107 #if defined (WINDOWS)
1108  print_appl_header (shm_appl->use_pdh_flag);
1109 #else
1110  print_appl_header (false);
1111 #endif
1112  current_time = time (NULL);
1113 
1114  /* CAS INFORMATION DISPLAY */
1115  appl_offset = 0;
1116 
1117  for (k = 0; k < i; k++)
1118  {
1119  appl_offset += shm_br->br_info[k].appl_server_max_num;
1120  }
1121  for (j = 0; j < shm_br->br_info[i].appl_server_max_num; j++)
1122  {
1123  appl_info_display (shm_appl, &(shm_appl->as_info[j]), i, j, &(appl_mnt_olds[appl_offset + j]),
1124  current_time, elapsed_time);
1125  } /* CAS INFORMATION DISPLAY */
1126 
1127  print_newline ();
1128 
1129  if (display_job_queue == true && shard_flag == OFF)
1130  {
1131  print_job_queue (job_queue);
1132  }
1133 
1134  if (shm_appl)
1135  {
1136  uw_shm_detach (shm_appl);
1137  }
1138  }
1139  }
1140 
1141  else
1142  { /* service_flag == OFF */
1143  str_out ("%c%s", FIELD_DELIMITER, "OFF");
1144  print_newline ();
1145  print_newline ();
1146  }
1147  }
1148 
1149  return 0;
1150 }
1151 
1152 static void
1154 {
1155  char buf[LINE_MAX];
1156  int buf_offset = 0;
1157  int i;
1158  static unsigned int tty_print_header = 0;
1159 
1160  assert (mnt_type <= MONITOR_T_LAST);
1161 
1162  if (tty_mode == true && (tty_print_header++ % 20 != 0) && mnt_type == MONITOR_T_BROKER
1164  {
1165  return;
1166  }
1167 
1168  buf_offset = 0;
1169 
1170  if (mnt_type == MONITOR_T_BROKER)
1171  {
1172  buf_offset = print_title (buf, buf_offset, FIELD_BROKER_NAME, NULL);
1173  buf_offset = print_title (buf, buf_offset, FIELD_PID, NULL);
1174  if (full_info_flag)
1175  {
1176  buf_offset = print_title (buf, buf_offset, FIELD_PSIZE, NULL);
1177  }
1178  buf_offset = print_title (buf, buf_offset, FIELD_PORT, NULL);
1179  }
1180  else if (mnt_type == MONITOR_T_SHARDDB)
1181  {
1182  buf_offset = print_title (buf, buf_offset, FIELD_SHARD_ID, NULL);
1183  }
1184  else if (mnt_type == MONITOR_T_PROXY)
1185  {
1186  buf_offset = print_title (buf, buf_offset, FIELD_PROXY_ID, NULL);
1187  }
1188 
1189  if (full_info_flag)
1190  {
1191  char field_title_with_interval[256];
1192 
1193  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_TOTAL, (char *) "AS(T");
1194  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_CLIENT_WAIT, NULL);
1195  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_BUSY, NULL);
1196  sprintf (field_title_with_interval, "%d%s", state_interval, "s-W");
1197  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_CLIENT_WAIT_IN_SEC, field_title_with_interval);
1198  sprintf (field_title_with_interval, "%d%s", state_interval, "s-B)");
1199  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_BUSY_IN_SEC, field_title_with_interval);
1200  }
1201  else
1202  {
1203  buf_offset = print_title (buf, buf_offset, FIELD_APPL_SERVER_NUM_TOTAL, (char *) "AS");
1204  }
1205 
1206  if (mnt_type == MONITOR_T_BROKER)
1207  {
1208  buf_offset = print_title (buf, buf_offset, FIELD_JOB_QUEUE_ID, NULL);
1209  }
1210  else if (mnt_type == MONITOR_T_SHARDDB || mnt_type == MONITOR_T_PROXY)
1211  {
1212  buf_offset = print_title (buf, buf_offset, FIELD_SHARD_Q_SIZE, NULL);
1213  }
1214 
1215 #ifdef GET_PSINFO
1216  buf_offset = print_title (buf, buf_offset, FIELD_THREAD, NULL);
1217  buf_offset = print_title (buf, buf_offset, FIELD_CPU_USAGE, NULL);
1218  buf_offset = print_title (buf, buf_offset, FIELD_CPU_TIME, NULL);
1219 #endif
1220 
1221  buf_offset = print_title (buf, buf_offset, FIELD_TPS, NULL);
1222  buf_offset = print_title (buf, buf_offset, FIELD_QPS, NULL);
1223  if (full_info_flag == false)
1224  {
1225  buf_offset = print_title (buf, buf_offset, FIELD_NUM_OF_SELECT_QUERIES, NULL);
1226  buf_offset = print_title (buf, buf_offset, FIELD_NUM_OF_INSERT_QUERIES, NULL);
1227  buf_offset = print_title (buf, buf_offset, FIELD_NUM_OF_UPDATE_QUERIES, NULL);
1228  buf_offset = print_title (buf, buf_offset, FIELD_NUM_OF_DELETE_QUERIES, NULL);
1229  buf_offset = print_title (buf, buf_offset, FIELD_NUM_OF_OTHERS_QUERIES, NULL);
1230  }
1231 
1232  buf_offset = print_title (buf, buf_offset, FIELD_LONG_TRANSACTION, NULL);
1233  buf_offset = print_title (buf, buf_offset, FIELD_LONG_QUERY, NULL);
1234  buf_offset = print_title (buf, buf_offset, FIELD_ERROR_QUERIES, NULL);
1235  buf_offset = print_title (buf, buf_offset, FIELD_UNIQUE_ERROR_QUERIES, NULL);
1236  if (full_info_flag && mnt_type == MONITOR_T_BROKER)
1237  {
1238  buf_offset = print_title (buf, buf_offset, FIELD_CANCELED, NULL);
1239  buf_offset = print_title (buf, buf_offset, FIELD_ACCESS_MODE, NULL);
1240  buf_offset = print_title (buf, buf_offset, FIELD_SQL_LOG, NULL);
1241  }
1242 
1243  if (mnt_type == MONITOR_T_BROKER)
1244  {
1245  buf_offset = print_title (buf, buf_offset, FIELD_NUMBER_OF_CONNECTION, NULL);
1246  buf_offset = print_title (buf, buf_offset, FIELD_NUMBER_OF_CONNECTION_REJECTED, NULL);
1247  }
1248  else if (mnt_type == MONITOR_T_SHARDDB)
1249  {
1250  buf_offset = print_title (buf, buf_offset, FIELD_REQUEST, NULL);
1251  }
1252  else if (mnt_type == MONITOR_T_PROXY)
1253  {
1254  buf_offset = print_title (buf, buf_offset, FIELD_NUMBER_OF_CONNECTION, NULL);
1255  buf_offset = print_title (buf, buf_offset, FIELD_NUMBER_OF_CONNECTION_REJECTED, NULL);
1256  buf_offset = print_title (buf, buf_offset, FIELD_RESTART, NULL);
1257 
1258  if (full_info_flag)
1259  {
1260  buf_offset = print_title (buf, buf_offset, FIELD_STMT_POOL_RATIO, NULL);
1261  }
1262  }
1263 
1264  str_out ("%s", buf);
1265  print_newline ();
1266 
1267  for (i = 0; i < buf_offset; i++)
1268  {
1269  str_out ("%s", "=");
1270  }
1271  print_newline ();
1272 
1273  return;
1274 }
1275 
1276 static void
1278  T_SHM_PROXY * shm_proxy, MONITOR_TYPE mnt_type)
1279 {
1280  int i, j;
1281  BR_MONITORING_ITEM *mnt_item_p = NULL;
1282  T_APPL_SERVER_INFO *as_info_p = NULL;
1284  T_SHARD_INFO *shard_info_p = NULL;
1285 
1286  assert (mnt_type <= MONITOR_T_LAST);
1287 
1288  mnt_item_p = mnt_items;
1289 
1290  mnt_item_p->num_appl_server = br_info_p->appl_server_num;
1291  for (i = 0; i < br_info_p->appl_server_max_num; i++)
1292  {
1293  as_info_p = &(shm_appl->as_info[i]);
1294 
1295  if (mnt_type == MONITOR_T_SHARDDB)
1296  {
1297  mnt_item_p = mnt_items + as_info_p->shard_id;
1298  }
1299  else if (mnt_type == MONITOR_T_PROXY)
1300  {
1301  mnt_item_p = mnt_items + as_info_p->proxy_id;
1302  }
1303 
1304  mnt_item_p->num_request += as_info_p->num_request;
1305  mnt_item_p->num_connect += as_info_p->num_connect_requests;
1306  mnt_item_p->num_connect_reject += as_info_p->num_connect_rejected;
1307  if (full_info_flag && as_info_p->service_flag == ON)
1308  {
1309  time_t cur_time = time (NULL);
1310  bool time_expired = (cur_time - as_info_p->last_access_time >= state_interval);
1311 
1312  if (as_info_p->uts_status == UTS_STATUS_BUSY && as_info_p->con_status != CON_STATUS_OUT_TRAN)
1313  {
1314  if (as_info_p->log_msg[0] == '\0')
1315  {
1316  mnt_item_p->num_client_wait++;
1317  if (time_expired)
1318  {
1319  mnt_item_p->num_client_wait_nsec++;
1320  }
1321  }
1322  else
1323  {
1324  mnt_item_p->num_busy++;
1325  if (time_expired)
1326  {
1327  mnt_item_p->num_busy_nsec++;
1328  }
1329  }
1330  }
1331 #if defined(WINDOWS)
1332  else if (as_info_p->uts_status == UTS_STATUS_BUSY_WAIT)
1333  {
1334  mnt_item_p->num_busy++;
1335  if (time_expired)
1336  {
1337  mnt_item_p->num_busy_nsec++;
1338  }
1339  }
1340 #endif
1341  }
1342  mnt_item_p->num_request += as_info_p->num_requests_received;
1343  mnt_item_p->num_tx += as_info_p->num_transactions_processed;
1344  mnt_item_p->num_qx += as_info_p->num_queries_processed;
1345  mnt_item_p->num_lt += as_info_p->num_long_transactions;
1346  mnt_item_p->num_lq += as_info_p->num_long_queries;
1347  mnt_item_p->num_eq += as_info_p->num_error_queries;
1348  mnt_item_p->num_eq_ui += as_info_p->num_unique_error_queries;
1349  mnt_item_p->num_interrupts += as_info_p->num_interrupts;
1350  mnt_item_p->num_select_query += as_info_p->num_select_queries;
1351  mnt_item_p->num_insert_query += as_info_p->num_insert_queries;
1352  mnt_item_p->num_update_query += as_info_p->num_update_queries;
1353  mnt_item_p->num_delete_query += as_info_p->num_delete_queries;
1354  mnt_item_p->num_others_query =
1355  (mnt_item_p->num_qx - mnt_item_p->num_select_query - mnt_item_p->num_insert_query -
1356  mnt_item_p->num_update_query - mnt_item_p->num_delete_query);
1357  }
1358 
1359  if (shm_appl->shard_flag == OFF)
1360  {
1361  return;
1362  }
1363 
1364  assert (shm_proxy);
1365 
1366  if (mnt_type == MONITOR_T_BROKER)
1367  {
1368  for (i = 0; i < shm_proxy->num_proxy; i++)
1369  {
1370  proxy_info_p = &shm_proxy->proxy_info[i];
1371 
1372  mnt_item_p->num_eq += proxy_info_p->num_proxy_error_processed;
1373  mnt_item_p->num_connect += proxy_info_p->num_connect_requests;
1374  mnt_item_p->num_connect_reject += proxy_info_p->num_connect_rejected;
1375  }
1376  }
1377  else if (mnt_type == MONITOR_T_SHARDDB)
1378  {
1379  /* we should init num_appl_server of shard monitor first item */
1380  mnt_items[0].num_appl_server = 0;
1381  for (i = 0; i < shm_proxy->num_proxy; i++)
1382  {
1383  proxy_info_p = &shm_proxy->proxy_info[i];
1384  for (j = 0; j < proxy_info_p->max_shard; j++)
1385  {
1386  shard_info_p = &proxy_info_p->shard_info[j];
1387  mnt_items[j].shard_waiter_count += shard_info_p->waiter_count;
1388  mnt_items[j].num_appl_server += shard_info_p->num_appl_server;
1389  }
1390  }
1391  }
1392  else if (mnt_type == MONITOR_T_PROXY)
1393  {
1394  /* we should init num_appl_server of proxy monitor first item */
1395  mnt_items[0].num_appl_server = 0;
1396  for (i = 0; i < shm_proxy->num_proxy; i++)
1397  {
1398  proxy_info_p = &shm_proxy->proxy_info[i];
1399 
1400  mnt_items[i].num_eq += proxy_info_p->num_proxy_error_processed;
1401  mnt_items[i].num_connect += proxy_info_p->num_connect_requests;
1402  mnt_items[i].num_connect_reject += proxy_info_p->num_connect_rejected;
1403  mnt_items[i].num_restart += proxy_info_p->num_restarts;
1404  mnt_items[i].num_request_stmt += proxy_info_p->num_request_stmt;
1405  mnt_items[i].num_request_stmt_in_pool += proxy_info_p->num_request_stmt_in_pool;
1406 
1407  for (j = 0; j < proxy_info_p->max_shard; j++)
1408  {
1409  shard_info_p = &proxy_info_p->shard_info[j];
1410  mnt_items[i].shard_waiter_count += shard_info_p->waiter_count;
1411  mnt_items[i].num_appl_server += shard_info_p->num_appl_server;
1412  }
1413  }
1414  }
1415 
1416  return;
1417 }
1418 
1419 static void
1420 print_monitor_items (BR_MONITORING_ITEM * mnt_items_cur, BR_MONITORING_ITEM * mnt_items_old, int num_mnt_items,
1421  double elapsed_time, T_BROKER_INFO * br_info_p, T_SHM_APPL_SERVER * shm_appl,
1422  MONITOR_TYPE mnt_type)
1423 {
1424  int i;
1425  BR_MONITORING_ITEM *mnt_item_cur_p = NULL;
1426  BR_MONITORING_ITEM *mnt_item_old_p = NULL;
1427  BR_MONITORING_ITEM mnt_item;
1428  char buf[256];
1429 #ifdef GET_PSINFO
1430  T_PSINFO proc_info;
1431  char time_str[32];
1432 #endif
1433 
1434  assert (mnt_type <= MONITOR_T_LAST);
1435 
1436  for (i = 0; i < num_mnt_items; i++)
1437  {
1438  mnt_item_cur_p = &mnt_items_cur[i];
1439  mnt_item_old_p = &mnt_items_old[i];
1440 
1441  if (elapsed_time > 0)
1442  {
1443  mnt_item.tps = (mnt_item_cur_p->num_tx - mnt_item_old_p->num_tx) / elapsed_time;
1444  mnt_item.qps = (mnt_item_cur_p->num_qx - mnt_item_old_p->num_qx) / elapsed_time;
1445  mnt_item.lts = mnt_item_cur_p->num_lt - mnt_item_old_p->num_lt;
1446  mnt_item.lqs = mnt_item_cur_p->num_lq - mnt_item_old_p->num_lq;
1447  mnt_item.eqs = mnt_item_cur_p->num_eq - mnt_item_old_p->num_eq;
1448  mnt_item.eqs_ui = mnt_item_cur_p->num_eq_ui - mnt_item_old_p->num_eq_ui;
1449  mnt_item.its = mnt_item_cur_p->num_interrupts - mnt_item_old_p->num_interrupt;
1450  mnt_item.num_select_query = mnt_item_cur_p->num_select_query - mnt_item_old_p->num_select_query;
1451  mnt_item.num_insert_query = mnt_item_cur_p->num_insert_query - mnt_item_old_p->num_insert_query;
1452  mnt_item.num_update_query = mnt_item_cur_p->num_update_query - mnt_item_old_p->num_update_query;
1453  mnt_item.num_delete_query = mnt_item_cur_p->num_delete_query - mnt_item_old_p->num_delete_query;
1454  mnt_item.num_others_query = mnt_item_cur_p->num_others_query - mnt_item_old_p->num_others_query;
1455 
1456  if (mnt_type == MONITOR_T_PROXY)
1457  {
1458  mnt_item.num_request_stmt =
1459  (mnt_item_cur_p->num_request_stmt - mnt_item_old_p->num_request_stmt) / elapsed_time;
1460  mnt_item.num_request_stmt_in_pool =
1461  (mnt_item_cur_p->num_request_stmt_in_pool - mnt_item_old_p->num_request_stmt_in_pool) / elapsed_time;
1462  }
1463 
1464  mnt_item_cur_p->tps = mnt_item.tps;
1465  mnt_item_cur_p->qps = mnt_item.qps;
1466  mnt_item_cur_p->lts = mnt_item.lts;
1467  mnt_item_cur_p->lqs = mnt_item.lqs;
1468  mnt_item_cur_p->eqs = mnt_item.eqs;
1469  mnt_item_cur_p->eqs_ui = mnt_item.eqs_ui;
1470  mnt_item_cur_p->its = mnt_item.its;
1471  }
1472  else
1473  {
1474  memcpy (&mnt_item, mnt_item_old_p, sizeof (mnt_item));
1475  }
1476 
1477  if (mnt_type == MONITOR_T_BROKER)
1478  {
1479  print_value (FIELD_PID, &(br_info_p->pid), FIELD_T_INT);
1480  if (full_info_flag)
1481  {
1482 #if defined(WINDOWS)
1483  if (shm_appl->use_pdh_flag == TRUE)
1484  {
1485  print_value (FIELD_PSIZE, &(br_info_p->pdh_workset), FIELD_T_INT);
1486  }
1487 #else
1488  int process_size;
1489 
1490  process_size = getsize (br_info_p->pid);
1491  print_value (FIELD_PSIZE, &process_size, FIELD_T_INT);
1492 #endif
1493  }
1494  print_value (FIELD_PORT, &(br_info_p->port), FIELD_T_INT);
1495  }
1496  else if (mnt_type == MONITOR_T_SHARDDB)
1497  {
1499  }
1500  else if (mnt_type == MONITOR_T_PROXY)
1501  {
1502  int proxy_id = i + 1;
1503  print_value (FIELD_PROXY_ID, &proxy_id, FIELD_T_INT);
1504  }
1505 
1507 
1508  if (full_info_flag)
1509  {
1510 
1515  }
1516 
1517  if (mnt_type == MONITOR_T_BROKER)
1518  {
1520  }
1521  else if (mnt_type == MONITOR_T_SHARDDB || mnt_type == MONITOR_T_PROXY)
1522  {
1524  }
1525 
1526 #ifdef GET_PSINFO
1527  get_psinfo (br_info_p->pid, &proc_info);
1528 
1529  print_value (FIELD_THREAD, &(proc_info.num_thr), FIELD_T_INT);
1530 
1531  get_cpu_usage_string (buf, proc_info.pcpu);
1533 
1534  time_format (proc_info.cpu_time, time_str);
1536 #endif
1537 
1538  print_value (FIELD_TPS, &mnt_item.tps, FIELD_T_UINT64);
1539  print_value (FIELD_QPS, &mnt_item.qps, FIELD_T_UINT64);
1540 
1541  if (full_info_flag == false)
1542  {
1548  }
1549  sprintf (buf, "%lu/%-.1f", mnt_item.lts, (shm_appl->long_transaction_time / 1000.0));
1551  sprintf (buf, "%lu/%-.1f", mnt_item.lqs, (shm_appl->long_query_time / 1000.0));
1555 
1556  if (full_info_flag && mnt_type == MONITOR_T_BROKER)
1557  {
1561  br_info_p->replica_only_flag), FIELD_T_STRING);
1563  FIELD_T_STRING);
1564  }
1565 
1566  if (mnt_type == MONITOR_T_BROKER)
1567  {
1570  }
1571  else if (mnt_type == MONITOR_T_SHARDDB)
1572  {
1573  print_value (FIELD_REQUEST, &mnt_item_cur_p->num_request, FIELD_T_UINT64);
1574  }
1575  else if (mnt_type == MONITOR_T_PROXY)
1576  {
1579  print_value (FIELD_RESTART, &mnt_item_cur_p->num_restart, FIELD_T_UINT64);
1580 
1581  if (full_info_flag)
1582  {
1583  float stmt_pool_ratio;
1584  if (mnt_item.num_request_stmt <= 0 || mnt_item.num_request_stmt_in_pool > mnt_item.num_request_stmt)
1585  {
1587  }
1588  else
1589  {
1590  stmt_pool_ratio = (mnt_item.num_request_stmt_in_pool * 100) / mnt_item.num_request_stmt;
1591  print_value (FIELD_STMT_POOL_RATIO, &stmt_pool_ratio, FIELD_T_FLOAT);
1592  }
1593  }
1594  }
1595 
1596  print_newline ();
1597  }
1598 
1599  return;
1600 }
1601 
1602 static int
1603 brief_monitor (char *br_vector, MONITOR_TYPE mnt_type, double elapsed_time)
1604 {
1608  static BR_MONITORING_ITEM **mnt_items_old[MONITOR_T_LAST + 1] = { NULL, };
1609  static BR_MONITORING_ITEM *mnt_items_cur_p = NULL;
1610  BR_MONITORING_ITEM *mnt_items_old_p = NULL;
1611  int br_index;
1612  int max_num_mnt_items = 0;
1613  int num_mnt_items;
1614  int max_broker_name_size = FIELD_WIDTH_BROKER_NAME;
1615  int broker_name_size;
1616 
1617  assert (mnt_type <= MONITOR_T_LAST);
1618 
1619  for (br_index = 0; br_index < shm_br->num_broker; br_index++)
1620  {
1621  if (br_vector[br_index] == 0)
1622  {
1623  continue;
1624  }
1625 
1626  broker_name_size = strlen (shm_br->br_info[br_index].name);
1627  if (broker_name_size > max_broker_name_size)
1628  {
1629  max_broker_name_size = broker_name_size;
1630  }
1631  }
1632  if (max_broker_name_size > BROKER_NAME_LEN)
1633  {
1634  max_broker_name_size = BROKER_NAME_LEN;
1635  }
1636  fields[FIELD_BROKER_NAME].width = max_broker_name_size;
1637 
1638  if (mnt_type == MONITOR_T_BROKER)
1639  {
1640  print_monitor_header (mnt_type);
1641  }
1642 
1643  if (mnt_items_old[mnt_type] == NULL)
1644  {
1645  mnt_items_old[mnt_type] = (BR_MONITORING_ITEM **) calloc (sizeof (BR_MONITORING_ITEM *), shm_br->num_broker);
1646  if (mnt_items_old[mnt_type] == NULL)
1647  {
1648  return -1;
1649  }
1650  }
1651 
1652  if (mnt_items_cur_p == NULL)
1653  {
1654  max_num_mnt_items = MAX (MAX (1, MAX_PROXY_NUM), MAX_SHARD_CONN);
1655 
1656  mnt_items_cur_p = (BR_MONITORING_ITEM *) malloc (sizeof (BR_MONITORING_ITEM) * max_num_mnt_items);
1657  if (mnt_items_cur_p == NULL)
1658  {
1659  str_out ("%s", "malloc error");
1660  print_newline ();
1661  return -1;
1662  }
1663  }
1664 
1665  for (br_index = 0; br_index < shm_br->num_broker; br_index++)
1666  {
1667  br_info_p = &shm_br->br_info[br_index];
1668 
1669  if (br_vector[br_index] == 0)
1670  {
1671  continue;
1672  }
1673 
1675  {
1676  continue;
1677  }
1678 
1679  if (mnt_type == MONITOR_T_BROKER)
1680  {
1681  char broker_name[BROKER_NAME_LEN + 1];
1682 
1683  snprintf (broker_name, BROKER_NAME_LEN, "%s", br_info_p->name);
1684  broker_name[BROKER_NAME_LEN] = '\0';
1685  str_out ("*%c", FIELD_DELIMITER);
1687  }
1688  else if (mnt_type == MONITOR_T_SHARDDB || mnt_type == MONITOR_T_PROXY)
1689  {
1690  str_out ("%% %s ", br_info_p->name);
1691  }
1692 
1693  if (br_info_p->service_flag != SERVICE_ON)
1694  {
1695  str_out ("%s", "OFF");
1696  print_newline ();
1697  continue;
1698  }
1699 
1700  if (mnt_type == MONITOR_T_SHARDDB || mnt_type == MONITOR_T_PROXY)
1701  {
1702  if (br_info_p->shard_flag == OFF)
1703  {
1704  str_out ("%s", "SHARD OFF");
1705  print_newline ();
1706  continue;
1707  }
1708  print_newline ();
1709 
1710  print_monitor_header (mnt_type);
1711  }
1712 
1714  if (shm_appl == NULL)
1715  {
1716  str_out ("%s", "shared memory open error");
1717  print_newline ();
1718  return -1;
1719  }
1720 
1721  if (br_info_p->shard_flag == ON)
1722  {
1723  shm_proxy_p = (T_SHM_PROXY *) uw_shm_open (br_info_p->proxy_shm_id, SHM_PROXY, SHM_MODE_MONITOR);
1724  if (shm_proxy_p == NULL)
1725  {
1726  str_out ("%s", "shared memory open error");
1727  print_newline ();
1728  goto error;
1729  }
1730  }
1731 
1732  num_mnt_items = get_num_monitor_items (mnt_type, shm_proxy_p);
1733 
1734  assert (num_mnt_items > 0);
1735 
1736  memset (mnt_items_cur_p, 0, sizeof (BR_MONITORING_ITEM) * num_mnt_items);
1737 
1738  if (mnt_items_old[mnt_type][br_index] == NULL)
1739  {
1740  mnt_items_old[mnt_type][br_index] =
1741  (BR_MONITORING_ITEM *) calloc (sizeof (BR_MONITORING_ITEM), num_mnt_items);
1742  if (mnt_items_old[mnt_type][br_index] == NULL)
1743  {
1744  str_out ("%s", "malloc error");
1745  print_newline ();
1746  goto error;
1747  }
1748  }
1749 
1750  mnt_items_old_p = mnt_items_old[mnt_type][br_index];
1751 
1752  set_monitor_items (mnt_items_cur_p, br_info_p, shm_appl, shm_proxy_p, mnt_type);
1753 
1754  print_monitor_items (mnt_items_cur_p, mnt_items_old_p, num_mnt_items, elapsed_time, br_info_p, shm_appl,
1755  mnt_type);
1756  memcpy (mnt_items_old_p, mnt_items_cur_p, sizeof (BR_MONITORING_ITEM) * num_mnt_items);
1757 
1758  if (shm_appl)
1759  {
1760  uw_shm_detach (shm_appl);
1761  shm_appl = NULL;
1762  }
1763 
1764  if (shm_proxy_p)
1765  {
1766  uw_shm_detach (shm_proxy_p);
1767  shm_proxy_p = NULL;
1768  }
1769  }
1770 
1771  return 0;
1772 
1773 error:
1774  if (shm_appl)
1775  {
1776  uw_shm_detach (shm_appl);
1777  }
1778  if (shm_proxy_p)
1779  {
1780  uw_shm_detach (shm_proxy_p);
1781  }
1782 
1783  return -1;
1784 }
1785 
1786 #ifdef GET_PSINFO
1787 static void
1788 time_format (int t, char *time_str)
1789 {
1790  int min, sec;
1791 
1792  min = t / 60;
1793  sec = t % 60;
1794  sprintf (time_str, "%d:%02d", min, sec);
1795 }
1796 #endif
1797 
1798 static void
1799 print_appl_header (bool use_pdh_flag)
1800 {
1801  char buf[256];
1802  char line_buf[256];
1803  int buf_offset = 0;
1804  int i;
1805 
1806  buf_offset = print_title (buf, buf_offset, FIELD_ID, NULL);
1807 
1808  buf_offset = print_title (buf, buf_offset, FIELD_PID, NULL);
1809  buf_offset = print_title (buf, buf_offset, FIELD_QPS, NULL);
1810  buf_offset = print_title (buf, buf_offset, FIELD_LQS, NULL);
1811 #if defined(WINDOWS)
1812  buf_offset = print_title (buf, buf_offset, FIELD_PORT, NULL);
1813 #endif
1814 #if defined(WINDOWS)
1815  if (use_pdh_flag == true)
1816  {
1817  buf_offset = print_title (buf, buf_offset, FIELD_PSIZE, NULL);
1818  }
1819 #else
1820  buf_offset = print_title (buf, buf_offset, FIELD_PSIZE, NULL);
1821 #endif
1822  buf_offset = print_title (buf, buf_offset, FIELD_STATUS, NULL);
1823 #if 0
1824  buf_offset = print_title (buf, buf_offset, FIELD_PORT, NULL);
1825 #endif
1826 #ifdef GET_PSINFO
1827  buf_offset = print_title (buf, buf_offset, FIELD_CPU_USAGE, NULL);
1828  buf_offset = print_title (buf, buf_offset, FIELD_CPU_TIME, NULL);
1829 #elif WINDOWS
1830  if (use_pdh_flag == true)
1831  {
1832  buf_offset = print_title (buf, buf_offset, FIELD_CPU_USAGE, NULL);
1833  }
1834 #endif
1835  if (full_info_flag)
1836  {
1837  buf_offset = print_title (buf, buf_offset, FIELD_LAST_ACCESS_TIME, NULL);
1838  buf_offset = print_title (buf, buf_offset, FIELD_DB_NAME, NULL);
1839  buf_offset = print_title (buf, buf_offset, FIELD_HOST, NULL);
1840  buf_offset = print_title (buf, buf_offset, FIELD_LAST_CONNECT_TIME, NULL);
1841 
1842  buf_offset = print_title (buf, buf_offset, FIELD_CLIENT_IP, NULL);
1843  buf_offset = print_title (buf, buf_offset, FIELD_CLIENT_VERSION, NULL);
1844 
1845  buf_offset = print_title (buf, buf_offset, FIELD_SQL_LOG_MODE, NULL);
1846 
1847  buf_offset = print_title (buf, buf_offset, FIELD_TRANSACTION_STIME, NULL);
1848  buf_offset = print_title (buf, buf_offset, FIELD_CONNECT, NULL);
1849  buf_offset = print_title (buf, buf_offset, FIELD_RESTART, NULL);
1850 
1851  }
1852 
1853  for (i = 0; i < buf_offset; i++)
1854  line_buf[i] = '-';
1855  line_buf[i] = '\0';
1856 
1857  str_out ("%s", line_buf);
1858  print_newline ();
1859  str_out ("%s", buf);
1860  print_newline ();
1861  str_out ("%s", line_buf);
1862  print_newline ();
1863 }
1864 
1865 #if defined(WINDOWS)
1866 static void
1867 refresh ()
1868 {
1869 }
1870 
1871 static void
1872 move (int x, int y)
1873 {
1874  COORD pos;
1875  pos.X = x;
1876  pos.Y = y;
1877 
1878  SetConsoleCursorPosition (h_console, pos);
1879 }
1880 
1881 static void
1882 clear ()
1883 {
1884  COORD pos = {
1885  0, 0
1886  };
1887  DWORD size;
1888  FillConsoleOutputCharacter (h_console, ' ', scr_info.dwSize.X * scr_info.dwSize.Y, pos, &size);
1889 }
1890 
1891 static void
1892 clrtobot ()
1893 {
1894  CONSOLE_SCREEN_BUFFER_INFO scr_buf_info;
1895  DWORD size;
1896 
1897  if (!GetConsoleScreenBufferInfo (h_console, &scr_buf_info))
1898  {
1899  return;
1900  }
1901  FillConsoleOutputCharacter (h_console, ' ',
1902  (scr_buf_info.dwSize.Y - scr_buf_info.dwCursorPosition.Y) * scr_buf_info.dwSize.X,
1903  scr_buf_info.dwCursorPosition, &size);
1904 }
1905 
1906 static void
1907 clrtoeol ()
1908 {
1909  CONSOLE_SCREEN_BUFFER_INFO scr_buf_info;
1910  DWORD size;
1911 
1912  if (!GetConsoleScreenBufferInfo (h_console, &scr_buf_info))
1913  {
1914  return;
1915  }
1916  FillConsoleOutputCharacter (h_console, ' ', scr_buf_info.dwSize.X - scr_buf_info.dwCursorPosition.X + 1,
1917  scr_buf_info.dwCursorPosition, &size);
1918  move (scr_buf_info.dwSize.X, scr_buf_info.dwCursorPosition.Y);
1919 }
1920 
1921 static void
1922 endwin ()
1923 {
1924  clear ();
1925  move (0, 0);
1926 }
1927 #endif
1928 
1929 static int
1930 metadata_monitor (double elapsed_time)
1931 {
1935 
1936  T_SHARD_USER *user_p;
1937  T_SHARD_KEY *key_p;
1938  T_SHARD_KEY_RANGE *range_p;
1939  T_SHARD_CONN *conn_p;
1940 
1941  T_SHM_SHARD_KEY_STAT *key_stat_p;
1942  T_SHM_SHARD_CONN_STAT *shard_stat_p;
1943 
1946  T_SHARD_INFO *shard_info_p = NULL;
1947 
1948  SHARD_STAT_ITEM *shard_stat_items = NULL;
1949  KEY_STAT_ITEM *key_stat_items = NULL;
1950  INT64 err_queries = 0;
1951 
1952  int shard_stat_items_size;
1953  int key_stat_items_size;
1954  static SHARD_STAT_ITEM *shard_stat_items_old = NULL;
1955  static KEY_STAT_ITEM *key_stat_items_old = NULL;
1956  static INT64 *err_queries_old = NULL;
1957  SHARD_STAT_ITEM *shard_stat_items_old_p = NULL;
1958  KEY_STAT_ITEM *key_stat_items_old_p = NULL;
1959 
1960  int i, j, k;
1961  int shmid;
1962  int col_len;
1963  char buf[1024];
1964  char line_buf[1024];
1965  int num_shard_q_arr[MAX_PROXY_NUM][SHARD_INFO_SIZE_LIMIT];
1966  int proxy_index, shard_index;
1967  int num_proxy, num_shard;
1968 
1969  INT64 num_hint_key_qr;
1970  INT64 num_hint_id_qr;
1971  INT64 num_no_hint_qr;
1972  INT64 num_all_qr;
1973  INT64 num_err_qr;
1974 
1975  INT64 num_range_qr;
1976 
1977  shard_stat_items_size = sizeof (SHARD_STAT_ITEM) * MAX_SHARD_CONN;
1978  key_stat_items_size = sizeof (KEY_STAT_ITEM) * MAX_SHARD_KEY;
1979 
1980  if (err_queries_old == NULL)
1981  {
1982  err_queries_old = (INT64 *) calloc (sizeof (INT64), shm_br->num_broker);
1983  if (err_queries_old == NULL)
1984  {
1985  goto free_and_error;
1986  }
1987  }
1988 
1989  if (shard_stat_items_old == NULL)
1990  {
1991  shard_stat_items_old = (SHARD_STAT_ITEM *) calloc (shard_stat_items_size, shm_br->num_broker);
1992  if (shard_stat_items_old == NULL)
1993  {
1994  goto free_and_error;
1995  }
1996  memset ((void *) shard_stat_items_old, 0, shard_stat_items_size * shm_br->num_broker);
1997  }
1998 
1999  if (key_stat_items_old == NULL)
2000  {
2001  key_stat_items_old = (KEY_STAT_ITEM *) calloc (key_stat_items_size, shm_br->num_broker);
2002  if (key_stat_items_old == NULL)
2003  {
2004  goto free_and_error;
2005  }
2006  memset ((void *) key_stat_items_old, 0, key_stat_items_size * shm_br->num_broker);
2007  }
2008 
2009  for (i = 0; i < shm_br->num_broker; i++)
2010  {
2011  str_out ("%% %s ", shm_br->br_info[i].name);
2012 
2013  if (shm_br->br_info[i].shard_flag == OFF)
2014  {
2015  str_out ("%s", " SHARD OFF");
2016  print_newline ();
2017  continue;
2018  }
2019  if (shm_br->br_info[i].service_flag != SERVICE_ON)
2020  {
2021  str_out ("%s", "OFF");
2022  print_newline ();
2023  continue;
2024  }
2025  shmid = shm_br->br_info[i].proxy_shm_id;
2026  shm_proxy_p = (T_SHM_PROXY *) uw_shm_open (shmid, SHM_PROXY, SHM_MODE_MONITOR);
2027  if (shm_proxy_p == NULL)
2028  {
2029  str_out ("%s", "shared memory open error");
2030  goto free_and_error;
2031  }
2032 
2033  num_proxy = shm_proxy_p->num_proxy;
2034  assert (num_proxy <= MAX_PROXY_NUM);
2035 
2036  num_shard = shm_proxy_p->proxy_info[0].num_shard_conn;
2037  assert (num_shard <= SHARD_INFO_SIZE_LIMIT);
2038 
2039  shard_stat_items_old_p = (SHARD_STAT_ITEM *) (((char *) shard_stat_items_old) + (shard_stat_items_size * i));
2040  key_stat_items_old_p = (KEY_STAT_ITEM *) (((char *) key_stat_items_old) + (key_stat_items_size * i));
2041 
2042  shm_user_p = shard_metadata_get_user (shm_proxy_p);
2043  shm_key_p = shard_metadata_get_key (shm_proxy_p);
2044  shm_conn_p = shard_metadata_get_conn (shm_proxy_p);
2045 
2046  print_newline ();
2047  str_out ("MODULAR : %d, ", shm_br->br_info[i].shard_key_modular);
2048  str_out ("LIBRARY_NAME : %s, ",
2049  (shm_br->br_info[i].shard_key_library_name[0] ==
2050  0) ? "NOT DEFINED" : shm_br->br_info[i].shard_key_library_name);
2051  str_out ("FUNCTION_NAME : %s ",
2052  (shm_br->br_info[i].shard_key_function_name[0] ==
2053  0) ? "NOT DEFINED" : shm_br->br_info[i].shard_key_function_name);
2054  print_newline ();
2055 
2056  /* PRINT CONN INFO */
2057  if (full_info_flag)
2058  {
2059  str_out ("SHARD : ");
2060  for (j = 0; j < num_shard; j++)
2061  {
2062  if (j != 0)
2063  {
2064  str_out (", ");
2065  }
2066  conn_p = (T_SHARD_CONN *) (&(shm_conn_p->shard_conn[j]));
2067  str_out ("%d [%s] [%s]", conn_p->shard_id, conn_p->db_conn_info, conn_p->db_name);
2068  }
2069  print_newline ();
2070  }
2071 
2072  str_out ("ACTIVE-PROXY : %d, ", num_proxy);
2073 
2074  /* PRINT SHARD STATSTICS */
2075 
2076  if (shard_stat_items != NULL)
2077  {
2078  free ((char *) shard_stat_items);
2079  }
2080  shard_stat_items = (SHARD_STAT_ITEM *) malloc (sizeof (SHARD_STAT_ITEM) * shm_conn_p->num_shard_conn);
2081  if (shard_stat_items == NULL)
2082  {
2083  str_out ("%s", "malloc error");
2084  goto free_and_error;
2085  }
2086  memset ((char *) shard_stat_items, 0, sizeof (SHARD_STAT_ITEM) * shm_conn_p->num_shard_conn);
2087 
2088  err_queries = 0;
2089  for (proxy_index = 0; proxy_index < shm_proxy_p->num_proxy; proxy_index++)
2090  {
2091  proxy_info_p = shard_shm_find_proxy_info (shm_proxy_p, proxy_index);
2092 
2093  err_queries += proxy_info_p->num_hint_err_queries_processed;
2094 
2095  shard_stat_p = shard_shm_get_shard_stat (proxy_info_p, 0);
2096  if (shard_stat_p == NULL)
2097  {
2098  str_out ("%s", "shard_stat open error");
2099  goto free_and_error;
2100  }
2101  for (j = 0; j < num_shard; shard_stat_p = shard_shm_get_shard_stat (proxy_info_p, ++j))
2102  {
2103  shard_stat_items[j].num_hint_key_queries_requested += shard_stat_p->num_hint_key_queries_requested;
2104  shard_stat_items[j].num_hint_id_queries_requested += shard_stat_p->num_hint_id_queries_requested;
2105  shard_stat_items[j].num_no_hint_queries_requested += shard_stat_p->num_no_hint_queries_requested;
2106  }
2107  } /* proxy_info loop */
2108 
2109  if (elapsed_time > 0)
2110  {
2111  num_err_qr = err_queries - err_queries_old[i];
2112 
2113  num_err_qr = num_err_qr / elapsed_time;
2114  }
2115  else
2116  {
2117  num_err_qr = err_queries;
2118  }
2119 
2120  str_out ("NUM-NO-HINT-ERR-Q : %d", num_err_qr);
2121 
2122  print_newline ();
2123  print_newline ();
2124 
2125  str_out ("SHARD STATISTICS ");
2126  print_newline ();
2127 
2128  col_len = 0;
2129  col_len += sprintf (buf + col_len, "%5s ", "ID");
2130  col_len += sprintf (buf + col_len, "%10s ", "NUM-KEY-Q");
2131  col_len += sprintf (buf + col_len, "%10s ", "NUM-ID-Q");
2132  col_len += sprintf (buf + col_len, "%15s ", "NUM-NO-HINT-Q");
2133  col_len += sprintf (buf + col_len, "%15s ", "SUM");
2134 
2135  for (k = 0; k < col_len; k++)
2136  {
2137  line_buf[k] = '-';
2138  }
2139  line_buf[k] = '\0';
2140 
2141  str_out ("\t%s", buf);
2142  print_newline ();
2143  str_out ("\t%s", line_buf);
2144  print_newline ();
2145 
2146  for (j = 0; j < num_shard; j++)
2147  {
2148  if (elapsed_time > 0)
2149  {
2150  num_hint_key_qr =
2151  shard_stat_items[j].num_hint_key_queries_requested -
2152  shard_stat_items_old_p[j].num_hint_key_queries_requested;
2153  num_hint_id_qr =
2154  shard_stat_items[j].num_hint_id_queries_requested -
2155  shard_stat_items_old_p[j].num_hint_id_queries_requested;
2156  num_no_hint_qr =
2157  shard_stat_items[j].num_no_hint_queries_requested -
2158  shard_stat_items_old_p[j].num_no_hint_queries_requested;
2159  num_all_qr = num_hint_key_qr + num_hint_id_qr + num_no_hint_qr;
2160 
2161  num_hint_key_qr = num_hint_key_qr / elapsed_time;
2162  num_hint_id_qr = num_hint_id_qr / elapsed_time;
2163  num_no_hint_qr = num_no_hint_qr / elapsed_time;
2164  num_all_qr = num_all_qr / elapsed_time;
2165  }
2166  else
2167  {
2168  num_hint_key_qr = shard_stat_items[j].num_hint_key_queries_requested;
2169  num_hint_id_qr = shard_stat_items[j].num_hint_id_queries_requested;
2170  num_no_hint_qr = shard_stat_items[j].num_no_hint_queries_requested;
2171  num_all_qr = num_hint_key_qr + num_hint_id_qr + num_no_hint_qr;
2172  }
2173 
2174  str_out ("\t%5d %10" PRId64 " %10" PRId64 " %15" PRId64 " %15" PRId64, j, num_hint_key_qr, num_hint_id_qr,
2175  num_no_hint_qr, num_all_qr);
2176 
2177  print_newline ();
2178  }
2179 
2180  print_newline ();
2181 
2182  str_out ("NUM_SHARD_Q");
2183  print_newline ();
2184 
2185  col_len = 0;
2186  memset (buf, '\0', 1024);
2187  col_len += sprintf (buf, "%12s", "PROXY_ID");
2188  for (j = 0; j < num_proxy; j++)
2189  {
2190  col_len += sprintf (buf + col_len, "%7d ", j + 1);
2191  }
2192 
2193  str_out ("\t%s", buf);
2194  print_newline ();
2195 
2196  str_out ("\tSHARD_ID");
2197  print_newline ();
2198 
2199  for (k = 0; k < col_len; k++)
2200  {
2201  line_buf[k] = '-';
2202  }
2203  line_buf[k] = '\0';
2204 
2205  str_out ("\t%s", line_buf);
2206  print_newline ();
2207 
2208  for (proxy_index = 0; proxy_index < num_proxy; proxy_index++)
2209  {
2210  proxy_info_p = shard_shm_find_proxy_info (shm_proxy_p, proxy_index);
2211  for (shard_index = 0; shard_index < num_shard; shard_index++)
2212  {
2213  shard_info_p = shard_shm_find_shard_info (proxy_info_p, shard_index);
2214 
2215  num_shard_q_arr[proxy_index][shard_index] = shard_info_p->waiter_count;
2216  }
2217  }
2218 
2219  for (shard_index = 0; shard_index < num_shard; shard_index++)
2220  {
2221  str_out ("\t%3d", shard_index);
2222  str_out ("%9s", " "); /* it is for matching up with PROXY_ID column */
2223 
2224  for (proxy_index = 0; proxy_index < num_proxy; proxy_index++)
2225  {
2226  print_value (FIELD_SHARD_Q_SIZE, &num_shard_q_arr[proxy_index][shard_index], FIELD_T_INT);
2227  }
2228  print_newline ();
2229  }
2230  print_newline ();
2231 
2232  /* PRINT KEY STATISTICS */
2233  if (full_info_flag)
2234  {
2235  if (key_stat_items != NULL)
2236  {
2237  free ((char *) key_stat_items);
2238  }
2239  key_stat_items = (KEY_STAT_ITEM *) malloc (sizeof (KEY_STAT_ITEM) * shm_key_p->num_shard_key);
2240  if (key_stat_items == NULL)
2241  {
2242  str_out ("%s", "malloc error");
2243  goto free_and_error;
2244  }
2245  memset ((char *) key_stat_items, 0, sizeof (KEY_STAT_ITEM) * shm_key_p->num_shard_key);
2246 
2247  for (proxy_index = 0; proxy_index < num_proxy; proxy_index++)
2248  {
2249  proxy_info_p = shard_shm_find_proxy_info (shm_proxy_p, proxy_index);
2250 
2251  key_stat_p = shard_shm_get_key_stat (proxy_info_p, 0);
2252  if (key_stat_p == NULL)
2253  {
2254  str_out ("%s", "key_stat open error");
2255  goto free_and_error;
2256  }
2257 
2258  for (j = 0; j < proxy_info_p->num_shard_key; key_stat_p = shard_shm_get_key_stat (proxy_info_p, ++j))
2259  {
2260  for (k = 0; k < key_stat_p->num_key_range; k++)
2261  {
2262  key_stat_items[j].num_range_queries_requested[k] +=
2263  key_stat_p->stat[k].num_range_queries_requested;
2264  }
2265  }
2266  }
2267 
2268  for (j = 0; j < shm_key_p->num_shard_key; j++)
2269  {
2270  key_p = (T_SHARD_KEY *) (&(shm_key_p->shard_key[j]));
2271  str_out ("RANGE STATISTICS : %s ", key_p->key_column);
2272  print_newline ();
2273 
2274  col_len = 0;
2275  col_len += sprintf (buf + col_len, "%5s ~ ", "MIN");
2276  col_len += sprintf (buf + col_len, "%5s : ", "MAX");
2277  col_len += sprintf (buf + col_len, "%10s", "SHARD");
2278  col_len += sprintf (buf + col_len, "%10s", "NUM-Q");
2279  for (k = 0; k < col_len; k++)
2280  {
2281  line_buf[k] = '-';
2282  }
2283  line_buf[k] = '\0';
2284 
2285  str_out ("\t%s", buf);
2286  print_newline ();
2287  str_out ("\t%s", line_buf);
2288  print_newline ();
2289 
2290  for (k = 0; k < key_p->num_key_range; k++)
2291  {
2292  range_p = (T_SHARD_KEY_RANGE *) (&(key_p->range[k]));
2293 
2294  if (elapsed_time > 0)
2295  {
2296  num_range_qr =
2297  key_stat_items[j].num_range_queries_requested[k] -
2298  key_stat_items_old_p[j].num_range_queries_requested[k];
2299 
2300  num_range_qr = num_range_qr / elapsed_time;
2301  }
2302  else
2303  {
2304  num_range_qr = key_stat_items[j].num_range_queries_requested[k];
2305  }
2306 
2307  str_out ("\t%5d ~ %5d : %10d %9" PRId64, range_p->min, range_p->max, range_p->shard_id, num_range_qr);
2308  print_newline ();
2309  }
2310  }
2311  }
2312 
2313  /* PRINT USER INFO */
2314  if (full_info_flag)
2315  {
2316  for (j = 0; j < shm_user_p->num_shard_user; j++)
2317  {
2318  user_p = (T_SHARD_USER *) (&(shm_user_p->shard_user[j]));
2319  str_out ("DB Alias : %s [USER : %s]", user_p->db_name, user_p->db_user);
2320  print_newline ();
2321  }
2322  }
2323  print_newline ();
2324 
2325  err_queries_old[i] = num_err_qr;
2326 
2327  if (shard_stat_items)
2328  {
2329  memcpy ((void *) shard_stat_items_old_p, shard_stat_items,
2330  sizeof (SHARD_STAT_ITEM) * shm_conn_p->num_shard_conn);
2331  }
2332 
2333  if (key_stat_items)
2334  {
2335  memcpy ((void *) key_stat_items_old_p, key_stat_items, sizeof (KEY_STAT_ITEM) * shm_key_p->num_shard_key);
2336  }
2337 
2338  uw_shm_detach (shm_proxy_p);
2339 
2340  shm_proxy_p = NULL;
2341  }
2342 
2343  return 0;
2344 
2345 free_and_error:
2346  if (shard_stat_items != NULL)
2347  {
2348  free ((char *) shard_stat_items);
2349  }
2350  if (key_stat_items != NULL)
2351  {
2352  free ((char *) key_stat_items);
2353  }
2354  if (shm_proxy_p != NULL)
2355  {
2356  uw_shm_detach (shm_proxy_p);
2357  }
2358  return -1;
2359 }
2360 
2361 static int
2363 {
2366  T_CLIENT_INFO *client_info_p = NULL;
2367  int i, len, proxy_index, client_index;
2368  char buf[256];
2369  char line_buf[256];
2370  int col_len = 0;
2371  char *ip_str;
2372  struct tm ct1;
2373 
2374  for (i = 0; i < shm_br->num_broker; i++)
2375  {
2376  if (shm_br->br_info[i].shard_flag == OFF)
2377  {
2378  str_out ("%% %s %s", shm_br->br_info[i].name, "SHARD OFF");
2379  print_newline ();
2380  continue;
2381  }
2382  if (shm_br->br_info[i].service_flag != SERVICE_ON)
2383  {
2384  str_out ("%% %s %s", shm_br->br_info[i].name, "OFF");
2385  print_newline ();
2386  continue;
2387  }
2388 
2389  shm_proxy_p = (T_SHM_PROXY *) uw_shm_open (shm_br->br_info[i].proxy_shm_id, SHM_PROXY, SHM_MODE_MONITOR);
2390  if (shm_proxy_p == NULL)
2391  {
2392  str_out ("%s", "shared memory open error");
2393  uw_shm_detach (shm_proxy_p);
2394  return -1;
2395  }
2396 
2397  for (proxy_index = 0; proxy_index < shm_proxy_p->num_proxy; proxy_index++)
2398  {
2399  proxy_info_p = shard_shm_find_proxy_info (shm_proxy_p, proxy_index);
2400 
2401  str_out ("%% %s(%d), MAX-CLIENT : %d, CUR-CLIENT : %d", shm_br->br_info[i].name, proxy_index,
2402  proxy_info_p->max_client, proxy_info_p->cur_client);
2403  print_newline ();
2404  if (full_info_flag)
2405  {
2406  col_len = 0;
2407  col_len += sprintf (buf + col_len, "%10s", "CLIENT-ID");
2408  col_len += sprintf (buf + col_len, "%20s", "CLIENT-IP");
2409  col_len += sprintf (buf + col_len, "%22s", "CONN-TIME");
2410  col_len += sprintf (buf + col_len, "%22s", "LAST-REQ-TIME");
2411  col_len += sprintf (buf + col_len, "%22s", "LAST-RES-TIME");
2412  col_len += sprintf (buf + col_len, "%15s", "LAST-REQ-CODE");
2413 
2414  for (len = 0; len < col_len; len++)
2415  line_buf[len] = '-';
2416  line_buf[len] = '\0';
2417  str_out ("%s", line_buf);
2418  print_newline ();
2419  str_out ("%s", buf);
2420  print_newline ();
2421  str_out ("%s", line_buf);
2422  print_newline ();
2423 
2424  for (client_index = 0; client_index < proxy_info_p->max_context; client_index++)
2425  {
2426  client_info_p = shard_shm_get_client_info (proxy_info_p, client_index);
2427 
2428  if (client_info_p->client_id == -1)
2429  {
2430  continue;
2431  }
2432  str_out ("%10d", client_info_p->client_id);
2433  ip_str = ut_uchar2ipstr ((unsigned char *) (&client_info_p->client_ip));
2434  str_out ("%20s", ip_str);
2435  localtime_r (&client_info_p->connect_time, &ct1);
2436  ct1.tm_year += 1900;
2437  str_out (" %04d/%02d/%02d %02d:%02d:%02d", ct1.tm_year, ct1.tm_mon + 1, ct1.tm_mday, ct1.tm_hour,
2438  ct1.tm_min, ct1.tm_sec);
2439  if (client_info_p->req_time > 0)
2440  {
2441  localtime_r (&client_info_p->req_time, &ct1);
2442  ct1.tm_year += 1900;
2443  str_out (" %04d/%02d/%02d %02d:%02d:%02d", ct1.tm_year, ct1.tm_mon + 1, ct1.tm_mday,
2444  ct1.tm_hour, ct1.tm_min, ct1.tm_sec);
2445  }
2446  else
2447  {
2448  str_out ("%22s", "-");
2449  }
2450 
2451  if (client_info_p->res_time > 0)
2452  {
2453  localtime_r (&client_info_p->res_time, &ct1);
2454  ct1.tm_year += 1900;
2455  str_out (" %04d/%02d/%02d %02d:%02d:%02d", ct1.tm_year, ct1.tm_mon + 1, ct1.tm_mday,
2456  ct1.tm_hour, ct1.tm_min, ct1.tm_sec);
2457  }
2458  else
2459  {
2460  str_out ("%22s", "-");
2461  }
2462 
2463  str_out ("%15d", client_info_p->func_code - 1);
2464  print_newline ();
2465  }
2466  }
2467  }
2468  uw_shm_detach (shm_proxy_p);
2469  }
2470 
2471  return 0;
2472 }
2473 
2474 static int
2476 {
2478  int i, j, u_index;
2479  char buf[LINE_MAX];
2480  int buf_offset;
2481 
2482  buf_offset = 0;
2483  buf_offset = print_title (buf, buf_offset, FIELD_BROKER_NAME, NULL);
2484  buf_offset = print_title (buf, buf_offset, FIELD_UNUSABLE_DATABASES, NULL);
2485 
2486  str_out ("%s", buf);
2487  print_newline ();
2488  for (i = strlen (buf); i > 0; i--)
2489  {
2490  str_out ("%s", "=");
2491  }
2492  print_newline ();
2493 
2494  for (i = 0; i < shm_br->num_broker; i++)
2495  {
2496  str_out ("*%c", FIELD_DELIMITER);
2498 
2499  if (shm_br->br_info[i].service_flag == SERVICE_ON)
2500  {
2501  shm_appl =
2504  if (shm_appl == NULL)
2505  {
2506  str_out ("%s", "shared memory open error");
2507  print_newline ();
2508  }
2509  else
2510  {
2511  if (shm_appl->monitor_server_flag)
2512  {
2513  u_index = shm_appl->unusable_databases_seq % 2;
2514 
2515  for (j = 0; j < shm_appl->unusable_databases_cnt[u_index]; j++)
2516  {
2517  str_out ("%s@%s ", shm_appl->unusable_databases[u_index][j].database_name,
2518  shm_appl->unusable_databases[u_index][j].database_host);
2519  }
2520  }
2521  print_newline ();
2522  uw_shm_detach (shm_appl);
2523  }
2524  }
2525 
2526  else
2527  {
2528  str_out ("%c%s", FIELD_DELIMITER, "OFF");
2529  print_newline ();
2530  }
2531  }
2532 
2533  return 0;
2534 }
2535 
2536 static int
2537 print_title (char *buf_p, int buf_offset, FIELD_NAME name, const char *new_title_p)
2538 {
2539  struct status_field *field_p = NULL;
2540  const char *title_p = NULL;
2541 
2542  assert (buf_p != NULL);
2543  assert (buf_offset >= 0);
2544 
2545  field_p = &fields[name];
2546 
2547  if (new_title_p != NULL)
2548  {
2549  title_p = new_title_p;
2550  }
2551  else
2552  {
2553  title_p = field_p->title;
2554  }
2555 
2556  switch (field_p->name)
2557  {
2558  case FIELD_BROKER_NAME:
2559  buf_offset += sprintf (buf_p + buf_offset, "%c%c", FIELD_DELIMITER, FIELD_DELIMITER);
2560  if (field_p->align == FIELD_LEFT_ALIGN)
2561  {
2562  buf_offset += sprintf (buf_p + buf_offset, "%-*s", field_p->width, title_p);
2563  }
2564  else
2565  {
2566  buf_offset += sprintf (buf_p + buf_offset, "%*s", field_p->width, title_p);
2567  }
2568  break;
2569  default:
2570  if (field_p->align == FIELD_LEFT_ALIGN)
2571  {
2572  buf_offset += sprintf (buf_p + buf_offset, "%-*s", field_p->width, title_p);
2573  }
2574  else
2575  {
2576  buf_offset += sprintf (buf_p + buf_offset, "%*s", field_p->width, title_p);
2577  }
2578  break;
2579  }
2580  buf_offset += sprintf (buf_p + buf_offset, "%c", FIELD_DELIMITER);
2581 
2582  return buf_offset;
2583 }
2584 
2585 static void
2586 print_value (FIELD_NAME name, const void *value_p, FIELD_TYPE type)
2587 {
2588  struct status_field *field_p = NULL;
2589  struct tm cur_tm;
2590  char time_buf[64];
2591 
2592  assert (value_p != NULL);
2593 
2594  field_p = &fields[name];
2595 
2596  switch (type)
2597  {
2598  case FIELD_T_INT:
2599  if (field_p->align == FIELD_LEFT_ALIGN)
2600  {
2601  str_out ("%-*d", field_p->width, *(const int *) value_p);
2602  }
2603  else
2604  {
2605  str_out ("%*d", field_p->width, *(const int *) value_p);
2606  }
2607  break;
2608  case FIELD_T_STRING:
2609  if (field_p->align == FIELD_LEFT_ALIGN)
2610  {
2611  str_out ("%-*s", field_p->width, (const char *) value_p);
2612  }
2613  else
2614  {
2615  str_out ("%*s", field_p->width, (const char *) value_p);
2616  }
2617  break;
2618  case FIELD_T_FLOAT:
2619  if (field_p->align == FIELD_LEFT_ALIGN)
2620  {
2621  str_out ("%-*f", field_p->width, *(const float *) value_p);
2622  }
2623  else
2624  {
2625  str_out ("%*f", field_p->width, *(const float *) value_p);
2626  }
2627  break;
2628  case FIELD_T_UINT64:
2629  if (field_p->align == FIELD_LEFT_ALIGN)
2630  {
2631  str_out ("%-*lu", field_p->width, *(const UINT64 *) value_p);
2632  }
2633  else
2634  {
2635  str_out ("%*lu", field_p->width, *(const UINT64 *) value_p);
2636  }
2637  break;
2638  case FIELD_T_INT64:
2639  if (field_p->align == FIELD_LEFT_ALIGN)
2640  {
2641  str_out ("%-*ld", field_p->width, *(const INT64 *) value_p);
2642  }
2643  else
2644  {
2645  str_out ("%*ld", field_p->width, *(const INT64 *) value_p);
2646  }
2647  break;
2648  case FIELD_T_TIME:
2649  localtime_r ((const time_t *) value_p, &cur_tm);
2650  cur_tm.tm_year += 1900;
2651  sprintf (time_buf, "%02d/%02d/%02d %02d:%02d:%02d", cur_tm.tm_year, cur_tm.tm_mon + 1, cur_tm.tm_mday,
2652  cur_tm.tm_hour, cur_tm.tm_min, cur_tm.tm_sec);
2653  if (field_p->align == FIELD_LEFT_ALIGN)
2654  {
2655  str_out ("%-*s", field_p->width, time_buf);
2656  }
2657  else
2658  {
2659  str_out ("%*s", field_p->width, time_buf);
2660  }
2661  default:
2662  break;
2663  }
2664  str_out ("%c", FIELD_DELIMITER);
2665 }
2666 
2667 static int
2669 {
2670  int num_mnt_items;
2671 
2672  if (mnt_type == MONITOR_T_BROKER)
2673  {
2674  num_mnt_items = 1;
2675  }
2676  else if (mnt_type == MONITOR_T_SHARDDB)
2677  {
2678  num_mnt_items = shm_proxy_p->proxy_info[0].max_shard;
2679  }
2680  else if (mnt_type == MONITOR_T_PROXY)
2681  {
2682  num_mnt_items = shm_proxy_p->num_proxy;
2683  }
2684  else
2685  {
2686  /* invalid MONITOR_TYPE */
2687  assert (false);
2688  num_mnt_items = 0;
2689  }
2690 
2691  return num_mnt_items;
2692 }
2693 
2694 static const char *
2696 {
2697  switch (mode)
2698  {
2699  case SQL_LOG_MODE_NONE:
2700  return "NONE";
2701  case SQL_LOG_MODE_ERROR:
2702  return "ERROR";
2703  case SQL_LOG_MODE_TIMEOUT:
2704  return "TIMEOUT";
2705  case SQL_LOG_MODE_NOTICE:
2706  return "NOTICE";
2707  case SQL_LOG_MODE_ALL:
2708  return "ALL";
2709  default:
2710  return "-";
2711  }
2712 }
2713 
2714 static const char *
2716 {
2717  switch (mode)
2718  {
2719  case READ_ONLY_ACCESS_MODE:
2720  return (replica_only_flag ? "RO-REPLICA" : "RO");
2722  return (replica_only_flag ? "SO-REPLICA" : "SO");
2724  return (replica_only_flag ? "RW-REPLICA" : "RW");
2725  default:
2726  return "--";
2727  }
2728 }
2729 
2730 static const char *
2731 get_status_string (T_APPL_SERVER_INFO * as_info_p, char appl_server)
2732 {
2733  assert (as_info_p != NULL);
2734 
2735  if (as_info_p->uts_status == UTS_STATUS_BUSY)
2736  {
2737  if (IS_APPL_SERVER_TYPE_CAS (appl_server))
2738  {
2739  if (as_info_p->con_status == CON_STATUS_OUT_TRAN)
2740  {
2741  return "CLOSE_WAIT";
2742  }
2743  else if (as_info_p->log_msg[0] == '\0')
2744  {
2745  return "CLIENT_WAIT";
2746  }
2747  else
2748  {
2749  return "BUSY";
2750  }
2751  }
2752  else
2753  {
2754  return "BUSY";
2755  }
2756  }
2757 #if defined(WINDOWS)
2758  else if (as_info_p->uts_status == UTS_STATUS_BUSY_WAIT)
2759  {
2760  return "BUSY";
2761  }
2762 #endif
2763  else if (as_info_p->uts_status == UTS_STATUS_RESTART)
2764  {
2765  return "INITIALIZE";
2766  }
2767  else if (as_info_p->uts_status == UTS_STATUS_CON_WAIT)
2768  {
2769  return "CON WAIT";
2770  }
2771  else
2772  {
2773  return "IDLE";
2774  }
2775 
2776  return NULL;
2777 }
2778 
2779 static void
2780 get_cpu_usage_string (char *buf_p, float usage)
2781 {
2782  assert (buf_p != NULL);
2783 
2784  if (usage >= 0)
2785  {
2786  sprintf (buf_p, "%.2f", usage);
2787  }
2788  else
2789  {
2790  sprintf (buf_p, " - ");
2791  }
2792 }
#define SLEEP_MILISEC(sec, msec)
Definition: util_func.h:40
void ut_cd_work_dir(void)
Definition: broker_util.c:335
DllImport int optind
INT64 num_no_hint_queries_requested
#define FIELD_DELIMITER
char shard_key_library_name[BROKER_INFO_NAME_MAX]
static void print_monitor_items(BR_MONITORING_ITEM *mnt_items_cur, BR_MONITORING_ITEM *mnt_items_old, int num_mnt_items, double elapsed_time, T_BROKER_INFO *br_info_p, T_SHM_APPL_SERVER *shm_appl, MONITOR_TYPE mnt_type)
INT64 num_long_transactions
Definition: broker_shm.h:347
char database_name[SRV_CON_DBNAME_SIZE]
Definition: broker_shm.h:552
static int refresh_sec
char database_name[SRV_CON_DBNAME_SIZE]
Definition: broker_shm.h:352
DllImport char * optarg
#define TRUE
Definition: broker_admin.c:49
static void print_job_queue(T_MAX_HEAP_NODE *)
int max_heap_delete(T_MAX_HEAP_NODE *max_heap, T_MAX_HEAP_NODE *ret)
static char service_filter_value
int num_shard_key
Definition: broker_shm.h:513
T_BROKER_INFO br_info[1]
Definition: broker_shm.h:661
T_MAX_HEAP_NODE job_queue[JOB_QUEUE_MAX_SIZE+1]
Definition: broker_shm.h:637
#define PRINT_AND_LOG_ERR_MSG(...)
Definition: util_func.h:49
char shard_key_function_name[BROKER_INFO_NAME_MAX]
T_PROXY_INFO proxy_info[MAX_PROXY_NUM]
Definition: broker_shm.h:545
T_SHARD_INFO * shard_shm_find_shard_info(T_PROXY_INFO *proxy_info_p, int shard_id)
Definition: shard_shm.c:433
INT64 num_no_hint_queries_requested
Definition: broker_shm.h:432
int getopt(int, char *const *, const char *)
#define FIELD_WIDTH_BROKER_NAME
T_SHARD_CONN shard_conn[MAX_SHARD_CONN]
Definition: broker_shm.h:286
#define SHM_BROKER
Definition: broker_shm.h:64
int argc
Definition: dynamic_load.c:951
char * ut_get_ipv4_string(char *ip_str, int len, const unsigned char *ip_addr)
Definition: broker_util.c:474
T_PROXY_INFO * shard_shm_find_proxy_info(T_SHM_PROXY *proxy_p, int proxy_id)
Definition: shard_shm.c:419
unsigned char cas_clt_ip[4]
Definition: broker_shm.h:323
#define JOB_QUEUE_MAX_SIZE
Definition: broker_shm.h:116
static int print_title(char *buf_p, int buf_offset, FIELD_NAME name, const char *new_title_p)
#define SHARDDB_MONITOR_FLAG_MASK
time_t last_access_time
Definition: broker_shm.h:317
char broker_name[BROKER_NAME_LEN]
Definition: cas.c:148
static T_BROKER_INFO * br_info_p
Definition: broker.c:312
char log_msg[SHM_LOG_MSG_SIZE]
Definition: broker_shm.h:342
static int last_access_sec
static const char * get_access_mode_string(T_ACCESS_MODE_VALUE mode, int replica_only_flag)
FIELD_ALIGN
#define SHM_PROXY
Definition: broker_shm.h:65
T_SHARD_KEY_RANGE range[SHARD_KEY_RANGE_MAX]
Definition: broker_shm.h:263
static int brief_monitor(char *br_vector, MONITOR_TYPE mnt_type, double elapsed_time)
int num_key_range
Definition: broker_shm.h:262
static T_SHM_PROXY * shm_proxy_p
Definition: broker.c:313
FIELD_NAME
int unusable_databases_cnt[PAIR_LIST]
Definition: broker_shm.h:627
char title[256]
#define UTS_STATUS_RESTART
Definition: broker_shm.h:47
struct status_field fields[FIELD_LAST+1]
T_SHM_SHARD_CONN * shard_metadata_get_conn(T_SHM_PROXY *shm_proxy_p)
INT64 num_unique_error_queries
Definition: broker_shm.h:369
static int appl_monitor(char *br_vector, double elapsed_time)
static void appl_info_display(T_SHM_APPL_SERVER *shm_appl, T_APPL_SERVER_INFO *as_info_p, int br_index, int as_index, APPL_MONITORING_ITEM *appl_mnt_old, time_t current_time, double elapsed_time)
INT64 num_queries_processed
Definition: broker_shm.h:345
T_SHM_SHARD_CONN_STAT * shard_shm_get_shard_stat(T_PROXY_INFO *proxy_info_p, int idx)
Definition: shard_shm.c:463
T_SHARD_INFO shard_info[SHARD_INFO_SIZE_LIMIT]
Definition: broker_shm.h:520
INT64 num_delete_queries
Definition: broker_shm.h:367
#define UTS_STATUS_BUSY
Definition: broker_shm.h:45
T_DB_SERVER unusable_databases[PAIR_LIST][UNUSABLE_DATABASE_MAX]
Definition: broker_shm.h:643
#define FIELD_WIDTH_AS_ID
T_SHM_SHARD_USER * shard_metadata_get_user(T_SHM_PROXY *shm_proxy_p)
static int state_interval
static void print_appl_header(bool use_pdh_flag)
INT64 num_update_queries
Definition: broker_shm.h:366
time_t connect_time
Definition: broker_shm.h:390
unsigned int width
#define PROXY_MONITOR_FLAG_MASK
INT64 num_insert_queries
Definition: broker_shm.h:365
char db_name[SRV_CON_DBNAME_SIZE]
Definition: broker_shm.h:234
T_SHM_SHARD_KEY_RANGE_STAT stat[SHARD_KEY_RANGE_MAX]
Definition: broker_shm.h:450
INT64 num_connect_requests
Definition: broker_shm.h:506
static void set_monitor_items(BR_MONITORING_ITEM *mnt_items, T_BROKER_INFO *br_info, T_SHM_APPL_SERVER *shm_appl, T_SHM_PROXY *shm_proxy, MONITOR_TYPE mnt_type)
time_t req_time
Definition: broker_shm.h:402
int broker_config_read(const char *conf_file, T_BROKER_INFO *br_info, int *num_broker, int *br_shm_id, char *admin_log_file, char admin_flag, bool *acl_flag, char *acl_file, char *admin_err_msg)
#define MAX_BROKER_NUM
Definition: broker_config.h:50
char database_host[CUB_MAXHOSTNAMELEN]
Definition: broker_shm.h:553
MONITOR_TYPE
int main(int argc, char **argv)
static void get_cpu_usage_string(char *buf_p, float usage)
INT64 num_range_queries_requested[SHARD_KEY_RANGE_MAX]
unsigned int unusable_databases_seq
Definition: broker_shm.h:628
static void print_newline()
#define UTS_STATUS_CON_WAIT
Definition: broker_shm.h:52
static void print_usage(void)
#define assert(x)
static bool display_job_queue
static void time2str(const time_t t, char *str)
static void print_monitor_header(MONITOR_TYPE mnt_type)
INT64 num_connect_requests
Definition: broker_shm.h:358
int proxy_id
Definition: shard_proxy.c:45
INT64 num_hint_err_queries_processed
Definition: broker_shm.h:499
static int get_args(int argc, char *argv[], char *br_vector)
int num_shard_conn
Definition: broker_shm.h:514
void uw_shm_detach(void *p)
Definition: broker_shm.c:700
T_SHM_SHARD_KEY * shm_key_p
Definition: shard_proxy.c:51
static int unusable_databases_monitor(void)
static enum scanner_mode mode
#define SHARD_KEY_RANGE_MAX
Definition: broker_shm.h:148
static bool tty_mode
#define SHARD_INFO_SIZE_LIMIT
#define min(a, b)
#define UNUSABLE_DATABASES_FLAG_MASK
enum t_sql_log_mode_value T_SQL_LOG_MODE_VALUE
INT64 num_restarts
Definition: broker_shm.h:508
static void str_to_screen(const char *msg)
time_t transaction_start_time
Definition: broker_shm.h:318
static int client_monitor(void)
T_SHM_SHARD_USER * shm_user_p
Definition: shard_proxy.c:50
#define NULL
Definition: freelistheap.h:34
#define BROKER_NAME_LEN
Definition: broker_config.h:87
INT64 num_connect_rejected
Definition: broker_shm.h:507
T_CLIENT_INFO * shard_shm_get_client_info(T_PROXY_INFO *proxy_info_p, int idx)
Definition: shard_shm.c:448
static int get_char(void)
char db_conn_info[MAX_CONN_INFO_LENGTH]
Definition: broker_shm.h:279
#define CLIENT_MONITOR_FLAG_MASK
char script[PRE_SEND_SCRIPT_SIZE]
#define err(fd,...)
Definition: porting.h:431
INT64 num_transactions_processed
Definition: broker_shm.h:344
T_SHM_SHARD_KEY * shard_metadata_get_key(T_SHM_PROXY *shm_proxy_p)
static unsigned int monitor_flag
INT64 num_hint_key_queries_requested
Definition: broker_shm.h:430
static T_SHM_APPL_SERVER * shm_appl
Definition: broker.c:311
enum t_access_mode_value T_ACCESS_MODE_VALUE
char database_host[CUB_MAXHOSTNAMELEN]
Definition: broker_shm.h:353
time_t res_time
Definition: broker_shm.h:403
struct timeval tran_start_time
Definition: cas.c:157
T_PROXY_INFO * proxy_info_p
Definition: shard_proxy.c:48
static void error(const char *msg)
Definition: gencat.c:331
char prg_name[PRE_SEND_PRG_NAME_SIZE]
INT64 num_request_stmt_in_pool
Definition: broker_shm.h:504
static int br_index
Definition: broker.c:315
#define IS_APPL_SERVER_TYPE_CAS(x)
Definition: broker_config.h:39
time_t last_connect_time
Definition: broker_shm.h:357
struct key_stat_item KEY_STAT_ITEM
#define MAX_SHARD_KEY
Definition: broker_shm.h:144
T_SHARD_KEY shard_key[MAX_SHARD_KEY]
Definition: broker_shm.h:270
INT64 num_request_stmt
Definition: broker_shm.h:503
bool monitor_server_flag
Definition: broker_shm.h:630
INT64 num_requests_received
Definition: broker_shm.h:343
INT64 num_hint_id_queries_requested
INT64 waiter_count
Definition: broker_shm.h:420
INT64 num_hint_id_queries_requested
Definition: broker_shm.h:431
#define MAX_SHARD_CONN
Definition: broker_shm.h:145
T_SHM_SHARD_KEY_STAT * shard_shm_get_key_stat(T_PROXY_INFO *proxy_info_p, int idx)
Definition: shard_shm.c:478
static void str_out(const char *fmt,...)
const char ** argv
Definition: dynamic_load.c:952
T_SHARD_USER shard_user[1]
Definition: broker_shm.h:243
#define strlen(s1)
Definition: intl_support.c:43
unsigned char ip_addr[4]
static void print_value(FIELD_NAME name, const void *value, FIELD_TYPE type)
static int metadata_monitor(double elapsed_time)
#define MAX_PROXY_NUM
Definition: broker_shm.h:135
char key_column[SHARD_KEY_COLUMN_LEN]
Definition: broker_shm.h:261
char name[BROKER_NAME_LEN]
static void ip2str(unsigned char *ip, char *ip_str)
int get_psinfo(int pid, T_PSINFO *ps)
static int get_num_monitor_items(MONITOR_TYPE mnt_type, T_SHM_PROXY *shm_proxy_p)
INT64 num_hint_key_queries_requested
char driver_version[SRV_CON_VER_STR_MAX_SIZE]
Definition: broker_shm.h:305
static const char * get_status_string(T_APPL_SERVER_INFO *as_info_p, char appl_server)
T_APPL_SERVER_INFO as_info[APPL_SERVER_NUM_LIMIT]
Definition: broker_shm.h:641
int num_appl_server
Definition: broker_shm.h:417
static T_SHM_BROKER * shm_br
int i
Definition: dynamic_load.c:954
#define BROKER_MONITOR_FLAG_MASK
FIELD_ALIGN align
INT64 num_select_queries
Definition: broker_shm.h:364
INT64 num_proxy_error_processed
Definition: broker_shm.h:501
FIELD_NAME name
int getsize(int pid)
#define METADATA_MONITOR_FLAG_MASK
char * ut_uchar2ipstr(unsigned char *ip_addr)
Definition: cas_util.c:43
char db_user[SRV_CON_DBUSER_SIZE]
Definition: broker_shm.h:235
void * uw_shm_open(int shm_key, int which_shm, T_SHM_MODE shm_mode)
Definition: broker_shm.c:139
void usage(void)
static bool full_info_flag
#define makestring(x)
T_SHM_SHARD_CONN * shm_conn_p
Definition: shard_proxy.c:52
UINT64 num_request_stmt_in_pool
static const char * get_sql_log_mode_string(T_SQL_LOG_MODE_VALUE mode)
INT64 num_connect_rejected
Definition: broker_shm.h:359
FIELD_TYPE
struct shard_stat_item SHARD_STAT_ITEM
char db_name[MAX_DBNAME_LENGTH]
Definition: broker_shm.h:278
void clear(cub_regex_object *&regex, char *&pattern)
#define SHM_APPL_SERVER
Definition: broker_shm.h:63