#include <stdio.h> #include <time.h> #include <sys/types.h> #include <errno.h> #include "template.h" #include "netmap.h" #include "ksnmplib_protos.h" void ask_seq(); void ask_par(); void Decode_Procs_Seq(); void Decode_Procs_Par(); extern char ownpname[]; /*---------------------------------------------------------------*/ /* Definitions for the User Variable Dictionary */ /*---------------------------------------------------------------*/ struct var_dict_type var_dict_usr[20]; int var_number_usr = 0; /*---------------------------------------------------------------*/ /* Definitions for the User Command Dictionary */ /*---------------------------------------------------------------*/ struct cmd_dict_type cmd_dict_usr[20]; int cmd_number_usr = 0; int getint(char *procname, char *varname) { struct var_dict_type var_struct; if(Get_Value(procname,varname,&var_struct) != SUCCESS) { printf("Error in getint(%s,%s)\n",procname,varname); return 0; } if(var_struct.type != INTEGER) { printf("Error in getint(%s,%s); not an integer\n",procname,varname); return 0; } return(*(int *)var_struct.addr); } char *getstring(char *procname, char *varname) { struct var_dict_type var_struct; if(Get_Value(procname,varname,&var_struct) != SUCCESS) { printf("Error in getstring(%s,%s)\n",procname,varname); return((char *) NULL); } if(var_struct.type != STRING) { printf("Error in getstring(%s,%s); not a string\n",procname,varname); return((char *) NULL); } return((char *)var_struct.addr); } int main(int argc, char *argv[]) { int loop_flag,i,j; int create_flag=0; char destination[80]; strcpy(ownpname, "rsd_status"); if (Attach_Table() == RETURN_ERROR){ printf("Error in Attach_Table()\n"); exit(0); } /* Map the common table */ init_mib(); /* initialize the MIB variables */ ksnmp_init(); /* initialize ksnmp */ if (argc == 1) strcpy(destination, "rspydaemon"); else strcpy(destination, argv[1]); printf("\n==================================================================\n"); printf("rsd_status of process %s\n",destination); printf("\n==================================================================\n"); { int msecs,bytes,runstate; runstate = getint(destination,"runstate"); printf("State: "); switch (runstate) { case UNDEFINED_STATE: printf("Undefined"); break; case INIT_STATE: printf("Initialized"); break; case RUNNING_STATE: printf("Running"); break; case PAUSE_STATE: printf("Paused"); break; } printf("\n\n"); if (getint(destination,"no_conn")==0) { int maxevents = getint(destination,"maxevents"); if (maxevents>=0) printf("Receiving up to %i events per packet from %s port %i\n", maxevents, getstring(destination,"raddr"),getint(destination,"rport")); else printf("Receiving packets from %s port %i\n", getstring(destination,"raddr"),getint(destination,"rport")); } else { printf("Not connected\n"); } if ((runstate==RUNNING_STATE) || (runstate==PAUSE_STATE)) printf("Writing to circ. buf. %s of size %i\n", getstring(destination,"lname"), getint(destination,"circsize")); printf("\n"); printf("%i timouts of up to %.3fs up to now.\n", getint(destination,"timeouts"), (1.e-6*getint(destination,"timeout_us"))*getint(destination,"timeoutcounts")); printf("Ignored %i packets.\n", getint(destination,"ignored")); printf("\n"); msecs = getint(destination,"sg_msecs"); if (msecs>0) { char timestr[256]; time_t timeval; timeval = getint(destination,"sg_uptime"); strftime(timestr,255,"%H:%M:%S", localtime(&timeval)); printf("Long term statistics: (uptime: %s)\n",timestr); printf("Running %.1fs CPU occupancy %.2f%%\n", msecs*1.e-3, getint(destination,"sg_cpu")*1.e-7); bytes = getint(destination,"sg_bytes"); printf("Received %i packets or %i bytes => %.2f bytes/s\n", getint(destination,"sg_packs"), bytes,bytes*1.e3/msecs); printf("\n"); } msecs = getint(destination,"sl_msecs"); if (msecs>0) { char timestr[256]; time_t timeval; timeval = getint(destination,"sl_uptime"); strftime(timestr,255,"%H:%M:%S", localtime(&timeval)); printf("Short term statistics: (uptime: %s)\n",timestr); printf("Period %.1fs CPU occupancy %.2f%%\n", msecs*1.e-3, getint(destination,"sl_cpu")*1.e-7); bytes = getint(destination,"sl_bytes"); printf("Received %i packets or %i bytes => %.2f bytes/s\n", getint(destination,"sl_packs"), bytes,bytes*1.e3/msecs); printf("\n"); } } printf("==================================================================\n"); if (Detach_Table() == RETURN_ERROR){ if (debug_level >= 10) printf("Error in Detach_Table()\n"); } if (create_flag) Delete_Table(); }