@cryptotaxi247 / netdata-1 / commits / 54977b213

code cleanup

Costa Tsaousis (ktsaou) committed Apr 12, 2014 at 17:00 UTC 54977b213328ec46501d0d5b1709d2da7060f611
3 files changed +262 -366
netdata.c
+259 -365
@@ -109,12 +109,6 @@
109
110 #define MAX_HTTP_HEADER_SIZE 16384
111
112 -#define MAX_PROC_NET_DEV_LINE 4096
113 -#define MAX_PROC_NET_DEV_IFACE_NAME 1024
114 -
115 -#define MAX_PROC_DISKSTATS_LINE 4096
116 -#define MAX_PROC_DISKSTATS_DISK_NAME 1024
117 -
112 #define MAX_PROC_NET_SNMP_LINE 4096
113 #define MAX_PROC_NET_SNMP_NAME 1024
114
@@ -339,105 +333,122 @@ int create_listen_socket(int port)
333 #define RRD_STATS_NAME_MAX 1024
334
335 struct rrd_dimension {
342 - char id[RRD_STATS_NAME_MAX + 1];
343 - char name[RRD_STATS_NAME_MAX + 1];
336 + char id[RRD_STATS_NAME_MAX + 1]; // the id of this dimension (for internal identification)
337 + char name[RRD_STATS_NAME_MAX + 1]; // the name of this dimension (as presented to user)
338
345 - int issigned;
339 + int issigned; // if true, the values are signed
340
347 - size_t bytes;
348 - size_t entries;
341 + size_t bytes; // how many bytes each value has, e.g. sizeof(long)
342 + size_t entries; // how many entries this dimension has
343 + // this should be the same to the entries of the data set
344
350 - int type;
351 - int hidden; // if set to non zero, this dimension will not be sent to the client
345 + int hidden; // if set to non zero, this dimension will not be sent to the client
346
353 - long multiplier;
354 - long divisor;
347 + // before presenting the value to the user:
348 + int type; // - first calculate a long double value based on this type of calculation
349 + long multiplier; // - then, multiple by this
350 + long divisor; // - then, divide by this
351
356 - void *values;
352 + void *values; // the array of values, each value is 'bytes' in length
353
354 // char **annotations;
355 // char *(*annotator)(long double previous, long double current);
356
361 - time_t last_updated;
357 + time_t last_updated; // when was this dimension last updated
358
363 - struct rrd_dimension *next;
359 + struct rrd_dimension *next; // linking of dimensions within the same data set
360 };
361 typedef struct rrd_dimension RRD_DIMENSION;
362
363 struct rrd_stats {
364 pthread_mutex_t mutex;
365
370 - char id[RRD_STATS_NAME_MAX + 1];
371 - char name[RRD_STATS_NAME_MAX + 1];
372 - char title[RRD_STATS_NAME_MAX + 1];
373 - char vtitle[RRD_STATS_NAME_MAX + 1];
366 + char id[RRD_STATS_NAME_MAX + 1]; // id of the data set
367 + char name[RRD_STATS_NAME_MAX + 1]; // name of the data set
368 +
369 + char type[RRD_STATS_NAME_MAX + 1]; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
370 + char group[RRD_STATS_NAME_MAX + 1]; // the group of this data set (for grouping them together)
371
375 - char usertitle[RRD_STATS_NAME_MAX + 1];
376 - char userpriority[RRD_STATS_NAME_MAX + 1];
372 + char title[RRD_STATS_NAME_MAX + 1]; // title shown to user
373 + char units[RRD_STATS_NAME_MAX + 1]; // units of measurement
374
378 - char envtitle[RRD_STATS_NAME_MAX + 1];
379 - char envpriority[RRD_STATS_NAME_MAX + 1];
375 + char usertitle[RRD_STATS_NAME_MAX + 1]; // the title as taken from the environment variable
376 + char userpriority[RRD_STATS_NAME_MAX + 1]; // the priority as taken from the environment variable
377
381 - char type[RRD_STATS_NAME_MAX + 1];
378 + char envtitle[RRD_STATS_NAME_MAX + 1]; // the variable name for taking the title
379 + char envpriority[RRD_STATS_NAME_MAX + 1]; // the variable name for taking the priority
380
383 - char hostname[RRD_STATS_NAME_MAX + 1];
381 + char hostname[RRD_STATS_NAME_MAX + 1]; // the host this data set belongs to
382
385 - size_t entries;
386 - size_t current_entry;
383 + size_t entries; // total number of entries in the data set
384 + size_t current_entry; // the entry that is currently being updated
385 + // it goes around in a round-robin fashion
386 // size_t last_entry;
387
389 - time_t last_updated;
388 + time_t last_updated; // when this data set was last updated
389
391 - struct timeval *times;
392 - RRD_DIMENSION *dimensions;
393 - struct rrd_stats *next;
390 + struct timeval *times; // the time in microseconds each data entry was collected
391 + RRD_DIMENSION *dimensions; // the actual data for every dimension
392 +
393 + struct rrd_stats *next; // linking of rrd stats
394 };
395 typedef struct rrd_stats RRD_STATS;
396
397 RRD_STATS *root = NULL;
398 pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER;
399
400 -RRD_STATS *rrd_stats_create(const char *id, const char *name, unsigned long entries, const char *title, const char *vtitle, const char *type)
400 +RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name, const char *group, const char *title, const char *units, unsigned long entries)
401 {
402 RRD_STATS *st = NULL;
403 char *p;
404
405 if(!id || !id[0]) {
406 - error("Cannot create rrd stats without an id.");
406 + fatal("Cannot create rrd stats without an id.");
407 return NULL;
408 }
409
410 debug(D_RRD_STATS, "Creating RRD_STATS for '%s'.", name);
411
412 st = calloc(1, sizeof(RRD_STATS));
413 - if(!st) return NULL;
413 + if(!st) {
414 + fatal("Cannot allocate memory for RRD_STATS %s.%s", type, id);
415 + return NULL;
416 + }
417
418 st->times = calloc(entries, sizeof(struct timeval));
419 if(!st->times) {
417 - error("Cannot allocate %lu entries of %lu bytes each for RRD_STATS.", st->entries, sizeof(struct timeval));
420 free(st);
421 + fatal("Cannot allocate %lu entries of %lu bytes each for RRD_STATS.", st->entries, sizeof(struct timeval));
422 return NULL;
423 }
424
422 - strncpy(st->id, id, RRD_STATS_NAME_MAX);
423 - st->id[RRD_STATS_NAME_MAX] = '\0';
425 + // no need to terminate the strings after strncpy(), because of calloc()
426 +
427 + strncpy(st->id, type, RRD_STATS_NAME_MAX-1);
428 + strcat(st->id, ".");
429 + int len = strlen(st->id);
430 + strncpy(&st->id[len], id, RRD_STATS_NAME_MAX - len);
431
425 - if(name) strncpy(st->name, name, RRD_STATS_NAME_MAX);
426 - else strncpy(st->name, id, RRD_STATS_NAME_MAX);
432 + if(name) {
433 + strncpy(st->name, type, RRD_STATS_NAME_MAX - 1);
434 + strcat(st->name, ".");
435 + len = strlen(st->name);
436 + strncpy(&st->name[len], name, RRD_STATS_NAME_MAX - len);
437 + }
438 + else strcpy(st->name, st->id);
439
428 - st->name[RRD_STATS_NAME_MAX] = '\0';
440 + // replace illegal characters in name
441 + while((p = strchr(st->name, ' '))) *p = '_';
442 while((p = strchr(st->name, '/'))) *p = '_';
443 while((p = strchr(st->name, '?'))) *p = '_';
444 while((p = strchr(st->name, '&'))) *p = '_';
445
433 - strncpy(st->title, title, RRD_STATS_NAME_MAX);
434 - st->title[RRD_STATS_NAME_MAX] = '\0';
435 -
436 - strncpy(st->vtitle, vtitle, RRD_STATS_NAME_MAX);
437 - st->vtitle[RRD_STATS_NAME_MAX] = '\0';
446 + if(group) strncpy(st->group, group, RRD_STATS_NAME_MAX);
447 + else strcpy(st->group, st->id);
448
449 + strncpy(st->title, title, RRD_STATS_NAME_MAX);
450 + strncpy(st->units, units, RRD_STATS_NAME_MAX);
451 strncpy(st->type, type, RRD_STATS_NAME_MAX);
440 - st->type[RRD_STATS_NAME_MAX] = '\0';
452
453 // check if there is a name for it in the environment
454 sprintf(st->envtitle, "NETDATA_TITLE_%s", st->id);
@@ -448,7 +459,6 @@ RRD_STATS *rrd_stats_create(const char *id, const char *name, unsigned long entr
459
460 if(p) strncpy(st->usertitle, p, RRD_STATS_NAME_MAX);
461 else strncpy(st->usertitle, st->name, RRD_STATS_NAME_MAX);
451 - st->usertitle[RRD_STATS_NAME_MAX] = '\0';
462
463 sprintf(st->envpriority, "NETDATA_PRIORITY_%s", st->id);
464 while((p = strchr(st->envpriority, '/'))) *p = '_';
@@ -458,7 +468,6 @@ RRD_STATS *rrd_stats_create(const char *id, const char *name, unsigned long entr
468
469 if(p) strncpy(st->userpriority, p, RRD_STATS_NAME_MAX);
470 else strncpy(st->userpriority, st->name, RRD_STATS_NAME_MAX);
461 - st->userpriority[RRD_STATS_NAME_MAX] = '\0';
471
472 if(gethostname(st->hostname, RRD_STATS_NAME_MAX) == -1)
473 error("Cannot get hostname.");
@@ -489,7 +498,10 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
498 debug(D_RRD_STATS, "Adding dimension '%s' (%s) to RRD_STATS '%s' (%s).", name, id, st->name, st->id);
499
500 rd = calloc(1, sizeof(RRD_DIMENSION));
492 - if(!rd) return NULL;
501 + if(!rd) {
502 + fatal("Cannot allocate RRD_DIMENSION %s/%s.", st->name, id);
503 + return NULL;
504 + }
505
506 rd->bytes = bytes;
507 rd->entries = st->entries;
@@ -500,24 +512,25 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
512
513 rd->values = calloc(rd->entries, rd->bytes);
514 if(!rd->values) {
503 - error("Cannot allocate %lu entries of %lu bytes each for RRD_DIMENSION values.", rd->entries, rd->bytes);
515 free(rd);
516 + fatal("Cannot allocate %lu entries of %lu bytes each for RRD_DIMENSION values.", rd->entries, rd->bytes);
517 return NULL;
518 }
519
520 /* rd->annotations = calloc(rd->entries, sizeof(char *));
521 if(!rd->annotations) {
510 - error("Cannot allocate %lu entries of %lu bytes each for RRD_DIMENSION annotations.", rd->entries, sizeof(char *));
522 free(rd->values);
523 free(rd);
524 + fatal("Cannot allocate %lu entries of %lu bytes each for RRD_DIMENSION annotations.", rd->entries, sizeof(char *));
525 return NULL;
526 }
527 */
528 + // no need to terminate the strings after strncpy(), because of calloc()
529 +
530 strncpy(rd->id, id, RRD_STATS_NAME_MAX);
517 - rd->id[RRD_STATS_NAME_MAX] = '\0';
531
519 - strncpy(rd->name, name, RRD_STATS_NAME_MAX);
520 - rd->name[RRD_STATS_NAME_MAX] = '\0';
532 + if(name) strncpy(rd->name, name, RRD_STATS_NAME_MAX);
533 + else strncpy(rd->name, id, RRD_STATS_NAME_MAX);
534
535 rd->next = st->dimensions;
536 st->dimensions = rd;
@@ -550,6 +563,20 @@ RRD_STATS *rrd_stats_find(const char *id)
563 return(st);
564 }
565
566 +RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id)
567 +{
568 + char buf[RRD_STATS_NAME_MAX + 1];
569 +
570 + strncpy(buf, type, RRD_STATS_NAME_MAX - 1);
571 + buf[RRD_STATS_NAME_MAX - 1] = '\0';
572 + strcat(buf, ".");
573 + int len = strlen(buf);
574 + strncpy(&buf[len], id, RRD_STATS_NAME_MAX - len);
575 + buf[RRD_STATS_NAME_MAX] = '\0';
576 +
577 + return(rrd_stats_find(buf));
578 +}
579 +
580 RRD_STATS *rrd_stats_find_byname(const char *name)
581 {
582 pthread_mutex_lock(&root_mutex);
@@ -904,13 +931,14 @@ void rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer *wb)
931 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"id\" : \"%s\",\n", st->id);
932 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"name\" : \"%s\",\n", st->name);
933 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"type\" : \"%s\",\n", st->type);
934 + wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"group\" : \"%s\",\n", st->group);
935 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"title\" : \"%s %s\",\n", st->title, st->name);
936 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"usertitle\" : \"%s %s (%s)\",\n", st->title, st->usertitle, st->id);
937 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"userpriority\" : \"%s\",\n", st->userpriority);
938 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"envtitle\" : \"%s\",\n", st->envtitle);
939 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"envpriority\" : \"%s\",\n", st->envpriority);
940 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"hostname\" : \"%s\",\n", st->hostname);
913 - wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"vtitle\" : \"%s\",\n", st->vtitle);
941 + wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"units\" : \"%s\",\n", st->units);
942 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"url\" : \"/data/%s/%s\",\n", st->name, options?options:"");
943 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"entries\" : %ld,\n", st->entries);
944 wb->bytes += sprintf(&wb->buffer[wb->bytes], "\t\t\t\"current\" : %ld,\n", st->current_entry);
@@ -2218,9 +2246,12 @@ void *socket_listen_main(void *ptr)
2246 // ----------------------------------------------------------------------------
2247 // /proc/net/dev processor
2248
2249 +#define MAX_PROC_NET_DEV_LINE 4096
2250 +#define MAX_PROC_NET_DEV_IFACE_NAME 1024
2251 +
2252 int do_proc_net_dev() {
2253 char buffer[MAX_PROC_NET_DEV_LINE+1] = "";
2223 - char name[MAX_PROC_NET_DEV_IFACE_NAME + 1] = RRD_TYPE_NET ".";
2254 + char iface[MAX_PROC_NET_DEV_IFACE_NAME + 1] = "";
2255 unsigned long long rbytes, rpackets, rerrors, rdrops, rfifo, rframe, rcompressed, rmulticast;
2256 unsigned long long tbytes, tpackets, terrors, tdrops, tfifo, tcollisions, tcarrier, tcompressed;
2257
@@ -2248,27 +2279,19 @@ int do_proc_net_dev() {
2279
2280 // if(DEBUG) printf("%s\n", buffer);
2281 r = sscanf(buffer, "%s\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\t%llu\n",
2251 - &name[RRD_TYPE_NET_LEN + 1],
2282 + iface,
2283 &rbytes, &rpackets, &rerrors, &rdrops, &rfifo, &rframe, &rcompressed, &rmulticast,
2284 &tbytes, &tpackets, &terrors, &tdrops, &tfifo, &tcollisions, &tcarrier, &tcompressed);
2285 if(r == EOF) break;
2286 if(r != 17) error("Cannot read /proc/net/dev line. Expected 17 params, read %d.", r);
2287 else {
2257 - RRD_STATS *st = rrd_stats_find(name);
2288 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_NET, iface);
2289
2290 if(!st) {
2260 - st = rrd_stats_create(name, name, save_history, "Network usage for ", "Bandwidth in kilobits/s", RRD_TYPE_NET);
2261 - if(!st) {
2262 - error("Cannot create RRD_STATS for interface %s.", name);
2263 - continue;
2264 - }
2265 -
2266 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2267 - error("Cannot add RRD_STATS dimension %s.", "sent");
2268 -
2269 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2270 - error("Cannot add RRD_STATS dimension %s.", "received");
2291 + st = rrd_stats_create(RRD_TYPE_NET, iface, NULL, iface, "Bandwidth", "kilobits/s", save_history);
2292
2293 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2294 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2295 }
2296 else rrd_stats_next(st);
2297
@@ -2285,9 +2308,12 @@ int do_proc_net_dev() {
2308 // ----------------------------------------------------------------------------
2309 // /proc/diskstats processor
2310
2311 +#define MAX_PROC_DISKSTATS_LINE 4096
2312 +#define MAX_PROC_DISKSTATS_DISK_NAME 1024
2313 +
2314 int do_proc_diskstats() {
2315 char buffer[MAX_PROC_DISKSTATS_LINE+1] = "";
2290 - char name[MAX_PROC_DISKSTATS_DISK_NAME + 1] = RRD_TYPE_DISK ".";
2316 + char disk[MAX_PROC_DISKSTATS_DISK_NAME + 1] = "";
2317 // 1 2 3 4 5 6 7 8 9 10 11
2318 unsigned long long major, minor, reads, reads_merged, readsectors, readms, writes, writes_merged, writesectors, writems, currentios, iosms, wiosms;
2319
@@ -2306,30 +2332,43 @@ int do_proc_diskstats() {
2332
2333 // if(DEBUG) printf("%s\n", buffer);
2334 r = sscanf(buffer, "%llu %llu %s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
2309 - &major, &minor, &name[RRD_TYPE_DISK_LEN + 1],
2335 + &major, &minor, disk,
2336 &reads, &reads_merged, &readsectors, &readms, &writes, &writes_merged, &writesectors, &writems, &currentios, &iosms, &wiosms
2337 );
2338 if(r == EOF) break;
2339 if(r != 14) error("Cannot read /proc/diskstats line. Expected 14 params, read %d.", r);
2340 else {
2341 switch(major) {
2316 - case 3: // ide
2317 - case 13: // 8bit ide
2318 - case 22: // ide
2319 - case 33: // ide
2320 - case 34: // ide
2321 - case 56: // ide
2322 - case 57: // ide
2323 - case 88: // ide
2324 - case 89: // ide
2325 - case 90: // ide
2326 - case 91: // ide
2327 - if(minor % 64) continue; // partitions
2342 + case 9: // MDs
2343 + case 43: // network block
2344 + case 144: // nfs
2345 + case 145: // nfs
2346 + case 146: // nfs
2347 + case 199: // veritas
2348 + case 201: // veritas
2349 + case 251: // dm
2350 break;
2351
2330 - case 160: // raid
2331 - case 161: // raid
2332 - if(minor % 32) continue; // partitions
2352 + case 48: // RAID
2353 + case 49: // RAID
2354 + case 50: // RAID
2355 + case 51: // RAID
2356 + case 52: // RAID
2357 + case 53: // RAID
2358 + case 54: // RAID
2359 + case 55: // RAID
2360 + case 112: // RAID
2361 + case 136: // RAID
2362 + case 137: // RAID
2363 + case 138: // RAID
2364 + case 139: // RAID
2365 + case 140: // RAID
2366 + case 141: // RAID
2367 + case 142: // RAID
2368 + case 143: // RAID
2369 + case 179: // MMC
2370 + case 180: // USB
2371 + if(minor % 8) continue; // partitions
2372 break;
2373
2374 case 8: // scsi disks
@@ -2383,49 +2422,35 @@ int do_proc_diskstats() {
2422 if(minor % 16) continue; // partitions
2423 break;
2424
2386 - case 9: // MDs
2387 - case 43: // network block
2388 - case 144: // nfs
2389 - case 145: // nfs
2390 - case 146: // nfs
2391 - case 199: // veritas
2392 - case 201: // veritas
2393 - case 251: // dm
2425 + case 160: // raid
2426 + case 161: // raid
2427 + if(minor % 32) continue; // partitions
2428 break;
2429
2396 - case 48: // RAID
2397 - case 49: // RAID
2398 - case 50: // RAID
2399 - case 51: // RAID
2400 - case 52: // RAID
2401 - case 53: // RAID
2402 - case 54: // RAID
2403 - case 55: // RAID
2404 - case 112: // RAID
2405 - case 136: // RAID
2406 - case 137: // RAID
2407 - case 138: // RAID
2408 - case 139: // RAID
2409 - case 140: // RAID
2410 - case 141: // RAID
2411 - case 142: // RAID
2412 - case 143: // RAID
2413 - case 179: // MMC
2414 - case 180: // USB
2415 - if(minor % 8) continue; // partitions
2430 + case 3: // ide
2431 + case 13: // 8bit ide
2432 + case 22: // ide
2433 + case 33: // ide
2434 + case 34: // ide
2435 + case 56: // ide
2436 + case 57: // ide
2437 + case 88: // ide
2438 + case 89: // ide
2439 + case 90: // ide
2440 + case 91: // ide
2441 + if(minor % 64) continue; // partitions
2442 break;
2443
2444 default:
2445 continue;
2446 }
2447
2422 - RRD_STATS *st = rrd_stats_find(name);
2423 -
2448 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_DISK, disk);
2449 if(!st) {
2450 char ssfilename[FILENAME_MAX + 1];
2451 int sector_size = 512;
2452
2428 - sprintf(ssfilename, "/sys/block/%s/queue/hw_sector_size", &name[RRD_TYPE_DISK_LEN + 1]);
2453 + sprintf(ssfilename, "/sys/block/%s/queue/hw_sector_size", disk);
2454 FILE *fpss = fopen(ssfilename, "r");
2455 if(fpss) {
2456 char ssbuffer[1025];
@@ -2434,28 +2459,20 @@ int do_proc_diskstats() {
2459 if(tmp) {
2460 sector_size = atoi(tmp);
2461 if(sector_size <= 0) {
2437 - error("Invalid sector size %d for device %s in %s. Assuming 512.", sector_size, name, ssfilename);
2462 + error("Invalid sector size %d for device %s in %s. Assuming 512.", sector_size, disk, ssfilename);
2463 sector_size = 512;
2464 }
2465 }
2441 - else error("Cannot read data for sector size for device %s from %s. Assuming 512.", name, ssfilename);
2466 + else error("Cannot read data for sector size for device %s from %s. Assuming 512.", disk, ssfilename);
2467
2468 fclose(fpss);
2469 }
2445 - else error("Cannot read sector size for device %s from %s. Assuming 512.", name, ssfilename);
2446 -
2447 - st = rrd_stats_create(name, name, save_history, "Disk usage for ", "I/O in kilobytes/s", RRD_TYPE_DISK);
2448 - if(!st) {
2449 - error("Cannot create RRD_STATS for disk %s.", name);
2450 - continue;
2451 - }
2470 + else error("Cannot read sector size for device %s from %s. Assuming 512.", disk, ssfilename);
2471
2453 - if(!rrd_stats_dimension_add(st, "writes", "writes", sizeof(unsigned long long), 0, sector_size * -1, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2454 - error("Cannot add RRD_STATS dimension %s.", "writes");
2455 -
2456 - if(!rrd_stats_dimension_add(st, "reads", "reads", sizeof(unsigned long long), 0, sector_size, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2457 - error("Cannot add RRD_STATS dimension %s.", "reads");
2472 + st = rrd_stats_create(RRD_TYPE_DISK, disk, NULL, disk, "Disk I/O", "kilobytes/s", save_history);
2473
2474 + rrd_stats_dimension_add(st, "writes", NULL, sizeof(unsigned long long), 0, sector_size * -1, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2475 + rrd_stats_dimension_add(st, "reads", NULL, sizeof(unsigned long long), 0, sector_size, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2476 }
2477 else rrd_stats_next(st);
2478
@@ -2508,21 +2525,11 @@ int do_proc_net_snmp() {
2525
2526 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_SNMP ".packets");
2527 if(!st) {
2511 - st = rrd_stats_create(RRD_TYPE_NET_SNMP ".packets", RRD_TYPE_NET_SNMP ".packets", save_history, "IPv4 Packets", "Packets/s", RRD_TYPE_NET_SNMP);
2512 - if(!st) {
2513 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_SNMP ".packets");
2514 - continue;
2515 - }
2516 -
2517 - if(!rrd_stats_dimension_add(st, "forwarded", "forwarded", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2518 - error("Cannot add RRD_STATS dimension %s.", "forwarded");
2519 -
2520 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2521 - error("Cannot add RRD_STATS dimension %s.", "sent");
2522 -
2523 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2524 - error("Cannot add RRD_STATS dimension %s.", "received");
2528 + st = rrd_stats_create(RRD_TYPE_NET_SNMP, "packets", NULL, RRD_TYPE_NET_SNMP, "IPv4 Packets", "packets/s", save_history);
2529
2530 + rrd_stats_dimension_add(st, "forwarded", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2531 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2532 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2533 }
2534 else rrd_stats_next(st);
2535
@@ -2552,14 +2559,9 @@ int do_proc_net_snmp() {
2559 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
2560 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcpsock");
2561 if(!st) {
2555 - st = rrd_stats_create(RRD_TYPE_NET_SNMP ".tcpsock", RRD_TYPE_NET_SNMP ".tcpsock", save_history, "IPv4 TCP Connections", "tcp connections", RRD_TYPE_NET_SNMP);
2556 - if(!st) {
2557 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_SNMP ".tcpsock");
2558 - continue;
2559 - }
2562 + st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcpsock", NULL, RRD_TYPE_NET_SNMP, "IPv4 TCP Connections", "active connections", save_history);
2563
2561 - if(!rrd_stats_dimension_add(st, "connections", "connections", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL))
2562 - error("Cannot add RRD_STATS dimension %s.", "connections");
2564 + rrd_stats_dimension_add(st, "connections", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL);
2565 }
2566 else rrd_stats_next(st);
2567
@@ -2568,17 +2570,10 @@ int do_proc_net_snmp() {
2570
2571 st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcppackets");
2572 if(!st) {
2571 - st = rrd_stats_create(RRD_TYPE_NET_SNMP ".tcppackets", RRD_TYPE_NET_SNMP ".tcppackets", save_history, "IPv4 TCP Packets", "Packets/s", RRD_TYPE_NET_SNMP);
2572 - if(!st) {
2573 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_SNMP ".tcppackets");
2574 - continue;
2575 - }
2576 -
2577 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2578 - error("Cannot add RRD_STATS dimension %s.", "sent");
2573 + st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcppackets", NULL, RRD_TYPE_NET_SNMP, "IPv4 TCP Packets", "packets/s", save_history);
2574
2580 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2581 - error("Cannot add RRD_STATS dimension %s.", "received");
2575 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2576 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2577 }
2578 else rrd_stats_next(st);
2579
@@ -2607,17 +2602,10 @@ int do_proc_net_snmp() {
2602 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
2603 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_SNMP ".udppackets");
2604 if(!st) {
2610 - st = rrd_stats_create(RRD_TYPE_NET_SNMP ".udppackets", RRD_TYPE_NET_SNMP ".udppackets", save_history, "IPv4 UDP Packets", "Packets/s", RRD_TYPE_NET_SNMP);
2611 - if(!st) {
2612 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_SNMP ".udppackets");
2613 - continue;
2614 - }
2615 -
2616 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2617 - error("Cannot add RRD_STATS dimension %s.", "sent");
2605 + st = rrd_stats_create(RRD_TYPE_NET_SNMP, "udppackets", NULL, RRD_TYPE_NET_SNMP, "IPv4 UDP Packets", "packets/s", save_history);
2606
2619 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2620 - error("Cannot add RRD_STATS dimension %s.", "received");
2607 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2608 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2609 }
2610 else rrd_stats_next(st);
2611
@@ -2667,18 +2655,10 @@ int do_proc_net_netstat() {
2655
2656 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_SNMP ".net");
2657 if(!st) {
2670 - st = rrd_stats_create(RRD_TYPE_NET_SNMP ".net", RRD_TYPE_NET_SNMP ".net", save_history, "All IPv4 Bandwidth", "bandwidth in kilobits/s", RRD_TYPE_NET_SNMP);
2671 - if(!st) {
2672 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_SNMP ".net");
2673 - continue;
2674 - }
2675 -
2676 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2677 - error("Cannot add RRD_STATS dimension %s.", "sent");
2678 -
2679 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2680 - error("Cannot add RRD_STATS dimension %s.", "received");
2658 + st = rrd_stats_create(RRD_TYPE_NET_SNMP, "net", NULL, RRD_TYPE_NET_SNMP, "All IPv4 Bandwidth", "kilobits/s", save_history);
2659
2660 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2661 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2662 }
2663 else rrd_stats_next(st);
2664
@@ -2746,14 +2726,9 @@ int do_proc_net_stat_conntrack() {
2726
2727 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".sockets");
2728 if(!st) {
2749 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK ".sockets", RRD_TYPE_NET_STAT_CONNTRACK ".sockets", save_history, "Netfilter Connections", "netfilter connections", RRD_TYPE_NET_STAT_CONNTRACK);
2750 - if(!st) {
2751 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_STAT_CONNTRACK ".sockets");
2752 - return 1;
2753 - }
2729 + st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "sockets", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connections", "active connections", save_history);
2730
2755 - if(!rrd_stats_dimension_add(st, "connections", "connections", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL))
2756 - error("Cannot add RRD_STATS dimension %s.", "connections");
2731 + rrd_stats_dimension_add(st, "connections", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL);
2732 }
2733 else rrd_stats_next(st);
2734
@@ -2762,17 +2737,10 @@ int do_proc_net_stat_conntrack() {
2737
2738 st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".new");
2739 if(!st) {
2765 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK ".new", RRD_TYPE_NET_STAT_CONNTRACK ".new", save_history, "Netfilter New Connections", "connections/s", RRD_TYPE_NET_STAT_CONNTRACK);
2766 - if(!st) {
2767 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_STAT_CONNTRACK ".new");
2768 - return 1;
2769 - }
2770 -
2771 - if(!rrd_stats_dimension_add(st, "dropped", "dropped", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2772 - error("Cannot add RRD_STATS dimension %s.", "dropped");
2740 + st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "new", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter New Connections", "connections/s", save_history);
2741
2774 - if(!rrd_stats_dimension_add(st, "new", "new", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2775 - error("Cannot add RRD_STATS dimension %s.", "new");
2742 + rrd_stats_dimension_add(st, "dropped", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2743 + rrd_stats_dimension_add(st, "new", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2744 }
2745 else rrd_stats_next(st);
2746
@@ -2782,17 +2750,10 @@ int do_proc_net_stat_conntrack() {
2750
2751 st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".changes");
2752 if(!st) {
2785 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK ".changes", RRD_TYPE_NET_STAT_CONNTRACK ".changes", save_history, "Netfilter Connection Changes", "connections/s", RRD_TYPE_NET_STAT_CONNTRACK);
2786 - if(!st) {
2787 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_STAT_CONNTRACK ".changes");
2788 - return 1;
2789 - }
2790 -
2791 - if(!rrd_stats_dimension_add(st, "deleted", "deleted", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2792 - error("Cannot add RRD_STATS dimension %s.", "deleted");
2753 + st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "changes", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Changes", "connections/s", save_history);
2754
2794 - if(!rrd_stats_dimension_add(st, "inserted", "inserted", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2795 - error("Cannot add RRD_STATS dimension %s.", "inserted");
2755 + rrd_stats_dimension_add(st, "deleted", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2756 + rrd_stats_dimension_add(st, "inserted", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2757 }
2758 else rrd_stats_next(st);
2759
@@ -2848,14 +2809,9 @@ int do_proc_net_ip_vs_stats() {
2809
2810 RRD_STATS *st = rrd_stats_find(RRD_TYPE_NET_IPVS ".sockets");
2811 if(!st) {
2851 - st = rrd_stats_create(RRD_TYPE_NET_IPVS ".sockets", RRD_TYPE_NET_IPVS ".sockets", save_history, "IPVS New Connections", "new connections/s", RRD_TYPE_NET_IPVS);
2852 - if(!st) {
2853 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_IPVS ".sockets");
2854 - return 1;
2855 - }
2812 + st = rrd_stats_create(RRD_TYPE_NET_IPVS, "sockets", NULL, RRD_TYPE_NET_IPVS, "IPVS New Connections", "connections/s", save_history);
2813
2857 - if(!rrd_stats_dimension_add(st, "connections", "connections", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2858 - error("Cannot add RRD_STATS dimension %s.", "connections");
2814 + rrd_stats_dimension_add(st, "connections", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2815 }
2816 else rrd_stats_next(st);
2817
@@ -2864,17 +2820,10 @@ int do_proc_net_ip_vs_stats() {
2820
2821 st = rrd_stats_find(RRD_TYPE_NET_IPVS ".packets");
2822 if(!st) {
2867 - st = rrd_stats_create(RRD_TYPE_NET_IPVS ".packets", RRD_TYPE_NET_IPVS ".packets", save_history, "IPVS Packets", "Packets/s", RRD_TYPE_NET_IPVS);
2868 - if(!st) {
2869 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_IPVS ".packets");
2870 - return 1;
2871 - }
2872 -
2873 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2874 - error("Cannot add RRD_STATS dimension %s.", "sent");
2823 + st = rrd_stats_create(RRD_TYPE_NET_IPVS, "packets", NULL, RRD_TYPE_NET_IPVS, "IPVS Packets", "packets/s", save_history);
2824
2876 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
2877 - error("Cannot add RRD_STATS dimension %s.", "received");
2825 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2826 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2827 }
2828 else rrd_stats_next(st);
2829
@@ -2884,17 +2833,10 @@ int do_proc_net_ip_vs_stats() {
2833
2834 st = rrd_stats_find(RRD_TYPE_NET_IPVS ".net");
2835 if(!st) {
2887 - st = rrd_stats_create(RRD_TYPE_NET_IPVS ".net", RRD_TYPE_NET_IPVS ".net", save_history, "IPVS Bandwidth", "bandwidth in kilobits/s", RRD_TYPE_NET_IPVS);
2888 - if(!st) {
2889 - error("Cannot create RRD_STATS for %s.", RRD_TYPE_NET_IPVS ".net");
2890 - return 1;
2891 - }
2836 + st = rrd_stats_create(RRD_TYPE_NET_IPVS, "net", NULL, RRD_TYPE_NET_IPVS, "IPVS Bandwidth", "kilobits/s", save_history);
2837
2893 - if(!rrd_stats_dimension_add(st, "sent", "sent", sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2894 - error("Cannot add RRD_STATS dimension %s.", "sent");
2895 -
2896 - if(!rrd_stats_dimension_add(st, "received", "received", sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
2897 - error("Cannot add RRD_STATS dimension %s.", "received");
2838 + rrd_stats_dimension_add(st, "sent", NULL, sizeof(unsigned long long), 0, -8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2839 + rrd_stats_dimension_add(st, "received", NULL, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
2840 }
2841 else rrd_stats_next(st);
2842
@@ -2919,61 +2861,37 @@ int do_proc_stat() {
2861 if(!p) break;
2862
2863 if(strncmp(p, "cpu", 3) == 0) {
2922 - char id[MAX_PROC_STAT_NAME + 1] = RRD_TYPE_STAT ".";
2864 + char id[MAX_PROC_STAT_NAME + 1] = "";
2865 unsigned long long user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0, guest_nice = 0;
2924 - char *name = &id[RRD_TYPE_STAT_LEN + 1];
2866
2867 int r = sscanf(buffer, "%s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
2927 - name, &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
2868 + id, &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
2869
2870 if(r == EOF) break;
2871 if(r < 10) error("Cannot read /proc/stat cpu line. Expected 11 params, read %d.", r);
2872
2932 - RRD_STATS *st = rrd_stats_find(id);
2873 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_STAT, id);
2874 if(!st) {
2934 - st = rrd_stats_create(id, id, save_history, "Time for ", "percentage", RRD_TYPE_STAT);
2935 - if(!st) {
2936 - error("Cannot create RRD_STATS for %s.", id);
2937 - continue;
2938 - }
2875 + char *title = "Core utilization";
2876 + if(strcmp(id, "cpu") == 0) title = "Total CPU utilization";
2877
2940 - if(strcmp(id, "cpu.cpu") == 0) strcpy(st->usertitle, "all CPUs");
2941 - else strcpy(st->usertitle, name);
2878 + st = rrd_stats_create(RRD_TYPE_STAT, id, NULL, RRD_TYPE_STAT, title, "percentage", save_history);
2879
2880 long multiplier = 1;
2881 long divisor = 1; // sysconf(_SC_CLK_TCK);
2882
2946 - if(!rrd_stats_dimension_add(st, "iowait", "iowait", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2947 - error("Cannot add RRD_STATS dimension %s.", "iowait");
2948 -
2949 - if(!rrd_stats_dimension_add(st, "nice", "nice", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2950 - error("Cannot add RRD_STATS dimension %s.", "nice");
2951 -
2952 - if(!rrd_stats_dimension_add(st, "system", "system", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2953 - error("Cannot add RRD_STATS dimension %s.", "system");
2954 -
2955 - if(!rrd_stats_dimension_add(st, "user", "user", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2956 - error("Cannot add RRD_STATS dimension %s.", "user");
2957 -
2958 - if(!rrd_stats_dimension_add(st, "idle", "idle", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2959 - error("Cannot add RRD_STATS dimension %s.", "idle");
2960 - else rrd_stats_dimension_hide(st, "idle");
2961 -
2962 - if(!rrd_stats_dimension_add(st, "irq", "irq", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2963 - error("Cannot add RRD_STATS dimension %s.", "irq");
2964 -
2965 - if(!rrd_stats_dimension_add(st, "softirq", "softirq", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2966 - error("Cannot add RRD_STATS dimension %s.", "softirq");
2967 -
2968 - if(!rrd_stats_dimension_add(st, "steal", "steal", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2969 - error("Cannot add RRD_STATS dimension %s.", "steal");
2970 -
2971 - if(!rrd_stats_dimension_add(st, "guest", "guest", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2972 - error("Cannot add RRD_STATS dimension %s.", "guest");
2973 -
2974 - if(!rrd_stats_dimension_add(st, "guest_nice", "guest_nice", sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL))
2975 - error("Cannot add RRD_STATS dimension %s.", "guest_nice");
2976 -
2883 + rrd_stats_dimension_add(st, "iowait", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2884 + rrd_stats_dimension_add(st, "nice", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2885 + rrd_stats_dimension_add(st, "system", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2886 + rrd_stats_dimension_add(st, "user", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2887 + rrd_stats_dimension_add(st, "idle", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2888 + rrd_stats_dimension_hide(st, "idle");
2889 +
2890 + rrd_stats_dimension_add(st, "irq", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2891 + rrd_stats_dimension_add(st, "softirq", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2892 + rrd_stats_dimension_add(st, "steal", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2893 + rrd_stats_dimension_add(st, "guest", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2894 + rrd_stats_dimension_add(st, "guest_nice", NULL, sizeof(unsigned long long), 0, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_TOTAL, NULL);
2895 }
2896 else rrd_stats_next(st);
2897
@@ -2990,26 +2908,19 @@ int do_proc_stat() {
2908 rrd_stats_done(st);
2909 }
2910 else if(strncmp(p, "intr ", 5) == 0) {
2993 - char id[MAX_PROC_STAT_NAME + 1] = RRD_TYPE_STAT ".";
2994 - char *name = &id[RRD_TYPE_STAT_LEN + 1];
2911 + char id[MAX_PROC_STAT_NAME + 1];
2912
2913 unsigned long long value;
2914
2998 - int r = sscanf(buffer, "%s %llu ", name, &value);
2915 + int r = sscanf(buffer, "%s %llu ", id, &value);
2916 if(r == EOF) break;
2917 if(r != 2) error("Cannot read /proc/stat intr line. Expected 2 params, read %d.", r);
2918
3002 - RRD_STATS *st = rrd_stats_find(id);
2919 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_STAT, id);
2920 if(!st) {
3004 - st = rrd_stats_create(id, id, save_history, "CPU Interrupts", "interrupts/s", RRD_TYPE_STAT);
3005 - if(!st) {
3006 - error("Cannot create RRD_STATS for %s.", id);
3007 - continue;
3008 - }
3009 -
3010 - if(!rrd_stats_dimension_add(st, "interrupts", "interrupts", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
3011 - error("Cannot add RRD_STATS dimension %s.", "interrupts");
2921 + st = rrd_stats_create(RRD_TYPE_STAT, id, NULL, RRD_TYPE_STAT, "CPU Interrupts", "interrupts/s", save_history);
2922
2923 + rrd_stats_dimension_add(st, "interrupts", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2924 }
2925 else rrd_stats_next(st);
2926
@@ -3017,26 +2928,19 @@ int do_proc_stat() {
2928 rrd_stats_done(st);
2929 }
2930 else if(strncmp(p, "ctxt ", 5) == 0) {
3020 - char id[MAX_PROC_STAT_NAME + 1] = RRD_TYPE_STAT ".";
3021 - char *name = &id[RRD_TYPE_STAT_LEN + 1];
2931 + char id[MAX_PROC_STAT_NAME + 1] = "";
2932
2933 unsigned long long value;
2934
3025 - int r = sscanf(buffer, "%s %llu ", name, &value);
2935 + int r = sscanf(buffer, "%s %llu ", id, &value);
2936 if(r == EOF) break;
2937 if(r != 2) error("Cannot read /proc/stat ctxt line. Expected 2 params, read %d.", r);
2938
3029 - RRD_STATS *st = rrd_stats_find(id);
2939 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_STAT, id);
2940 if(!st) {
3031 - st = rrd_stats_create(id, id, save_history, "CPU Context Switches", "context switches/s", RRD_TYPE_STAT);
3032 - if(!st) {
3033 - error("Cannot create RRD_STATS for %s.", id);
3034 - continue;
3035 - }
3036 -
3037 - if(!rrd_stats_dimension_add(st, "switches", "switches", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
3038 - error("Cannot add RRD_STATS dimension %s.", "switches");
2941 + st = rrd_stats_create(RRD_TYPE_STAT, id, NULL, RRD_TYPE_STAT, "CPU Context Switches", "context switches/s", save_history);
2942
2943 + rrd_stats_dimension_add(st, "switches", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2944 }
2945 else rrd_stats_next(st);
2946
@@ -3044,26 +2948,19 @@ int do_proc_stat() {
2948 rrd_stats_done(st);
2949 }
2950 else if(strncmp(p, "processes ", 10) == 0) {
3047 - char id[MAX_PROC_STAT_NAME + 1] = RRD_TYPE_STAT ".";
3048 - char *name = &id[RRD_TYPE_STAT_LEN + 1];
2951 + char id[MAX_PROC_STAT_NAME + 1] = "";
2952
2953 unsigned long long value;
2954
3052 - int r = sscanf(buffer, "%s %llu ", name, &value);
2955 + int r = sscanf(buffer, "%s %llu ", id, &value);
2956 if(r == EOF) break;
2957 if(r != 2) error("Cannot read /proc/stat processes line. Expected 2 params, read %d.", r);
2958
3056 - RRD_STATS *st = rrd_stats_find(id);
2959 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_STAT, id);
2960 if(!st) {
3058 - st = rrd_stats_create(id, id, save_history, "Started Processes", "processes/s", RRD_TYPE_STAT);
3059 - if(!st) {
3060 - error("Cannot create RRD_STATS for %s.", id);
3061 - continue;
3062 - }
3063 -
3064 - if(!rrd_stats_dimension_add(st, "started", "started", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL))
3065 - error("Cannot add RRD_STATS dimension %s.", "started");
2961 + st = rrd_stats_create(RRD_TYPE_STAT, id, NULL, RRD_TYPE_STAT, "Started Processes", "processes/s", save_history);
2962
2963 + rrd_stats_dimension_add(st, "started", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_INCREMENTAL, NULL);
2964 }
2965 else rrd_stats_next(st);
2966
@@ -3071,26 +2968,19 @@ int do_proc_stat() {
2968 rrd_stats_done(st);
2969 }
2970 else if(strncmp(p, "procs_running ", 14) == 0) {
3074 - char id[MAX_PROC_STAT_NAME + 1] = RRD_TYPE_STAT ".";
3075 - char *name = &id[RRD_TYPE_STAT_LEN + 1];
2971 + char id[MAX_PROC_STAT_NAME + 1] = "";
2972
2973 unsigned long long value;
2974
3079 - int r = sscanf(buffer, "%s %llu ", name, &value);
2975 + int r = sscanf(buffer, "%s %llu ", id, &value);
2976 if(r == EOF) break;
2977 if(r != 2) error("Cannot read /proc/stat processes line. Expected 2 params, read %d.", r);
2978
3083 - RRD_STATS *st = rrd_stats_find(id);
2979 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_STAT, id);
2980 if(!st) {
3085 - st = rrd_stats_create(id, id, save_history, "CPU Running Processes", "processes running", RRD_TYPE_STAT);
3086 - if(!st) {
3087 - error("Cannot create RRD_STATS for %s.", id);
3088 - continue;
3089 - }
3090 -
3091 - if(!rrd_stats_dimension_add(st, "running", "running", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL))
3092 - error("Cannot add RRD_STATS dimension %s.", "running");
2981 + st = rrd_stats_create(RRD_TYPE_STAT, id, NULL, RRD_TYPE_STAT, "CPU Running Processes", "processes running", save_history);
2982
2983 + rrd_stats_dimension_add(st, "running", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL);
2984 }
2985 else rrd_stats_next(st);
2986
@@ -3188,6 +3078,7 @@ struct tc_class {
3078 struct tc_device {
3079 char id[RRD_STATS_NAME_MAX + 1];
3080 char name[RRD_STATS_NAME_MAX + 1];
3081 + char group[RRD_STATS_NAME_MAX + 1];
3082
3083 struct tc_class *classes;
3084 };
@@ -3228,19 +3119,13 @@ void tc_device_commit(struct tc_device *d)
3119
3120 debug(D_TC_LOOP, "Committing TC device '%s'", d->name);
3121
3231 - RRD_STATS *st = rrd_stats_find(d->id);
3122 + RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_TC, d->id);
3123 if(!st) {
3233 - st = rrd_stats_create(d->id, d->name, save_history, "Class usage for ", "Bandwidth in kilobits/s", RRD_TYPE_TC);
3234 - if(!st) {
3235 - error("Cannot create RRD_STATS for interface %s.", d->name);
3236 - return;
3237 - }
3124 + st = rrd_stats_create(RRD_TYPE_TC, d->id, d->name, d->group, "Class usage for ", "kilobits/s", save_history);
3125
3126 for ( c = d->classes ; c ; c = c->next) {
3240 - if(c->isleaf && c->hasparent) {
3241 - if(!rrd_stats_dimension_add(st, c->id, c->name, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
3242 - error("Cannot add RRD_STATS dimension %s.", c->name);
3243 - }
3127 + if(c->isleaf && c->hasparent)
3128 + rrd_stats_dimension_add(st, c->id, c->name, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
3129 }
3130 }
3131 else rrd_stats_next(st);
@@ -3250,14 +3135,12 @@ void tc_device_commit(struct tc_device *d)
3135 if(rrd_stats_dimension_set(st, c->id, &c->bytes, NULL) != 0) {
3136
3137 // new class, we have to add it
3253 - if(!rrd_stats_dimension_add(st, c->id, c->name, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL))
3254 - error("Cannot add RRD_STATS dimension %s.", c->name);
3255 - else rrd_stats_dimension_set(st, c->id, &c->bytes, NULL);
3138 + rrd_stats_dimension_add(st, c->id, c->name, sizeof(unsigned long long), 0, 8, 1024, RRD_DIMENSION_INCREMENTAL, NULL);
3139 + rrd_stats_dimension_set(st, c->id, &c->bytes, NULL);
3140 }
3141
3142 // if it has a name, different to the id
3143 if(strcmp(c->id, c->name) != 0) {
3260 -
3144 // update the rrd dimension with the new name
3145 RRD_DIMENSION *rd;
3146 for(rd = st->dimensions ; rd ; rd = rd->next) {
@@ -3283,9 +3166,14 @@ void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
3166
3167 void tc_device_set_device_name(struct tc_device *d, char *name)
3168 {
3286 - strcpy(d->name, RRD_TYPE_TC ".");
3287 - strncpy(&d->name[RRD_TYPE_TC_LEN + 1], name, RRD_STATS_NAME_MAX - 3);
3288 - d->name[RRD_STATS_NAME_MAX] = '\0';
3169 + strncpy(d->name, name, RRD_STATS_NAME_MAX);
3170 + // no need for null termination - it is already null
3171 +}
3172 +
3173 +void tc_device_set_device_group(struct tc_device *d, char *name)
3174 +{
3175 + strncpy(d->group, name, RRD_STATS_NAME_MAX);
3176 + // no need for null termination - it is already null
3177 }
3178
3179 struct tc_device *tc_device_create(char *name)
@@ -3293,12 +3181,14 @@ struct tc_device *tc_device_create(char *name)
3181 struct tc_device *d;
3182
3183 d = calloc(1, sizeof(struct tc_device));
3296 - if(!d) return NULL;
3297 -
3298 - strcpy(d->name, RRD_TYPE_TC ".");
3299 - strncpy(&d->name[RRD_TYPE_TC_LEN + 1], name, RRD_STATS_NAME_MAX - RRD_TYPE_TC_LEN - 1);
3184 + if(!d) {
3185 + fatal("Cannot allocate memory for tc_device %s", name);
3186 + return NULL;
3187 + }
3188
3301 - strcpy(d->id, d->name);
3189 + strncpy(d->id, name, RRD_STATS_NAME_MAX);
3190 + strcpy(d->name, d->id);
3191 + strcpy(d->group, d->id);
3192
3193 // no need for null termination on the strings, because of calloc()
3194
@@ -3310,7 +3200,10 @@ struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, cha
3200 struct tc_class *c;
3201
3202 c = calloc(1, sizeof(struct tc_class));
3313 - if(!c) return NULL;
3203 + if(!c) {
3204 + fatal("Cannot allocate memory for tc class");
3205 + return NULL;
3206 + }
3207
3208 c->next = n->classes;
3209 n->classes = c;
@@ -3375,7 +3268,10 @@ void *tc_main(void *ptr)
3268 }
3269
3270 p = strsep(&b, " \n");
3378 - if(p && *p) device = tc_device_create(p);
3271 + if(p && *p) {
3272 + device = tc_device_create(p);
3273 + class = NULL;
3274 + }
3275 }
3276 else if(device && (strcmp(p, "class") == 0)) {
3277 p = strsep(&b, " \n"); // the class: htb, fq_codel, etc
@@ -3415,12 +3311,16 @@ void *tc_main(void *ptr)
3311 if(p && *p) class->bytes = atoll(p);
3312 }
3313 else if(device && (strcmp(p, "SETDEVICENAME") == 0)) {
3418 - char *name = strsep(&b, " |\n");
3314 + char *name = strsep(&b, " \n");
3315 if(name && *name) tc_device_set_device_name(device, name);
3316 }
3317 + else if(device && (strcmp(p, "SETDEVICEGROUP") == 0)) {
3318 + char *name = strsep(&b, " \n");
3319 + if(name && *name) tc_device_set_device_group(device, name);
3320 + }
3321 else if(device && (strcmp(p, "SETCLASSNAME") == 0)) {
3422 - char *id = strsep(&b, " |\n");
3423 - char *path = strsep(&b, " |\n");
3322 + char *id = strsep(&b, " \n");
3323 + char *path = strsep(&b, " \n");
3324 if(id && *id && path && *path) tc_device_set_class_name(device, id, path);
3325 }
3326 else if((strcmp(p, "MYPID") == 0)) {
@@ -3470,15 +3370,9 @@ void *cpuidlejitter_main(void *ptr)
3370
3371 RRD_STATS *st = rrd_stats_find(RRD_TYPE_STAT ".idlejitter");
3372 if(!st) {
3473 - st = rrd_stats_create(RRD_TYPE_STAT ".idlejitter", RRD_TYPE_STAT ".idlejitter", save_history, "CPU Idle Jitter", "microseconds lost", RRD_TYPE_STAT);
3474 - if(!st) {
3475 - error("Cannot create RRD_STATS for interface %s.", RRD_TYPE_STAT ".idlejitter");
3476 - continue;
3477 - }
3478 -
3479 - if(!rrd_stats_dimension_add(st, "jitter", "jitter", sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL))
3480 - error("Cannot add RRD_STATS dimension %s.", "jitter");
3373 + st = rrd_stats_create(RRD_TYPE_STAT, "idlejitter", NULL, RRD_TYPE_STAT, "CPU Idle Jitter", "microseconds lost/s", save_history);
3374
3375 + rrd_stats_dimension_add(st, "jitter", NULL, sizeof(unsigned long long), 0, 1, 1, RRD_DIMENSION_ABSOLUTE, NULL);
3376 }
3377 else rrd_stats_next(st);
3378
tc-all.sh
+2
@@ -36,6 +36,8 @@ show_tc() {
36 do
37 setclassname `echo $n | tr '|' ' '`
38 done
39 +
40 + echo "SETDEVICEGROUP $interface_dev"
41 fi
42 echo "END $x"
43 }
web/netdata.js
+1 -1
@@ -228,7 +228,7 @@ function loadCharts(base_url, doNext) {
228 lineWidth: 1,
229 title: json.charts[i].title,
230 hAxis: {title: "Time of Day", viewWindowMode: 'maximized', format:'HH:mm:ss'},
231 - vAxis: {title: json.charts[i].vtitle, viewWindowMode: 'pretty', minValue: 0, maxValue: 10},
231 + vAxis: {title: json.charts[i].units, viewWindowMode: 'pretty', minValue: 0, maxValue: 10},
232 focusTarget: 'category',
233 annotation: {'1': {style: 'line'}},
234 //tooltip: {isHtml: true},