Index: trunk/udpprofile/collector.c |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | |
33 | 33 | void handleMessage(char *,ssize_t ); |
34 | 34 | void handleConnection(int); |
| 35 | +void updateEntry(char *dbname, char *hostname, char *task, struct pfstats *incoming); |
35 | 36 | |
36 | 37 | int main(int ac, char **av) { |
37 | 38 | |
— | — | @@ -44,7 +45,7 @@ |
45 | 46 | u_int yes=1; |
46 | 47 | int port; |
47 | 48 | struct sockaddr_in me, them; |
48 | | - socklen_t sl; |
| 49 | + socklen_t sl = sizeof(struct sockaddr_in); |
49 | 50 | |
50 | 51 | struct pollfd fds[2]; |
51 | 52 | |
— | — | @@ -109,15 +110,13 @@ |
110 | 111 | char hostname[128]; |
111 | 112 | char dbname[128]; |
112 | 113 | char task[1024]; |
113 | | - char keytext[1500]; |
114 | 114 | int r; |
115 | 115 | |
116 | | - struct pfstats incoming,*old; |
| 116 | + struct pfstats incoming; |
117 | 117 | /* db host count cpu cpusq real realsq eventdescription */ |
118 | 118 | const char msgformat[]="%127s %127s %ld %lf %lf %lf %lf %1023[^\n]"; |
119 | 119 | |
120 | 120 | |
121 | | - DBT key,data; |
122 | 121 | |
123 | 122 | buf[l]=0; |
124 | 123 | pp=buf; |
— | — | @@ -135,39 +134,51 @@ |
136 | 135 | &incoming.pf_real,&incoming.pf_real_sq, (char *)&task); |
137 | 136 | if (r<7) |
138 | 137 | continue; |
139 | | - snprintf(keytext,1499,"%s:%s:%s",dbname,hostname,task); |
140 | 138 | |
141 | | - bzero(&key,sizeof(key)); |
142 | | - bzero(&data,sizeof(data)); |
143 | | - key.data=keytext; |
144 | | - key.size=strlen(keytext); |
| 139 | + // Update the DB-specific entry |
| 140 | + updateEntry(dbname, hostname, task, &incoming); |
145 | 141 | |
146 | | - /* Add new values if exists, put in fresh structure if not */ |
147 | | - if (db->get(db,NULL,&key,&data,0)==0) { |
148 | | - /* Update old stuff */ |
149 | | - old=data.data; |
150 | | - old->pf_count += incoming.pf_count; |
151 | | - old->pf_cpu += incoming.pf_cpu; |
152 | | - old->pf_cpu_sq += incoming.pf_cpu_sq; |
153 | | - old->pf_real += incoming.pf_real; |
154 | | - old->pf_real_sq += incoming.pf_real_sq; |
155 | | - old->pf_reals[old->pf_real_pointer] = incoming.pf_real; |
156 | | - if (old->pf_real_pointer == POINTS-1) { |
157 | | - old->pf_real_pointer = 0; |
158 | | - } else { |
159 | | - old->pf_real_pointer++; |
160 | | - } |
161 | | - db->put(db,NULL,&key,&data,0); |
162 | | - } else { |
163 | | - /* Put in fresh data */ |
164 | | - incoming.pf_real_pointer = 1; |
165 | | - incoming.pf_reals[0] = incoming.pf_real; |
166 | | - data.data=&incoming; |
167 | | - data.size=sizeof(incoming); |
168 | | - db->put(db,NULL,&key,&data,0); |
| 142 | + // Update the aggregate entry |
| 143 | + updateEntry("all", "-", task, &incoming); |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +void updateEntry(char *dbname, char *hostname, char *task, struct pfstats *incoming) { |
| 148 | + char keytext[1500]; |
| 149 | + DBT key,data; |
| 150 | + struct pfstats *old; |
| 151 | + |
| 152 | + snprintf(keytext,1499,"%s:%s:%s",dbname,hostname,task); |
| 153 | + |
| 154 | + bzero(&key,sizeof(key)); |
| 155 | + bzero(&data,sizeof(data)); |
| 156 | + key.data=keytext; |
| 157 | + key.size=strlen(keytext); |
| 158 | + |
| 159 | + /* Add new values if exists, put in fresh structure if not */ |
| 160 | + if (db->get(db,NULL,&key,&data,0)==0) { |
| 161 | + /* Update old stuff */ |
| 162 | + old=data.data; |
| 163 | + old->pf_count += incoming->pf_count; |
| 164 | + old->pf_cpu += incoming->pf_cpu; |
| 165 | + old->pf_cpu_sq += incoming->pf_cpu_sq; |
| 166 | + old->pf_real += incoming->pf_real; |
| 167 | + old->pf_real_sq += incoming->pf_real_sq; |
| 168 | + old->pf_reals[old->pf_real_pointer] = incoming->pf_real; |
| 169 | + if (old->pf_real_pointer == POINTS-1) { |
| 170 | + old->pf_real_pointer = 0; |
| 171 | + } else { |
| 172 | + old->pf_real_pointer++; |
169 | 173 | } |
170 | | - } |
171 | | - |
| 174 | + db->put(db,NULL,&key,&data,0); |
| 175 | + } else { |
| 176 | + /* Put in fresh data */ |
| 177 | + incoming->pf_real_pointer = 1; |
| 178 | + incoming->pf_reals[0] = incoming->pf_real; |
| 179 | + data.data=incoming; |
| 180 | + data.size=sizeof(*incoming); |
| 181 | + db->put(db,NULL,&key,&data,0); |
| 182 | + } |
172 | 183 | } |
173 | 184 | |
174 | 185 | void handleConnection(int c) { |
Index: trunk/udpprofile/Makefile |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | #CFLAGS+=-I/sw/include/ |
7 | 7 | #LDFLAGS+=-L/sw/lib/ |
8 | 8 | |
9 | | -LDFLAGS+=-ldb |
| 9 | +LDLIBS+=-ldb |
10 | 10 | CFLAGS+=-Wall -g |
11 | 11 | |
12 | 12 | all: collector exporter |