[C#/COMMON/NATS] NATS 서버 정보 구하기
■ NATS 서버 정보를 구하는 방법을 보여준다. ▶ varz.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
using System; using System.Collections.Generic; using System.Text; namespace TestProject { /// <summary> /// cluster /// </summary> public class cluster { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 주소 - addr /// <summary> /// 주소 /// </summary> public string addr { get; set; } #endregion #region 클러스터 포트 - cluster_port /// <summary> /// 클러스터 포트 /// </summary> public int cluster_port { get; set; } #endregion #region 인증 타임아웃 - auth_timeout /// <summary> /// 인증 타임아웃 /// </summary> public int auth_timeout { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString(indentCount) /// <summary> /// 문자열 구하기 /// </summary> /// <param name="indentCount">들여쓰기 카운트</param> /// <returns>문자열</returns> public string ToString(int indentCount = 0) { string indentString = " ".GetRepeatString(indentCount); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"{indentString}addr : {addr }"); stringBuilder.AppendLine($"{indentString}cluster_port : {cluster_port}"); stringBuilder.AppendLine($"{indentString}auth_timeout : {auth_timeout}"); return stringBuilder.ToString(); } #endregion } /// <summary> /// varz /// </summary> public class varz { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 서버 ID - server_id /// <summary> /// 서버 ID /// </summary> public string server_id { get; set; } #endregion #region 버전 - version /// <summary> /// 버전 /// </summary> public string version { get; set; } #endregion #region 원형 - proto /// <summary> /// 원형 /// </summary> public int proto { get; set; } #endregion #region GO 언어 버전 - go /// <summary> /// GO 언어 버전 /// </summary> public string go { get; set; } #endregion #region 호스트 - host /// <summary> /// 호스트 /// </summary> public string host { get; set; } #endregion #region 인증 요구 여부 - auth_required /// <summary> /// 인증 요구 여부 /// </summary> public bool auth_required { get; set; } #endregion #region 연결 URL 리스트 - connect_urls /// <summary> /// 연결 URL 리스트 /// </summary> public List<string> connect_urls { get; set; } #endregion #region 주소 - addr /// <summary> /// 주소 /// </summary> public string addr { get; set; } #endregion #region 최대 연결 수 - max_connections /// <summary> /// 최대 연결 수 /// </summary> public int max_connections { get; set; } #endregion #region PING 주기 - ping_interval /// <summary> /// PING 주기 /// </summary> public long ping_interval { get; set; } #endregion #region PING 최대 횟수 - ping_max /// <summary> /// PING 최대 횟수 /// </summary> public int ping_max { get; set; } #endregion #region HTTP 호스트 - http_host /// <summary> /// HTTP 호스트 /// </summary> public string http_host { get; set; } #endregion #region HTTP 포트 - http_port /// <summary> /// HTTP 포트 /// </summary> public int http_port { get; set; } #endregion #region HTTPS 포트 - https_port /// <summary> /// HTTPS 포트 /// </summary> public int https_port { get; set; } #endregion #region 인증 타임아웃 - auth_timeout /// <summary> /// 인증 타임아웃 /// </summary> public int auth_timeout { get; set; } #endregion #region 최대 컨트롤 라인 - max_control_line /// <summary> /// 최대 컨트롤 라인 /// </summary> public int max_control_line { get; set; } #endregion #region 클러스터 - cluster /// <summary> /// 클러스터 /// </summary> public cluster cluster { get; set; } #endregion #region TLS 타임아웃 - tls_timeout /// <summary> /// TLS 타임아웃 /// </summary> public double tls_timeout { get; set; } #endregion #region 포트 - port /// <summary> /// 포트 /// </summary> public int port { get; set; } #endregion #region 최대 페이로드 - max_payload /// <summary> /// 최대 페이로드 /// </summary> public int max_payload { get; set; } #endregion #region 시작 시간 - start /// <summary> /// 시작 시간 /// </summary> public DateTime start { get; set; } #endregion #region 현재 시간 - now /// <summary> /// 현재 시간 /// </summary> public DateTime now { get; set; } #endregion #region UP 시간 - uptime /// <summary> /// UP 시간 /// </summary> public string uptime { get; set; } #endregion #region 메모리 - mem /// <summary> /// 메모리 /// </summary> public long mem { get; set; } #endregion #region 코어 수 - cores /// <summary> /// 코어 수 /// </summary> public int cores { get; set; } #endregion #region CPU - cpu /// <summary> /// CPU /// </summary> public double cpu { get; set; } #endregion #region 연결 수 - connections /// <summary> /// 연결 수 /// </summary> public int connections { get; set; } #endregion #region 총 연결 수 - total_connections /// <summary> /// 총 연결 수 /// </summary> public int total_connections { get; set; } #endregion #region 라우팅 수 - routes /// <summary> /// 라우팅 수 /// </summary> public int routes { get; set; } #endregion #region 원격지 수 - remotes /// <summary> /// 원격지 수 /// </summary> public int remotes { get; set; } #endregion #region 입력 메시지 수 - in_msgs /// <summary> /// 입력 메시지 수 /// </summary> public long in_msgs { get; set; } #endregion #region 출력 메시지 수 - out_msgs /// <summary> /// 출력 메시지 수 /// </summary> public long out_msgs { get; set; } #endregion #region 입력 바이트 수 - in_bytes /// <summary> /// 입력 바이트 수 /// </summary> public long in_bytes { get; set; } #endregion #region 출력 바이트 수 - out_bytes /// <summary> /// 출력 바이트 수 /// </summary> public long out_bytes { get; set; } #endregion #region SLOW 소비자 수 - slow_consumers /// <summary> /// SLOW 소비자 수 /// </summary> public int slow_consumers { get; set; } #endregion #region 최대 보류 수 - max_pending /// <summary> /// 최대 보류 수 /// </summary> public long max_pending { get; set; } #endregion #region 쓰기 데드라인 - write_deadline /// <summary> /// 쓰기 데드라인 /// </summary> public long write_deadline { get; set; } #endregion #region 구독 수 - subscriptions /// <summary> /// 구독 수 /// </summary> public int subscriptions { get; set; } #endregion #region HTTP 요청 상태 딕셔너리 - http_req_stats /// <summary> /// HTTP 요청 상태 딕셔너리 /// </summary> public Dictionary<string, long> http_req_stats { get; set; } #endregion #region 구성 로드 시간 - config_load_time /// <summary> /// 구성 로드 시간 /// </summary> public DateTime config_load_time { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"server_id : {server_id }"); stringBuilder.AppendLine($"version : {version }"); stringBuilder.AppendLine($"proto : {proto }"); stringBuilder.AppendLine($"go : {go }"); stringBuilder.AppendLine($"host : {host }"); stringBuilder.AppendLine($"auth_required : {auth_required }"); stringBuilder.AppendLine($"connect_urls"); stringBuilder.AppendLine($"--------------------------------------------------"); if(connect_urls != null && connect_urls.Count > 0) { foreach(string connect_url in connect_urls) { stringBuilder.AppendLine($" {connect_url}"); } } stringBuilder.AppendLine($"--------------------------------------------------"); stringBuilder.AppendLine($"addr : {addr }"); stringBuilder.AppendLine($"max_connections : {max_connections }"); stringBuilder.AppendLine($"ping_interval : {ping_interval }"); stringBuilder.AppendLine($"ping_max : {ping_max }"); stringBuilder.AppendLine($"http_host : {http_host }"); stringBuilder.AppendLine($"http_port : {http_port }"); stringBuilder.AppendLine($"https_port : {https_port }"); stringBuilder.AppendLine($"auth_timeout : {auth_timeout }"); stringBuilder.AppendLine($"max_control_line : {max_control_line }"); stringBuilder.AppendLine($"cluster : {cluster }"); stringBuilder.AppendLine($"--------------------------------------------------"); stringBuilder.AppendLine($"{cluster.ToString(4)}"); stringBuilder.AppendLine($"--------------------------------------------------"); stringBuilder.AppendLine($"tls_timeout : {tls_timeout }"); stringBuilder.AppendLine($"port : {port }"); stringBuilder.AppendLine($"max_payload : {max_payload }"); stringBuilder.AppendLine($"start : {start }"); stringBuilder.AppendLine($"now : {now }"); stringBuilder.AppendLine($"uptime : {uptime }"); stringBuilder.AppendLine($"mem : {mem }"); stringBuilder.AppendLine($"cores : {cores }"); stringBuilder.AppendLine($"cpu : {cpu }"); stringBuilder.AppendLine($"connections : {connections }"); stringBuilder.AppendLine($"total_connections : {total_connections}"); stringBuilder.AppendLine($"routes : {routes }"); stringBuilder.AppendLine($"remotes : {remotes }"); stringBuilder.AppendLine($"in_msgs : {in_msgs }"); stringBuilder.AppendLine($"out_msgs : {out_msgs }"); stringBuilder.AppendLine($"in_bytes : {in_bytes }"); stringBuilder.AppendLine($"out_bytes : {out_bytes }"); stringBuilder.AppendLine($"slow_consumers : {slow_consumers }"); stringBuilder.AppendLine($"max_pending : {max_pending }"); stringBuilder.AppendLine($"write_deadline : {write_deadline }"); stringBuilder.AppendLine($"subscriptions : {subscriptions }"); stringBuilder.AppendLine($"http_req_stats"); stringBuilder.AppendLine($"--------------------------------------------------"); if(http_req_stats != null && http_req_stats.Count > 0) { int maximumKeyLength = 0; foreach(KeyValuePair<string, long> keyValuePair in http_req_stats) { if(keyValuePair.Key.Length > maximumKeyLength) { maximumKeyLength = keyValuePair.Key.Length; } } foreach(KeyValuePair<string, long> keyValuePair in http_req_stats) { string key = $"{keyValuePair.Key}{" ".GetRepeatString(maximumKeyLength - keyValuePair.Key.Length)}"; stringBuilder.AppendLine($" {key} : {keyValuePair.Value}"); } } stringBuilder.AppendLine($"--------------------------------------------------"); stringBuilder.AppendLine($"config_load_time : {config_load_time }"); return stringBuilder.ToString(); } #endregion } } |
▶ connz.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
using System; using System.Collections.Generic; using System.Text; namespace TestProject { /// <summary> /// connection /// </summary> public class connection { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 연결 ID - cid /// <summary> /// 연결 ID /// </summary> public long cid { get; set; } #endregion #region IP 주소 - ip /// <summary> /// IP 주소 /// </summary> public string ip { get; set; } #endregion #region 포트 - port /// <summary> /// 포트 /// </summary> public int port { get; set; } #endregion #region 시작 시간 - start /// <summary> /// 시작 시간 /// </summary> public DateTime start { get; set; } #endregion #region 마지막 활동 시간 - last_activity /// <summary> /// 마지막 활동 시간 /// </summary> public DateTime last_activity { get; set; } #endregion #region RTT - rtt /// <summary> /// RTT /// </summary> public string rtt { get; set; } #endregion #region UP 시간 - uptime /// <summary> /// UP 시간 /// </summary> public string uptime { get; set; } #endregion #region 보류 바이트 수 - pending_bytes /// <summary> /// 보류 바이트 수 /// </summary> public long pending_bytes { get; set; } #endregion #region 입력 메시지 수 - in_msgs /// <summary> /// 입력 메시지 수 /// </summary> public long in_msgs { get; set; } #endregion #region 출력 메시지 수 - out_msgs /// <summary> /// 출력 메시지 수 /// </summary> public long out_msgs { get; set; } #endregion #region 입력 바이트 수 - in_bytes /// <summary> /// 입력 바이트 수 /// </summary> public long in_bytes { get; set; } #endregion #region 출력 바이트 수 - out_bytes /// <summary> /// 출력 바이트 수 /// </summary> public long out_bytes { get; set; } #endregion #region 구독 수 - subscriptions /// <summary> /// 구독 수 /// </summary> public long subscriptions { get; set; } #endregion #region 프로그래밍 언어 - lang /// <summary> /// 프로그래밍 언어 /// </summary> public string lang { get; set; } #endregion #region 버전 - version /// <summary> /// 버전 /// </summary> public string version { get; set; } #endregion #region 구독 리스트 - subscriptions_list /// <summary> /// 구독 리스트 /// </summary> public List<string> subscriptions_list { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString(indentCount) /// <summary> /// 문자열 구하기 /// </summary> /// <param name="indentCount">들여쓰기 카운트</param> /// <returns>문자열</returns> public string ToString(int indentCount = 0) { string indentString = " ".GetRepeatString(indentCount); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"{indentString}cid : {cid }"); stringBuilder.AppendLine($"{indentString}ip : {ip }"); stringBuilder.AppendLine($"{indentString}port : {port }"); stringBuilder.AppendLine($"{indentString}start : {start }"); stringBuilder.AppendLine($"{indentString}last_activity : {last_activity}"); stringBuilder.AppendLine($"{indentString}rtt : {rtt }"); stringBuilder.AppendLine($"{indentString}uptime : {uptime }"); stringBuilder.AppendLine($"{indentString}pending_bytes : {pending_bytes}"); stringBuilder.AppendLine($"{indentString}in_msgs : {in_msgs }"); stringBuilder.AppendLine($"{indentString}out_msgs : {out_msgs }"); stringBuilder.AppendLine($"{indentString}in_bytes : {in_bytes }"); stringBuilder.AppendLine($"{indentString}out_bytes : {out_bytes }"); stringBuilder.AppendLine($"{indentString}subscriptions : {subscriptions}"); stringBuilder.AppendLine($"{indentString}lang : {lang }"); stringBuilder.AppendLine($"{indentString}version : {version }"); if(subscriptions_list != null && subscriptions_list.Count > 0) { stringBuilder.AppendLine($"{indentString}subscriptions_list"); stringBuilder.AppendLine($"{indentString}--------------------------------------------------"); for(int i = 0; i < subscriptions_list.Count; i++) { stringBuilder.AppendLine($"{indentString} {subscriptions_list[i]}"); } stringBuilder.AppendLine($"{indentString}--------------------------------------------------"); } return stringBuilder.ToString(); } #endregion } /// <summary> /// connz /// </summary> public class connz { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 서버 ID - server_id /// <summary> /// 서버 ID /// </summary> public string server_id { get; set; } #endregion #region 현재 시간 - now /// <summary> /// 현재 시간 /// </summary> public DateTime now { get; set; } #endregion #region 연결 수 - num_connections /// <summary> /// 연결 수 /// </summary> public long num_connections { get; set; } #endregion #region 전체 수 - total /// <summary> /// 전체 수 /// </summary> public long total { get; set; } #endregion #region 오프셋 - offset /// <summary> /// 오프셋 /// </summary> public long offset { get; set; } #endregion #region 제한 - limit /// <summary> /// 제한 /// </summary> public long limit { get; set; } #endregion #region 연결 리스트 - connections /// <summary> /// 연결 리스트 /// </summary> public List<connection> connections { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"server_id : {server_id }"); stringBuilder.AppendLine($"now : {now }"); stringBuilder.AppendLine($"num_connections : {num_connections}"); stringBuilder.AppendLine($"total : {total }"); stringBuilder.AppendLine($"offset : {offset }"); stringBuilder.AppendLine($"limit : {limit }"); if(connections != null && connections.Count > 0) { stringBuilder.AppendLine($"connections"); stringBuilder.AppendLine($"--------------------------------------------------"); for(int i = 0; i < connections.Count; i++) { connection connection = connections[i]; if(i > 0) { stringBuilder.AppendLine(); } stringBuilder.AppendLine(connection.ToString(4)); } stringBuilder.AppendLine($"--------------------------------------------------"); } return stringBuilder.ToString(); } #endregion } } |
▶ routez.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
using System; using System.Collections.Generic; using System.Text; namespace TestProject { /// <summary> /// route /// </summary> public class route { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 라우팅 ID - rid /// <summary> /// 라우팅 ID /// </summary> public int rid { get; set; } #endregion #region 원격 ID - remote_id /// <summary> /// 원격 ID /// </summary> public string remote_id { get; set; } #endregion #region DID SOLICIT - did_solicit /// <summary> /// DID SOLICIT /// </summary> public bool did_solicit { get; set; } #endregion #region 구성 여부 - is_configured /// <summary> /// 구성 여부 /// </summary> public bool is_configured { get; set; } #endregion #region IP 주소 - ip /// <summary> /// IP 주소 /// </summary> public string ip { get; set; } #endregion #region 포트 - port /// <summary> /// 포트 /// </summary> public int port { get; set; } #endregion #region 보류 크기 - pending_size /// <summary> /// 보류 크기 /// </summary> public long pending_size { get; set; } #endregion #region 입력 메시지 수 - in_msgs /// <summary> /// 입력 메시지 수 /// </summary> public long in_msgs { get; set; } #endregion #region 출력 메시지 수 - out_msgs /// <summary> /// 출력 메시지 수 /// </summary> public long out_msgs { get; set; } #endregion #region 입력 바이트 수 - in_bytes /// <summary> /// 입력 바이트 수 /// </summary> public long in_bytes { get; set; } #endregion #region 출력 바이트 수 - out_bytes /// <summary> /// 출력 바이트 수 /// </summary> public long out_bytes { get; set; } #endregion #region 구독 수 - subscriptions /// <summary> /// 구독 수 /// </summary> public int subscriptions { get; set; } #endregion #region 구독 리스트 - subscriptions_list /// <summary> /// 구독 리스트 /// </summary> public List<string> subscriptions_list { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString(indentCount) /// <summary> /// 문자열 구하기 /// </summary> /// <param name="indentCount">들여쓰기 카운트</param> /// <returns>문자열</returns> public string ToString(int indentCount = 0) { string indentString = " ".GetRepeatString(indentCount); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"{indentString}rid : {rid }"); stringBuilder.AppendLine($"{indentString}remote_id : {remote_id }"); stringBuilder.AppendLine($"{indentString}did_solicit : {did_solicit }"); stringBuilder.AppendLine($"{indentString}is_configured : {is_configured}"); stringBuilder.AppendLine($"{indentString}ip : {ip }"); stringBuilder.AppendLine($"{indentString}port : {port }"); stringBuilder.AppendLine($"{indentString}pending_size : {pending_size }"); stringBuilder.AppendLine($"{indentString}in_msgs : {in_msgs }"); stringBuilder.AppendLine($"{indentString}out_msgs : {out_msgs }"); stringBuilder.AppendLine($"{indentString}in_bytes : {in_bytes }"); stringBuilder.AppendLine($"{indentString}out_bytes : {out_bytes }"); stringBuilder.AppendLine($"{indentString}subscriptions : {subscriptions}"); stringBuilder.AppendLine($"{indentString}subscriptions_list"); stringBuilder.AppendLine($"{indentString}--------------------------------------------------"); if(subscriptions_list != null && subscriptions_list.Count > 0) { foreach(string subscription in subscriptions_list) { stringBuilder.AppendLine($"{indentString} {subscription}"); } } stringBuilder.AppendLine($"{indentString}--------------------------------------------------"); return stringBuilder.ToString(); } #endregion } /// <summary> /// routez /// </summary> public class routez { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 서버 ID - server_id /// <summary> /// 서버 ID /// </summary> public string server_id { get; set; } #endregion #region 현재 시간 - now /// <summary> /// 현재 시간 /// </summary> public DateTime now { get; set; } #endregion #region 라우팅 리스트 - routes /// <summary> /// 라우팅 리스트 /// </summary> public List<route> routes { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"server_id : {server_id }"); stringBuilder.AppendLine($"now : {now }"); stringBuilder.AppendLine($"routes"); stringBuilder.AppendLine($"--------------------------------------------------"); if(routes != null && routes.Count > 0) { foreach(route route in routes) { stringBuilder.AppendLine(route.ToString(4)); } } stringBuilder.AppendLine($"--------------------------------------------------"); return stringBuilder.ToString(); } #endregion } } |
▶ subsz.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
using System.Collections.Generic; using System.Text; namespace TestProject { /// <summary> /// subscription /// </summary> public class subscription { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 서브젝트 - subject /// <summary> /// 서브젝트 /// </summary> public string subject { get; set; } #endregion #region 서브젝트 ID - sid /// <summary> /// 서브젝트 ID /// </summary> public int sid { get; set; } #endregion #region 메시지 수 - msgs /// <summary> /// 메시지 수 /// </summary> public long msgs { get; set; } #endregion #region 클러스터 ID - cid /// <summary> /// 클러스터 ID /// </summary> public int cid { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString(indentCount) /// <summary> /// 문자열 구하기 /// </summary> /// <param name="indentCount">들여쓰기 카운트</param> /// <returns>문자열</returns> public string ToString(int indentCount = 0) { string indentString = " ".GetRepeatString(indentCount); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"{indentString}subject : {subject}"); stringBuilder.AppendLine($"{indentString}sid : {sid }"); stringBuilder.AppendLine($"{indentString}msgs : {msgs }"); stringBuilder.AppendLine($"{indentString}cid : {cid }"); return stringBuilder.ToString(); } #endregion } /// <summary> /// subsz /// </summary> public class subsz { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 구독 수 - num_subscriptions /// <summary> /// 구독 수 /// </summary> public long num_subscriptions { get; set; } #endregion #region 캐시 수 - num_cache /// <summary> /// 캐시 수 /// </summary> public long num_cache { get; set; } #endregion #region 삽입 수 - num_inserts /// <summary> /// 삽입 수 /// </summary> public long num_inserts { get; set; } #endregion #region 제거 수 - num_removes /// <summary> /// 제거 수 /// </summary> public long num_removes { get; set; } #endregion #region 매칭 수 - num_matches /// <summary> /// 매칭 수 /// </summary> public long num_matches { get; set; } #endregion #region 캐시 히트 비율 - cache_hit_rate /// <summary> /// 캐시 히트 비율 /// </summary> public double cache_hit_rate { get; set; } #endregion #region 최대 FANOUT - max_fanout /// <summary> /// 최대 FANOUT /// </summary> public double max_fanout { get; set; } #endregion #region 평균 FANOUT - avg_fanout /// <summary> /// 평균 FANOUT /// </summary> public double avg_fanout { get; set; } #endregion #region 전체 수 - total /// <summary> /// 전체 수 /// </summary> public long total { get; set; } #endregion #region 오프셋 - offset /// <summary> /// 오프셋 /// </summary> public long offset { get; set; } #endregion #region 제한 수 - limit /// <summary> /// 제한 수 /// </summary> public long limit { get; set; } #endregion #region 구독 리스트 - subscriptions_list /// <summary> /// 구독 리스트 /// </summary> public List<subscription> subscriptions_list { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"num_subscriptions : {num_subscriptions}"); stringBuilder.AppendLine($"num_cache : {num_cache }"); stringBuilder.AppendLine($"num_inserts : {num_inserts }"); stringBuilder.AppendLine($"num_removes : {num_removes }"); stringBuilder.AppendLine($"num_matches : {num_matches }"); stringBuilder.AppendLine($"cache_hit_rate : {cache_hit_rate }"); stringBuilder.AppendLine($"max_fanout : {max_fanout }"); stringBuilder.AppendLine($"avg_fanout : {avg_fanout }"); stringBuilder.AppendLine($"total : {total }"); stringBuilder.AppendLine($"offset : {offset }"); stringBuilder.AppendLine($"limit : {limit }"); if(subscriptions_list != null && subscriptions_list.Count > 0) { stringBuilder.AppendLine($"subscriptions_list"); stringBuilder.AppendLine($"--------------------------------------------------"); for(int i = 0; i < subscriptions_list.Count; i++) { subscription subscription = subscriptions_list[i]; if(i > 0) { stringBuilder.AppendLine(); } stringBuilder.AppendLine(subscription.ToString(4)); } stringBuilder.AppendLine($"--------------------------------------------------"); } return stringBuilder.ToString(); } #endregion } } |
▶ NATSHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
using System.Collections.Generic; using System.Text; using Newtonsoft.Json; namespace TestProject { /// <summary> /// NATS 헬퍼 /// </summary> public static class NATSHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 서버 정보 구하기 - GetVARZ(serverAddress, serverPort) /// <summary> /// 서버 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <returns>서버 정보</returns> public static varz GetVARZ(string serverAddress, int serverPort) { string url = $"http://{serverAddress}:{serverPort}/varz"; string contentType = "application/json; charset=utf8"; Encoding encoding = Encoding.UTF8; string argument = string.Empty; string json = HTTPHelper.GetStringPOSTRequest(url, contentType, encoding, argument); varz varz = JsonConvert.DeserializeObject<varz>(json); return varz; } #endregion #region 연결 정보 구하기 - GetCONNZ(serverAddress, serverPort, limit, offset, includeSubscriptionList) /// <summary> /// 연결 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <param name="itemLimitCount">항목 제한 수</param> /// <param name="itemOffset">항목 오프셋</param> /// <param name="includeSubscriptionList">구독 리스트 포함 여부</param> /// <returns>연결 정보</returns> public static connz GetCONNZ(string serverAddress, int serverPort, int itemLimitCount, int itemOffset, bool includeSubscriptionList = true) { string url = $"http://{serverAddress}:{serverPort}/connz?limit={itemLimitCount}&offset={itemOffset}" + (includeSubscriptionList ? "&subs=1" : string.Empty); string contentType = "application/json; charset=utf8"; Encoding encoding = Encoding.UTF8; string argument = string.Empty; string json = HTTPHelper.GetStringPOSTRequest(url, contentType, encoding, argument); connz connz = JsonConvert.DeserializeObject<connz>(json); return connz; } #endregion #region 연결 정보 구하기 - GetCONNZ(serverAddress, serverPort) /// <summary> /// 연결 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <returns>연결 정보</returns> public static connz GetCONNZ(string serverAddress, int serverPort) { int limit = 1024; int current = 0; connz resultCONNZ = new connz(); resultCONNZ.connections = new List<connection>(); while(true) { connz connz = NATSHelper.GetCONNZ(serverAddress, serverPort, limit, current, true); resultCONNZ.server_id = connz.server_id; resultCONNZ.now = connz.now; resultCONNZ.num_connections += connz.num_connections; resultCONNZ.total = connz.total; resultCONNZ.offset = connz.offset; resultCONNZ.limit = connz.limit; foreach(connection connection in connz.connections) { resultCONNZ.connections.Add(connection); } current += limit; if(current >= connz.total) { break; } } return resultCONNZ; } #endregion #region 라우팅 정보 구하기 - GetROUTEZ(serverAddress, serverPort, includeSubscriptionList) /// <summary> /// 라우팅 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <param name="includeSubscriptionList">구독 리스트 포함 여부</param> /// <returns>라우팅 정보</returns> public static routez GetROUTEZ(string serverAddress, int serverPort, bool includeSubscriptionList = true) { string url = $"http://{serverAddress}:{serverPort}/routez" + (includeSubscriptionList ? "?subs=1" : string.Empty); string contentType = "application/json; charset=utf8"; Encoding encoding = Encoding.UTF8; string argument = string.Empty; string json = HTTPHelper.GetStringPOSTRequest(url, contentType, encoding, argument); routez routez = JsonConvert.DeserializeObject<routez>(json); return routez; } #endregion #region 구독 정보 구하기 - GetSUBSZ(serverAddress, serverPort, limit, offset, includeSubscriptionList) /// <summary> /// 구독 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <param name="itemLimitCount">항목 제한 수</param> /// <param name="itemOffset">항목 오프셋</param> /// <param name="includeSubscriptionList">구독 리스트 포함 여부</param> /// <returns>구독 정보</returns> public static subsz GetSUBSZ(string serverAddress, int serverPort, int itemLimitCount, int itemOffset, bool includeSubscriptionList = true) { string url = $"http://{serverAddress}:{serverPort}/subsz?limit={itemLimitCount}&offset={itemOffset}" + (includeSubscriptionList ? "&subs=1" : string.Empty); string contentType = "application/json; charset=utf8"; Encoding encoding = Encoding.UTF8; string argument = string.Empty; string json = HTTPHelper.GetStringPOSTRequest(url, contentType, encoding, argument); subsz subsz = JsonConvert.DeserializeObject<subsz>(json); return subsz; } #endregion #region 구독 정보 구하기 - GetSUBSZ(serverAddress, serverPort) /// <summary> /// 구독 정보 구하기 /// </summary> /// <param name="serverAddress">서버 주소</param> /// <param name="serverPort">서버 포트</param> /// <returns>구독 정보</returns> public static subsz GetSUBSZ(string serverAddress, int serverPort) { int limit = 1024; int current = 0; subsz resultSUBSZ = new subsz(); resultSUBSZ.subscriptions_list = new List<subscription>(); while(true) { subsz subsz = NATSHelper.GetSUBSZ("127.0.0.1", 20030, limit, current); resultSUBSZ.num_subscriptions = subsz.num_subscriptions; resultSUBSZ.num_cache = subsz.num_cache; resultSUBSZ.num_inserts = subsz.num_inserts; resultSUBSZ.num_removes = subsz.num_removes; resultSUBSZ.num_matches = subsz.num_matches; resultSUBSZ.cache_hit_rate = subsz.cache_hit_rate; resultSUBSZ.max_fanout = subsz.max_fanout; resultSUBSZ.avg_fanout = subsz.avg_fanout; resultSUBSZ.total += subsz.total; resultSUBSZ.offset = subsz.offset; resultSUBSZ.limit = subsz.limit; foreach(subscription subscription in subsz.subscriptions_list) { resultSUBSZ.subscriptions_list.Add(subscription); } if(subsz.total < limit) { break; } current += limit; } return resultSUBSZ; } #endregion } } |