comparison extensions/test_ccload/test_ccload.c @ 1381:f374d3f8f7d3

test_ccload: add statistics for received messages
author Thomas Klausner <tk@giga.or.at>
date Wed, 26 Jun 2019 18:11:36 +0200
parents 2bd83cd4d2b2
children f62e18dc4800
comparison
equal deleted inserted replaced
1380:1fe534395b05 1381:f374d3f8f7d3
64 struct statistics { 64 struct statistics {
65 uint64_t sent; 65 uint64_t sent;
66 uint64_t success; 66 uint64_t success;
67 uint64_t error; 67 uint64_t error;
68 time_t first; 68 time_t first;
69 time_t first_reply;
69 time_t last; 70 time_t last;
71 time_t last_reply;
70 } statistics; 72 } statistics;
71 73
72 void print_statistics(void) { 74 void print_statistics(void) {
73 uint64_t missing; 75 uint64_t missing, received;
74 76
75 if (statistics.first == 0 || statistics.last == 0 || statistics.last == statistics.first) { 77 if (statistics.first == 0 || statistics.last == 0 || statistics.last == statistics.first) {
76 return; 78 return;
77 } 79 }
78 80
79 missing = statistics.sent - statistics.error - statistics.success; 81 received = statistics.error + statistics.success;
80 82 missing = statistics.sent - received;
81 fd_log_error("%s: %lld CCR messages sent in %llds (%.2f messages/second), %lld success (%.2f%%), %lld errors (%.2f%%), %lld missing (%.2f%%)", 83
84 fd_log_error("%s: %lld CCR messages sent in %llds (%.2f messages/second), %lld CCA messages received in %llds (%.2f messages/second), %lld success (%.2f%%), %lld errors (%.2f%%), %lld missing (%.2f%%)",
82 fd_g_config->cnf_diamid, 85 fd_g_config->cnf_diamid,
83 (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first), 86 (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first),
87 (long long)received, (long long)(statistics.last_reply-statistics.first_reply), (float)received / (statistics.last_reply-statistics.first_reply),
84 (long long)statistics.success, 88 (long long)statistics.success,
85 100*(float)statistics.success/statistics.sent, (long long)statistics.error, 100*(float)statistics.error/statistics.sent, 89 100*(float)statistics.success/statistics.sent, (long long)statistics.error, 100*(float)statistics.error/statistics.sent,
86 missing, 100*(float)missing/statistics.sent); 90 missing, 100*(float)missing/statistics.sent);
87 } 91 }
88 92
101 if ((hdr->msg_code != 272) || (hdr->msg_flags & CMD_FLAG_REQUEST)) { 105 if ((hdr->msg_code != 272) || (hdr->msg_flags & CMD_FLAG_REQUEST)) {
102 fd_log_error("[%s] invalid message type (type %d, flags 0x%x)", MODULE_NAME, hdr->msg_code, hdr->msg_flags); 106 fd_log_error("[%s] invalid message type (type %d, flags 0x%x)", MODULE_NAME, hdr->msg_code, hdr->msg_flags);
103 return -1; 107 return -1;
104 } 108 }
105 109
110 if (statistics.first_reply == 0) {
111 statistics.first_reply = time(NULL);
112 }
106 /* Answer received, check it */ 113 /* Answer received, check it */
107 if (fd_msg_search_avp(*msg, rc_avp_do, &rc) < 0 || rc == NULL) { 114 if (fd_msg_search_avp(*msg, rc_avp_do, &rc) < 0 || rc == NULL) {
108 fd_log_error("[%s] Result-Code not found in CCA", MODULE_NAME); 115 fd_log_error("[%s] Result-Code not found in CCA", MODULE_NAME);
109 return -1; 116 return -1;
110 } 117 }
111 118
112 if (fd_msg_avp_hdr(rc, &ahdr) < 0) { 119 if (fd_msg_avp_hdr(rc, &ahdr) < 0) {
113 fd_log_error("[%s] error parsing Result-Code in CCA", MODULE_NAME); 120 fd_log_error("[%s] error parsing Result-Code in CCA", MODULE_NAME);
114 return -1; 121 return -1;
115 } 122 }
123 statistics.last_reply = time(NULL);
116 fd_log_debug("Credit-Control-Answer with Result-Code %d received", ahdr->avp_value->i32); 124 fd_log_debug("Credit-Control-Answer with Result-Code %d received", ahdr->avp_value->i32);
117 switch (ahdr->avp_value->i32/1000) { 125 switch (ahdr->avp_value->i32/1000) {
118 case 2: 126 case 2:
119 statistics.success++; 127 statistics.success++;
120 break; 128 break;
121 default: 129 default:
122 statistics.error++; 130 statistics.error++;
123 break; 131 break;
132 }
133 if (statistics.sent - statistics.error - statistics.success == 0) {
134 print_statistics();
124 } 135 }
125 136
126 return 0; 137 return 0;
127 } 138 }
128 139
"Welcome to our mercurial repository"