now it attempts to parse only HTB classes and it collects all values: bytes, packets, dropped, overlimits, requeues, lended, borrowed, giants, tokens, ctokens
Costa Tsaousis (ktsaou) committed
Feb 28, 2016 at 04:33 UTC
ccaf15f9bb7925ff3c5ef1ac7a6e6e32dad84e5b
1 file changed
+55
-7
src/plugin_tc.c
+55
-7
@@ -42,6 +42,15 @@ struct tc_class {
42
char hasparent;
43
char isleaf;
44
unsigned long long bytes;
45
+ unsigned long long packets;
46
+ unsigned long long dropped;
47
+ unsigned long long overlimits;
48
+ unsigned long long requeues;
49
+ unsigned long long lended;
50
+ unsigned long long borrowed;
51
+ unsigned long long giants;
52
+ unsigned long long tokens;
53
+ unsigned long long ctokens;
54
55
char updated; // updated bytes
56
char seen; // seen in the tc list (even without bytes)
@@ -499,6 +508,8 @@ void *tc_main(void *ptr)
508
uint32_t END_HASH = simple_hash("END");
509
uint32_t CLASS_HASH = simple_hash("class");
510
uint32_t SENT_HASH = simple_hash("Sent");
511
+ uint32_t LENDED_HASH = simple_hash("lended:");
512
+ uint32_t TOKENS_HASH = simple_hash("tokens:");
513
uint32_t SETDEVICENAME_HASH = simple_hash("SETDEVICENAME");
514
uint32_t SETDEVICEGROUP_HASH = simple_hash("SETDEVICEGROUP");
515
uint32_t SETCLASSNAME_HASH = simple_hash("SETCLASSNAME");
@@ -540,11 +551,18 @@ void *tc_main(void *ptr)
551
552
first_hash = simple_hash(words[0]);
553
543
- if(first_hash == CLASS_HASH && strcmp(words[0], "class") == 0 && device) {
554
+ if(device && first_hash == CLASS_HASH && strcmp(words[0], "class") == 0) {
555
// debug(D_TC_LOOP, "CLASS line on class id='%s', parent='%s', parentid='%s', leaf='%s', leafid='%s'", words[2], words[3], words[4], words[5], words[6]);
556
557
+ // clear the last class
558
+ class = NULL;
559
+
560
if(words[1] && words[2] && words[3] && words[4] && (strcmp(words[3], "parent") == 0 || strcmp(words[3], "root") == 0)) {
547
- // char *type = words[1]; // the class: htb, fq_codel, etc
561
+ char *type = words[1]; // the class: htb, fq_codel, etc
562
+
563
+ // we are only interested for HTB classes
564
+ if(strcmp(type, "htb") != 0) continue;
565
+
566
char *id = words[2]; // the class major:minor
567
char *parent = words[3]; // 'parent' or 'root'
568
char *parentid = words[4]; // the parent's id
@@ -598,23 +616,53 @@ void *tc_main(void *ptr)
616
class = NULL;
617
}
618
}
601
- else if(first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0 && device && class) {
619
+ else if(device && class && first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0) {
620
// debug(D_TC_LOOP, "SENT line '%s'", words[1]);
621
if(words[1] && *words[1]) {
622
class->bytes = strtoull(words[1], NULL, 10);
623
class->updated = 1;
624
}
607
- else class->bytes = 0;
625
+
626
+ if(words[3] && *words[3])
627
+ class->packets = strtoull(words[3], NULL, 10);
628
+
629
+ if(words[6] && *words[6])
630
+ class->dropped = strtoull(words[6], NULL, 10);
631
+
632
+ if(words[8] && *words[8])
633
+ class->overlimits = strtoull(words[8], NULL, 10);
634
+
635
+ if(words[10] && *words[10])
636
+ class->requeues = strtoull(words[8], NULL, 10);
637
+ }
638
+ else if(device && class && class->updated && first_hash == LENDED_HASH && strcmp(words[0], "lended:") == 0) {
639
+ // debug(D_TC_LOOP, "LENDED line '%s'", words[1]);
640
+ if(words[1] && *words[1])
641
+ class->lended = strtoull(words[1], NULL, 10);
642
+
643
+ if(words[3] && *words[3])
644
+ class->borrowed = strtoull(words[3], NULL, 10);
645
+
646
+ if(words[5] && *words[5])
647
+ class->giants = strtoull(words[5], NULL, 10);
648
+ }
649
+ else if(device && class && class->updated && first_hash == TOKENS_HASH && strcmp(words[0], "tokens:") == 0) {
650
+ // debug(D_TC_LOOP, "TOKENS line '%s'", words[1]);
651
+ if(words[1] && *words[1])
652
+ class->tokens = strtoull(words[1], NULL, 10);
653
+
654
+ if(words[3] && *words[3])
655
+ class->ctokens = strtoull(words[3], NULL, 10);
656
}
609
- else if(first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0 && device) {
657
+ else if(device && first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0) {
658
// debug(D_TC_LOOP, "SETDEVICENAME line '%s'", words[1]);
659
if(words[1] && *words[1]) tc_device_set_device_name(device, words[1]);
660
}
613
- else if(first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0 && device) {
661
+ else if(device && first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0) {
662
// debug(D_TC_LOOP, "SETDEVICEGROUP line '%s'", words[1]);
663
if(words[1] && *words[1]) tc_device_set_device_family(device, words[1]);
664
}
617
- else if(first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0 && device) {
665
+ else if(device && first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0) {
666
// debug(D_TC_LOOP, "SETCLASSNAME line '%s' '%s'", words[1], words[2]);
667
char *id = words[1];
668
char *path = words[2];