github.com/zartbot/goflow@v0.0.0-20221001080520-456f7dfad288/service/ciscoavc/meandelay.go (about) 1 package ciscoavc 2 3 import ( 4 "github.com/zartbot/go_utils/map2value" 5 ) 6 7 /* 8 Field Definition Link: 9 https://www.cisco.com/c/en/us/td/docs/ios/solutions_docs/avc/guide/avc-user-guide/avc_config.html 10 https://www.cisco.com/c/en/us/td/docs/routers/access/ISRG2/AVC/api/guide/AVC_Metric_Definition_Guide/5_AVC_Metric_Def.html 11 https://www.cisco.com/c/en/us/td/docs/ios/solutions_docs/avc/ios_xe3_9/avc_soln_guide_iosxe3_9/avc_app_exported_fields.html 12 13 conn_delay_app_sum [milliseconds] 14 CLI: collect connection delay app sum 15 16 conn_delay_response_to_server_sum [milliseconds] 17 * CLI: collect connection delay response to-server sum 18 * Response time is the time between the client request and the corresponding first response packet 19 * from the server, as observed at the observation point. The value of this information element is 20 * the sum of all response times observed for the responses of this flow. For the average, this field 21 * must be divided by numRespsCountDelta (42060). 22 23 conn_delay_response_client_to_server_sum [milliseconds] 24 * CLI: collect connection delay response client-to-server sum 25 * Total delay is the time between the client request and the first response packet from the server, 26 * as seen by the client. This is the sum of all total delays observed for the responses of this flow. 27 * For the average, this field must be divided by numRespsCountDelta (42060) 28 29 */ 30 type ResponseDelay struct { 31 App float32 32 Client2Server float32 33 ToServer float32 34 } 35 36 func meanAppDelay(d map[string]interface{}) *ResponseDelay { 37 r := &ResponseDelay{ 38 App: 0, 39 Client2Server: 0, 40 ToServer: 0, 41 } 42 SrvRspCnt, ErrSrvRspCnt := map2value.MapToUInt32(d, "conn_server_response_cnt") 43 DelayAppSum, ErrDelayAppSum := map2value.MapToUInt32(d, "conn_delay_app_sum") 44 DelayRspC2SSum, ErrDelayRspC2SSum := map2value.MapToUInt32(d, "conn_delay_response_client_to_server_sum") 45 DelayRsp2SSum, ErrDelayRsp2SSum := map2value.MapToUInt32(d, "conn_delay_response_to_server_sum") 46 if ErrSrvRspCnt == nil && SrvRspCnt > 0 { 47 var SrvRspCntFloat32 = float32(SrvRspCnt) 48 if ErrDelayAppSum == nil { 49 r.App = float32(DelayAppSum) / SrvRspCntFloat32 50 } 51 52 if ErrDelayRspC2SSum == nil { 53 r.Client2Server = float32(DelayRspC2SSum) / SrvRspCntFloat32 54 } 55 56 if ErrDelayRsp2SSum == nil { 57 r.ToServer = float32(DelayRsp2SSum) / SrvRspCntFloat32 58 } 59 } 60 return r 61 } 62 63 type NetWorkDelay struct { 64 Client float32 65 Server float32 66 Total float32 //client2server 67 } 68 69 type Duration struct { 70 ConnTotal float32 71 ConnMean float32 72 TransTotal float32 73 TransMean float32 74 } 75 76 func meanNetDelay(d map[string]interface{}) (*NetWorkDelay, *Duration) { 77 78 network := &NetWorkDelay{ 79 Client: 0, 80 Server: 0, 81 Total: 0, 82 } 83 duration := &Duration{ 84 ConnTotal: 0, 85 ConnMean: 0, 86 TransTotal: 0, 87 TransMean: 0, 88 } 89 90 //Trans duration mean 91 NumTrans, ErrNumTrans := map2value.MapToUInt32(d, "conn_transaction_cnt_complete") 92 TransDuraSum, ErrTransDuraSum := map2value.MapToUInt32(d, "conn_transaction_duration_sum") 93 if (ErrNumTrans == nil) && (ErrTransDuraSum == nil) { 94 if NumTrans > 0 { 95 duration.TransMean = float32(TransDuraSum) / float32(NumTrans) 96 duration.TransTotal = float32(TransDuraSum) 97 } 98 } 99 100 NumConn, ErrNumConn := map2value.MapToUInt32(d, "newConnectionDeltaCount") 101 DuraSum, ErrDuraSum := map2value.MapToUInt64(d, "connectionSumDurationSeconds") 102 CNetDelaySum, ErrCNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_to_client_sum") 103 SNetDelaySum, ErrSNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_to_server_sum") 104 C2SNetDelaySum, ErrC2SNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_client_to_server_sum") 105 106 if ErrNumConn == nil && NumConn > 0 { 107 var NumConnFloat32 = float32(NumConn) 108 if ErrDuraSum == nil { 109 duration.ConnMean = float32(float64(DuraSum) / float64(NumConn)) 110 duration.ConnTotal = float32(DuraSum) 111 } 112 113 if ErrCNetDelaySum == nil { 114 network.Client = float32(float32(CNetDelaySum) / NumConnFloat32) 115 116 } 117 if ErrSNetDelaySum == nil { 118 network.Server = float32(float32(SNetDelaySum) / NumConnFloat32) 119 } 120 121 if ErrC2SNetDelaySum == nil { 122 network.Total = float32(float32(C2SNetDelaySum) / NumConnFloat32) 123 } 124 } 125 126 tn := network.Client + network.Server 127 if tn > network.Total { 128 network.Total = tn 129 } 130 return network, duration 131 } 132 133 //Long Live Record Mode 134 func meanLLNetDelay(d map[string]interface{}) (*NetWorkDelay, *Duration) { 135 network := new(NetWorkDelay) 136 duration := new(Duration) 137 138 //Conn duration mean 139 NumConn, ErrNumConn := map2value.MapToUInt32(d, "newConnectionDeltaCount") 140 DuraSum, ErrDuraSum := map2value.MapToUInt64(d, "connectionSumDurationSeconds") 141 if ErrNumConn == nil && NumConn > 0 { 142 if ErrDuraSum == nil { 143 duration.ConnMean = float32(float64(DuraSum) / float64(NumConn)) 144 duration.ConnTotal = float32(DuraSum) 145 } 146 } 147 148 //Trans duration mean 149 NumTrans, ErrNumTrans := map2value.MapToUInt32(d, "conn_transaction_cnt_complete") 150 TransDuraSum, ErrTransDuraSum := map2value.MapToUInt32(d, "conn_transaction_duration_sum") 151 if (ErrNumTrans == nil) && (ErrTransDuraSum == nil) { 152 if NumTrans > 0 { 153 duration.TransMean = float32(TransDuraSum) / float32(NumTrans) 154 duration.TransTotal = float32(TransDuraSum) 155 } 156 } 157 158 //client 159 NumC, ErrNumC := map2value.MapToUInt32(d, "conn_delay_network_to_client_num_samples") 160 CNetDelaySum, ErrCNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_long_lived_to_client") 161 if (ErrNumC == nil) && (ErrCNetDelaySum == nil) { 162 if NumC > 0 { 163 network.Client = float32(CNetDelaySum) / float32(NumC) 164 } else { 165 network.Client = 0 166 } 167 } 168 169 //server 170 NumS, ErrNumS := map2value.MapToUInt32(d, "conn_delay_network_to_server_num_samples") 171 SNetDelaySum, ErrSNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_long_lived_to_server") 172 if (ErrNumS == nil) && (ErrSNetDelaySum == nil) { 173 if NumS > 0 { 174 network.Server = float32(SNetDelaySum) / float32(NumS) 175 } else { 176 network.Server = 0 177 } 178 } 179 180 //client-to-server 181 NumC2S, ErrNumC2S := map2value.MapToUInt32(d, "conn_delay_network_client_to_server_num_samples") 182 C2SNetDelaySum, ErrC2SNetDelaySum := map2value.MapToUInt32(d, "conn_delay_network_long_lived_client_to_server") 183 if (ErrNumC2S == nil) && (ErrC2SNetDelaySum == nil) { 184 if NumC2S > 0 { 185 network.Total = float32(C2SNetDelaySum) / float32(NumC2S) 186 } 187 } 188 189 //sometime to_client sample counter is zero, need to fix from C2SNetDelay and SNetDelay 190 if network.Client == 0 && network.Server != 0 { 191 delta := network.Total - network.Server 192 if delta > 0 { 193 network.Client = delta 194 } 195 } 196 197 //sometime to_server sample counter is zero, need to fix from C2SNetDelay and CNetDelay 198 if network.Client != 0 && network.Server == 0 { 199 delta := network.Total - network.Client 200 if delta > 0 { 201 network.Server = delta 202 } 203 } 204 return network, duration 205 }