root/trunk/src/renetcolAgg.c @ 26

Revision 26, 5.9 KB (checked in by andreu, 16 years ago)

aggregation feature : error rrd correct

  • Property svn:eol-style set to native
Line 
1/*
2 * File: renetcolAgg.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2007 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include "renetcolAgg.h"
27
28struct SHMForAgg *shmForAgg;
29
30int
31main(int argc, char *argv[])
32{
33  int shmid;
34  int i, index;
35  key_t key;
36  static char buf[2048];
37  static char name[2048];
38  static char ipStr[20];
39  static char createstr[2048];
40  int res_rrd = 0;
41  FILE *fp;
42  static time_t now;
43
44  key = 8765;
45  if ((shmid = shmget(key, SHMSIZE, 0666)) < 0) {
46    perror("shmget");
47    exit(1);
48  }
49  if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) {
50    perror("shmat");
51    exit(1);
52  }
53
54  fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. By.\n");
55  if (fork () != 0)
56    exit (0);
57  if (setsid() == -1){
58    exit(4);
59  }
60 
61  do {
62    if (shmForAgg->readed == 1) {
63      shmForAgg->readed = 0;
64      if (shmForAgg->currentTable == 0) {
65        index = 1;
66      }else{
67        index = 0;
68      }
69      now = time((time_t *)NULL);
70      for (i=0; i<shmForAgg->v4PrefixNb; i++){
71        /* HERE Put in RRD FILE */
72        name[0] = '\0';
73        createstr[0] = '\0';
74        ipStr[0] = '\0';
75        buf[0] = '\0';
76        strcat(name, RRD_LOCATION);
77        sprintf(ipStr, "%lu", shmForAgg->prefixV4Tab[index][i].beginning);
78        strcat(name, ipStr);
79        /*      strcat(name, SAMPLING_HERE); */
80        strcat(name, RRD_EXTENSION);
81        fprintf(stderr, "%s\n", name);
82        if ( (fp=fopen(name,"r")) == NULL ){
83          strcat(createstr, name);
84          strcat(createstr, END_RRD_CREATE);
85          fprintf(stderr, "%s\n", createstr);
86          res_rrd = wrap_rrd_create(createstr);
87        }else{
88          fclose(fp);
89        }
90   
91        snprintf(buf, 2048, "%s%s%s %lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
92                 RRD_LOCATION,
93                 ipStr,
94                 RRD_EXTENSION,
95                 now-300,  /* or ctime(&now) with %s */
96                 shmForAgg->prefixV4Tab[index][i].flowNbIN,  /* 1  */
97                 shmForAgg->prefixV4Tab[index][i].flowNbOUT,
98                 shmForAgg->prefixV4Tab[index][i].bytesNbIN,
99                 shmForAgg->prefixV4Tab[index][i].bytesNbOUT,
100                 shmForAgg->prefixV4Tab[index][i].pktsNbIN,  /* 5 */
101                 shmForAgg->prefixV4Tab[index][i].pktsNbOUT,
102                 shmForAgg->prefixV4Tab[index][i].udpPktsNbIN,
103                 shmForAgg->prefixV4Tab[index][i].udpPktsNbOUT,
104                 shmForAgg->prefixV4Tab[index][i].tcpPktsNbIN,
105                 shmForAgg->prefixV4Tab[index][i].tcpPktsNbOUT, /* 10 */
106                 shmForAgg->prefixV4Tab[index][i].icmpPktsNbIN,
107                 shmForAgg->prefixV4Tab[index][i].icmpPktsNbOUT,
108                 shmForAgg->prefixV4Tab[index][i].othersPktsNbIN,
109                 shmForAgg->prefixV4Tab[index][i].othersPktsNbOUT,
110                 shmForAgg->prefixV4Tab[index][i].udpBytesNbIN,  /* 15 */
111                 shmForAgg->prefixV4Tab[index][i].udpBytesNbOUT,
112                 shmForAgg->prefixV4Tab[index][i].tcpBytesNbIN,
113                 shmForAgg->prefixV4Tab[index][i].tcpBytesNbOUT,
114                 shmForAgg->prefixV4Tab[index][i].icmpBytesNbIN,
115                 shmForAgg->prefixV4Tab[index][i].icmpBytesNbOUT,  /*  20 */
116                 shmForAgg->prefixV4Tab[index][i].othersBytesNbIN,
117                 shmForAgg->prefixV4Tab[index][i].othersBytesNbOUT,
118                 shmForAgg->prefixV4Tab[index][i].udpFlowNbIN,
119                 shmForAgg->prefixV4Tab[index][i].udpFlowNbOUT,
120                 shmForAgg->prefixV4Tab[index][i].tcpFlowNbIN, /* 25 */
121                 shmForAgg->prefixV4Tab[index][i].tcpFlowNbOUT,
122                 shmForAgg->prefixV4Tab[index][i].icmpFlowNbIN,
123                 shmForAgg->prefixV4Tab[index][i].icmpFlowNbOUT,
124                 shmForAgg->prefixV4Tab[index][i].othersFlowNbIN,
125                 shmForAgg->prefixV4Tab[index][i].othersFlowNbOUT  /* 30 */
126                 );
127        printf("\n%s\n", buf);
128        if ( (res_rrd = wrap_rrd_update(buf)) < 0 ) {
129          syslog(LOG_ERR, "wrap_rrd_update return : %d, param were : %s", res_rrd, buf);
130        }
131        /* Reinit the shared table */
132        shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
133        shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
134        shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
135        shmForAgg->prefixV4Tab[index][i].udpPktsNbIN = 0;
136        shmForAgg->prefixV4Tab[index][i].tcpPktsNbIN = 0;
137        shmForAgg->prefixV4Tab[index][i].icmpPktsNbIN = 0;
138        shmForAgg->prefixV4Tab[index][i].othersPktsNbIN = 0;
139        shmForAgg->prefixV4Tab[index][i].udpBytesNbIN = 0;
140        shmForAgg->prefixV4Tab[index][i].tcpBytesNbIN = 0;
141        shmForAgg->prefixV4Tab[index][i].icmpBytesNbIN = 0;
142        shmForAgg->prefixV4Tab[index][i].othersBytesNbIN = 0;
143        shmForAgg->prefixV4Tab[index][i].udpFlowNbIN = 0;
144        shmForAgg->prefixV4Tab[index][i].tcpFlowNbIN = 0;
145        shmForAgg->prefixV4Tab[index][i].icmpFlowNbIN = 0;
146        shmForAgg->prefixV4Tab[index][i].othersFlowNbIN = 0;
147        shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
148        shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
149        shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
150        shmForAgg->prefixV4Tab[index][i].udpPktsNbOUT = 0;
151        shmForAgg->prefixV4Tab[index][i].tcpPktsNbOUT = 0;
152        shmForAgg->prefixV4Tab[index][i].icmpPktsNbOUT = 0;
153        shmForAgg->prefixV4Tab[index][i].othersPktsNbOUT = 0;
154        shmForAgg->prefixV4Tab[index][i].udpBytesNbOUT = 0;
155        shmForAgg->prefixV4Tab[index][i].tcpBytesNbOUT = 0;
156        shmForAgg->prefixV4Tab[index][i].icmpBytesNbOUT = 0;
157        shmForAgg->prefixV4Tab[index][i].othersBytesNbOUT = 0;
158        shmForAgg->prefixV4Tab[index][i].udpFlowNbOUT = 0;
159        shmForAgg->prefixV4Tab[index][i].tcpFlowNbOUT = 0;
160        shmForAgg->prefixV4Tab[index][i].icmpFlowNbOUT = 0;
161        shmForAgg->prefixV4Tab[index][i].othersFlowNbOUT = 0;   
162      }
163    }
164    sleep(5);
165  } while (1);
166
167  exit(0);
168}
Note: See TracBrowser for help on using the browser.