Changeset 115 for trunk

Show
Ignore:
Timestamp:
06/25/09 12:38:15 (13 years ago)
Author:
andreu
Message:

ticket#27 continuation

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/renetcolAgg.c

    r96 r115  
    719719#endif 
    720720#endif /* AS */ 
     721        if (rrdMibsUpdate(index) != 1) {syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");} 
    721722        now2 = time((time_t *)NULL); 
    722723#ifdef DEBUGAGG 
     
    738739      } else { 
    739740        isFirstUpdate = 0; 
    740         /* Reinit the shared table */ 
     741        /* RRD Update only for the MIB counters, else we clear all counters in shared memory (after) */ 
     742        if (rrdMibsUpdate(index) != 1) {syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");} 
     743        /* CLEAR */ 
    741744        for (i=0; i<shmForAgg->v4PrefixNb; i++){ 
    742745          shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; 
     
    771774          shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;  
    772775        } 
    773         /* reinit */ 
    774776#ifdef MATRIX 
    775777        for (i=0; i<ROUTER_INDEX_MAX; i++){ 
     
    803805        } 
    804806#endif 
     807        /* reinit */ 
    805808      } /* end is first update */  
    806809    } /* end read ok */ 
     
    809812  exit(0); 
    810813} 
     814 
     815 
     816/* 
     817 * rrdMibsUpdate 
     818 */ 
     819short rrdMibsUpdate(int index) 
     820{ 
     821  int i, j, k = 0; 
     822  int rrd_update_er_ct = 0; 
     823  int rrd_update_ok_ct = 0; 
     824  int rrd_already_created_ct = 0; 
     825  int rrd_create_er_ct = 0; 
     826  int rrd_create_ok_ct = 0; 
     827  static char buf[2048]; 
     828  static char name[2048]; 
     829  static char createstr[2048]; 
     830  char *opt[27]; 
     831  char *optUpdate[3]; 
     832  FILE *fp; 
     833  static time_t now, now2; 
     834 
     835  now = time((time_t *)NULL); 
     836  for (k=0; k<strlen(name); k++) {name[k] = '\0';} 
     837  for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} 
     838  strcat(name, MIB_RRD_LOCATION); 
     839  strcat(name, GLOBAL_MIB_RRD_FILE); 
     840  if ( (fp=fopen(name,"r")) == NULL ){ 
     841    opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_0) + 1) * sizeof(char)); 
     842    strcpy(opt[0], RRD_PARAM_MIB_0); 
     843    opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     844    strcpy(opt[1], name); 
     845    opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_1) + 1) * sizeof(char)); 
     846    strcpy(opt[2], RRD_PARAM_MIB_1); 
     847    opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_2) + 1) * sizeof(char)); 
     848    strcpy(opt[3], RRD_PARAM_MIB_2); 
     849    opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_3) + 1) * sizeof(char)); 
     850    strcpy(opt[4], RRD_PARAM_MIB_3); 
     851    opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_4) + 1) * sizeof(char)); 
     852    strcpy(opt[5], RRD_PARAM_MIB_4); 
     853    opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_5) + 1) * sizeof(char)); 
     854    strcpy(opt[6], RRD_PARAM_MIB_5); 
     855    opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_6) + 1) * sizeof(char)); 
     856    strcpy(opt[7], RRD_PARAM_MIB_6); 
     857    opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_7) + 1) * sizeof(char)); 
     858    strcpy(opt[8], RRD_PARAM_MIB_7); 
     859    opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_8) + 1) * sizeof(char)); 
     860    strcpy(opt[9], RRD_PARAM_MIB_8); 
     861    opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_9) + 1) * sizeof(char)); 
     862    strcpy(opt[10], RRD_PARAM_MIB_9); 
     863    opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_10) + 1) * sizeof(char)); 
     864    strcpy(opt[11], RRD_PARAM_MIB_10); 
     865    opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_11) + 1) * sizeof(char)); 
     866    strcpy(opt[12], RRD_PARAM_MIB_11); 
     867    opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_12) + 1) * sizeof(char)); 
     868    strcpy(opt[13], RRD_PARAM_MIB_12); 
     869    opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_13) + 1) * sizeof(char)); 
     870    strcpy(opt[14], RRD_PARAM_MIB_13); 
     871    opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_14) + 1) * sizeof(char)); 
     872    strcpy(opt[15], RRD_PARAM_MIB_14); 
     873    opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_15) + 1) * sizeof(char)); 
     874    strcpy(opt[16], RRD_PARAM_MIB_15); 
     875    opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_16) + 1) * sizeof(char)); 
     876    strcpy(opt[17], RRD_PARAM_MIB_16); 
     877    opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_17) + 1) * sizeof(char)); 
     878    strcpy(opt[18], RRD_PARAM_MIB_17); 
     879    opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_18) + 1) * sizeof(char)); 
     880    strcpy(opt[19], RRD_PARAM_MIB_18); 
     881    opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_19) + 1) * sizeof(char)); 
     882    strcpy(opt[20], RRD_PARAM_MIB_19); 
     883    opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_20) + 1) * sizeof(char)); 
     884    strcpy(opt[21], RRD_PARAM_MIB_20); 
     885    opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_21) + 1) * sizeof(char)); 
     886    strcpy(opt[22], RRD_PARAM_MIB_21); 
     887    opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_22) + 1) * sizeof(char)); 
     888    strcpy(opt[23], RRD_PARAM_MIB_22); 
     889    optind = opterr = 0; 
     890    rrd_clear_error(); 
     891    if ( rrd_create(24,opt) < 0) { 
     892      syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     893      rrd_create_er_ct++; 
     894    } else { 
     895      rrd_create_ok_ct++; 
     896    } 
     897    for ( k=0; k<24; k++) { 
     898      free(opt[k]); 
     899      opt[k] = NULL; 
     900    } 
     901  }else{  
     902    fclose(fp); 
     903    rrd_already_created_ct++; 
     904    snprintf(buf,  
     905             2048,  
     906             "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",   
     907             now-300,  /* or ctime(&now) with %s */ 
     908             shmForAgg->myMIB[index].ipPacketNb, 
     909             shmForAgg->myMIB[index].udpPacketNb, 
     910             shmForAgg->myMIB[index].v9PacketNb, 
     911             shmForAgg->myMIB[index].v9UnSeqNb, 
     912             shmForAgg->myMIB[index].flowSetNb, 
     913             shmForAgg->myMIB[index].dataFlowSetNb, 
     914             shmForAgg->myMIB[index].defFlowSetNb, 
     915             shmForAgg->myMIB[index].optDataFlowSetNb, 
     916             shmForAgg->myMIB[index].optDefFlowSetNb, 
     917             shmForAgg->myMIB[index].flowNb, 
     918             shmForAgg->myMIB[index].realFlowNb 
     919             ); 
     920    fprintf(stderr,"\n%s\n",buf); 
     921    optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     922    strcpy(optUpdate[0], RRD_UPDATE_0); 
     923    optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     924    strcpy(optUpdate[1], name); 
     925    optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     926    strcpy(optUpdate[2], buf); 
     927    optind = opterr = 0;  
     928    rrd_clear_error(); 
     929    if ( rrd_update(3, optUpdate) < 0 ) {  
     930      syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     931      rrd_update_er_ct++; 
     932    } else { 
     933      rrd_update_ok_ct++; 
     934    } 
     935    for ( k=0; k<3; k++) { 
     936      free(optUpdate[k]); 
     937      optUpdate[k] = NULL; 
     938    } 
     939  } 
     940  shmForAgg->myMIB[index].ipPacketNb = 0; 
     941  shmForAgg->myMIB[index].udpPacketNb = 0; 
     942  shmForAgg->myMIB[index].v9PacketNb = 0; 
     943  shmForAgg->myMIB[index].v9UnSeqNb = 0; 
     944  shmForAgg->myMIB[index].flowSetNb = 0; 
     945  shmForAgg->myMIB[index].dataFlowSetNb = 0; 
     946  shmForAgg->myMIB[index].defFlowSetNb = 0; 
     947  shmForAgg->myMIB[index].optDataFlowSetNb = 0; 
     948  shmForAgg->myMIB[index].optDefFlowSetNb = 0; 
     949  shmForAgg->myMIB[index].flowNb = 0; 
     950  shmForAgg->myMIB[index].realFlowNb = 0; 
     951  return 1; 
     952} 
  • trunk/src/renetcolAgg.h

    r113 r115  
    4343#include "renetcolParam.h" 
    4444#include "as.h" 
     45#include "renetcol_mib.h" 
    4546 
    4647struct SHMForAgg { /* if you change it, you must change renetcol.h structure */ 
     
    6667  struct RenetcolMIB myMIB[2]; 
    6768};  
     69 
     70short rrdMibsUpdate(int); 
  • trunk/src/renetcolParam.h

    r113 r115  
    102102#define SNMP_INDEX_RRD_LOCATION "/mnt/data/RRD/RENATER/SNMP_INDEX/" 
    103103#define MIB_RRD_LOCATION "/mnt/data/RRD/RENATER/RENETCOL_MIB/" 
     104 
     105/* 
     106 * RRD filenames (static names), location : "MIB_RRD_LOCATION" 
     107 */ 
     108#define GLOBAL_MIB_RRD_FILE "RENETCOL_GLOBAL_COUNTERS.rrd" 
     109#define IPV4_MIB_RRD_FILE "RENETCOL_IPV4_MIB.rrd" 
     110#define IPV6_MIB_RRD_FILE "RENETCOL_IPV6_MIB.rrd" 
     111#define L4_IPV4_MIB_RRD_FILE "RENETCOL_L4_IPV4_MIB.rrd" 
     112#define L4_IPV6_MIB_RRD_FILE "RENETCOL_L4_IPV6_MIB.rrd" 
     113#define FLOWSIZE_IPV4_MIB_RRD_FILE "RENETCOL_FLOWSIZE_IPV4_MIB.rrd" 
     114#define FLOWSIZE_IPV6_MIB_RRD_FILE "RENETCOL_FLOWSIZE_IPV6_MIB.rrd" 
     115#define L7_IPV4_MIB_RRD_FILE "RENETCOL_L7_IPV4_MIB.rrd" 
     116#define L7_IPV6_MIB_RRD_FILE "RENETCOL_L7_IPV6_MIB.rrd" 
    104117 
    105118/*