a lot faster generation of all.json
Costa Tsaousis (ktsaou) committed
Apr 29, 2014 at 01:03 UTC
4e728ea8be543bca0aa7994574841f08d4a7f6aa
1 file changed
+77
-41
netdata.c
+77
-41
@@ -1286,26 +1286,44 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
1286
size_t first_entry = rrd_stats_first_entry(st);
1287
time_t first_entry_t = st->times[first_entry].tv_sec;
1288
1289
- web_buffer_printf(wb, "\t\t{\n");
1290
- web_buffer_printf(wb, "\t\t\t\"id\" : \"%s\",\n", st->id);
1291
- web_buffer_printf(wb, "\t\t\t\"name\" : \"%s\",\n", st->name);
1292
- web_buffer_printf(wb, "\t\t\t\"type\" : \"%s\",\n", st->type);
1293
- web_buffer_printf(wb, "\t\t\t\"group_tag\" : \"%s\",\n", st->group);
1294
- //web_buffer_printf(wb, "\t\t\t\"title\" : \"%s\",\n", st->title);
1295
- web_buffer_printf(wb, "\t\t\t\"title\" : \"%s\",\n", st->usertitle);
1296
- web_buffer_printf(wb, "\t\t\t\"priority\" : %ld,\n", st->userpriority);
1297
- web_buffer_printf(wb, "\t\t\t\"enabled\" : %d,\n", st->enabled);
1298
- web_buffer_printf(wb, "\t\t\t\"units\" : \"%s\",\n", st->units);
1299
- web_buffer_printf(wb, "\t\t\t\"url\" : \"/data/%s/%s\",\n", st->name, options?options:"");
1300
- web_buffer_printf(wb, "\t\t\t\"entries\" : %ld,\n", st->entries);
1301
- //web_buffer_printf(wb, "\t\t\t\"first_entry\" : %ld,\n", first_entry);
1302
- web_buffer_printf(wb, "\t\t\t\"first_entry_t\" : %ld,\n", first_entry_t);
1303
- //web_buffer_printf(wb, "\t\t\t\"last_entry\" : %ld,\n", st->current_entry);
1304
- web_buffer_printf(wb, "\t\t\t\"last_entry_t\" : %lu,\n", st->last_updated);
1305
- //web_buffer_printf(wb, "\t\t\t\"last_entry_secs_ago\" : %lu,\n", time(NULL) - st->last_updated);
1306
- web_buffer_printf(wb, "\t\t\t\"update_every\" : %d,\n", st->update_every);
1307
- web_buffer_printf(wb, "\t\t\t\"isdetail\" : %d,\n", st->isdetail);
1308
- web_buffer_printf(wb, "\t\t\t\"dimensions\" : [\n");
1289
+ web_buffer_printf(wb,
1290
+ "\t\t{\n"
1291
+ "\t\t\t\"id\": \"%s\",\n"
1292
+ "\t\t\t\"name\": \"%s\",\n"
1293
+ "\t\t\t\"type\": \"%s\",\n"
1294
+ "\t\t\t\"group_tag\": \"%s\",\n"
1295
+ "\t\t\t\"title\": \"%s\",\n"
1296
+ "\t\t\t\"priority\": %ld,\n"
1297
+ "\t\t\t\"enabled\": %d,\n"
1298
+ "\t\t\t\"units\": \"%s\",\n"
1299
+ "\t\t\t\"url\": \"/data/%s/%s\",\n"
1300
+ "\t\t\t\"entries\": %ld,\n"
1301
+ "\t\t\t\"first_entry\": %ld,\n"
1302
+ "\t\t\t\"first_entry_t\": %ld,\n"
1303
+ "\t\t\t\"last_entry\": %ld,\n"
1304
+ "\t\t\t\"last_entry_t\": %lu,\n"
1305
+ "\t\t\t\"last_entry_secs_ago\": %lu,\n"
1306
+ "\t\t\t\"update_every\": %d,\n"
1307
+ "\t\t\t\"isdetail\": %d,\n"
1308
+ "\t\t\t\"dimensions\": [\n"
1309
+ , st->id
1310
+ , st->name
1311
+ , st->type
1312
+ , st->group
1313
+ , st->usertitle
1314
+ , st->userpriority
1315
+ , st->enabled
1316
+ , st->units
1317
+ , st->name, options?options:""
1318
+ , st->entries
1319
+ , first_entry
1320
+ , first_entry_t
1321
+ , st->current_entry
1322
+ , st->last_updated
1323
+ , time(NULL) - st->last_updated
1324
+ , st->update_every
1325
+ , st->isdetail
1326
+ );
1327
1328
unsigned long memory = sizeof(RRD_STATS) + (sizeof(struct timeval) * st->entries);
1329
@@ -1314,46 +1332,64 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
1332
unsigned long rdmem = sizeof(RRD_DIMENSION) + (rd->bytes * rd->entries);
1333
memory += rdmem;
1334
1317
- web_buffer_printf(wb, "\t\t\t\t{\n");
1318
- web_buffer_printf(wb, "\t\t\t\t\t\"id\" : \"%s\",\n", rd->id);
1319
- web_buffer_printf(wb, "\t\t\t\t\t\"name\" : \"%s\",\n", rd->name);
1320
- //web_buffer_printf(wb, "\t\t\t\t\t\"bytes\" : %ld,\n", rd->bytes);
1321
- //web_buffer_printf(wb, "\t\t\t\t\t\"entries\" : %ld,\n", rd->entries);
1322
- web_buffer_printf(wb, "\t\t\t\t\t\"isSigned\" : %d,\n", rd->issigned);
1323
- web_buffer_printf(wb, "\t\t\t\t\t\"isHidden\" : %d,\n", rd->hidden);
1324
-
1335
+ char *algorithm = "";
1336
switch(rd->type) {
1337
case RRD_DIMENSION_INCREMENTAL:
1327
- web_buffer_printf(wb, "\t\t\t\t\t\"type\" : \"%s\",\n", "incremental");
1338
+ algorithm = "incremental";
1339
break;
1340
1341
case RRD_DIMENSION_ABSOLUTE:
1331
- web_buffer_printf(wb, "\t\t\t\t\t\"type\" : \"%s\",\n", "absolute");
1342
+ algorithm = "absolute";
1343
break;
1344
1345
case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
1335
- web_buffer_printf(wb, "\t\t\t\t\t\"type\" : \"%s\",\n", "percent on incremental total");
1346
+ algorithm = "percent on incremental total";
1347
break;
1348
1349
case RRD_DIMENSION_PCENT_OVER_ROW_TOTAL:
1339
- web_buffer_printf(wb, "\t\t\t\t\t\"type\" : \"%s\",\n", "percent on absolute total");
1350
+ algorithm = "percent on absolute total";
1351
break;
1352
1353
default:
1343
- web_buffer_printf(wb, "\t\t\t\t\t\"type\" : %d,\n", rd->type);
1354
+ algorithm = "other";
1355
break;
1356
}
1357
1347
- //web_buffer_printf(wb, "\t\t\t\t\t\"multiplier\" : %ld,\n", rd->multiplier);
1348
- //web_buffer_printf(wb, "\t\t\t\t\t\"divisor\" : %ld,\n", rd->divisor);
1349
- //web_buffer_printf(wb, "\t\t\t\t\t\"last_entry_t\" : %lu,\n", rd->last_updated);
1350
- web_buffer_printf(wb, "\t\t\t\t\t\"memory\" : %lu\n", rdmem);
1351
- web_buffer_printf(wb, "\t\t\t\t}%s\n", rd->next?",":"");
1358
+ web_buffer_printf(wb,
1359
+ "\t\t\t\t{\n"
1360
+ "\t\t\t\t\t\"id\" : \"%s\",\n"
1361
+ "\t\t\t\t\t\"name\" : \"%s\",\n"
1362
+ "\t\t\t\t\t\"bytes\" : %ld,\n"
1363
+ "\t\t\t\t\t\"entries\" : %ld,\n"
1364
+ "\t\t\t\t\t\"isSigned\" : %d,\n"
1365
+ "\t\t\t\t\t\"isHidden\" : %d,\n"
1366
+ "\t\t\t\t\t\"algorithm\" : \"%s\",\n"
1367
+ "\t\t\t\t\t\"multiplier\" : %ld,\n"
1368
+ "\t\t\t\t\t\"divisor\" : %ld,\n"
1369
+ "\t\t\t\t\t\"last_entry_t\" : %lu,\n"
1370
+ "\t\t\t\t\t\"memory\" : %lu\n"
1371
+ "\t\t\t\t}%s\n"
1372
+ , rd->id
1373
+ , rd->name
1374
+ , rd->bytes
1375
+ , rd->entries
1376
+ , rd->issigned
1377
+ , rd->hidden
1378
+ , algorithm
1379
+ , rd->multiplier
1380
+ , rd->divisor
1381
+ , rd->last_updated
1382
+ , rdmem
1383
+ , rd->next?",":""
1384
+ );
1385
}
1386
1354
- web_buffer_printf(wb, "\t\t\t],\n");
1355
- web_buffer_printf(wb, "\t\t\t\"memory\" : %lu\n", memory);
1356
- web_buffer_printf(wb, "\t\t}");
1387
+ web_buffer_printf(wb,
1388
+ "\t\t\t],\n"
1389
+ "\t\t\t\"memory\" : %lu\n"
1390
+ "\t\t}"
1391
+ , memory
1392
+ );
1393
1394
pthread_mutex_unlock(&st->mutex);
1395
return memory;