crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

showstatus.c (2915B)


      1 /*************************************************************************
      2  * This file is part of Crosroads 1.23, a load balancer and fail over
      3  * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL.
      4  * Visit http://crossroads.e-tunity.com for information.
      5  *************************************************************************/
      6 #include "crossroads.h"
      7 
      8 static char *timestr (double nsec) {
      9     static char *buf;
     10     char *tmp;
     11     
     12     free (buf);
     13     buf = 0;
     14 
     15     if (nsec > 3600) {
     16 	buf = str_printf ("%uh", (unsigned) (nsec / 3600));
     17 	nsec = fmod (nsec, 3600);
     18     }
     19     if (nsec > 60) {
     20 	tmp = str_printf ("%um", (unsigned) (nsec / 60));
     21 	nsec = fmod (nsec, 60);
     22 	buf = xstrcat (buf, tmp);
     23 	free (tmp);
     24     }
     25     tmp = str_printf ("%.2fs", nsec);
     26     buf = xstrcat (buf, tmp);
     27     free (tmp);
     28 
     29     return (buf);
     30 }
     31 
     32 static char *bytestr (unsigned long long nbytes) {
     33     static char *buf;
     34 
     35     free (buf);
     36     
     37     if (nbytes > (double)1024*1024*1024*1024)
     38 	buf = str_printf ("%.2fTb",
     39 			  ((double) nbytes) /
     40 			  ((double) 1024*1024*1024*1024));
     41     else if (nbytes > 1024*1024*1024)
     42 	buf = str_printf ("%.2fGb",
     43 			  ((double) nbytes) /
     44 			  ((double) 1024*1024*1024));
     45     else if (nbytes > 1024*1024)
     46 	buf = str_printf ("%.2fMb",
     47 			  ((double) nbytes) /
     48 			  ((double) 1024*1024));
     49     else if (nbytes > 1024)
     50 	buf = str_printf ("%.2fKb",
     51 			  ((double) nbytes) /
     52 			  (double) 1024);
     53     else
     54 	buf = str_printf ("%llub", nbytes);
     55 
     56     return (buf);
     57 }
     58 
     59 int show_status (int ac, char **av) {
     60     int i, j;
     61 
     62     for (i = 0; i < nservice; i++) {
     63 	if (i)
     64 	    putchar ('\n');
     65 	alloc_reporter (service + i, 0);
     66 	msg ("Reporting service %s (pid = %d)",
     67 	     service[i].name, servicereport->pid);
     68 	printf ("Service      : %s, %d live connections, last backend %d\n",
     69 		service[i].name, servicereport->nclients,
     70 		servicereport->last_backend);
     71 	for (j = 0; j < service[i].nbackend; j++) {
     72             printf ("  Backend %2d : %s is %s, %u live connections\n"
     73                     "    Stats    : %lu failures out of %lu connections",
     74 		    j,
     75 		    service[i].backend[j].name,
     76 		    state_to_string (servicereport->backendstate[j].avail),
     77 		    servicereport->backendstate[j].nclients,
     78 		    servicereport->backendstate[j].failures,
     79 		    servicereport->backendstate[j].totuses);
     80 	    if (service[i].type == type_http)
     81 		printf (", %lu sessions,",
     82 			servicereport->backendstate[j].sessions);
     83             printf ("\n"
     84 		    "               usage %s, %s",
     85 		    timestr (servicereport->backendstate[j].nsec),
     86 		    bytestr (servicereport->backendstate[j].nbytes));
     87 	    if (service[i].dispatchover)
     88 		printf (", avg %s, %s",
     89 			timestr(servicereport->backendstate[j].avg_nsec),
     90 			bytestr(servicereport->backendstate[j].avg_nbytes));
     91 	    putchar ('\n');
     92 	}
     93 	
     94 	if (shmdt (servicereport) < 0)
     95 	    error ("Failure releasing reporter memory: %s",
     96 		   strerror(errno));
     97     }
     98 
     99     return (1);
    100 }