@@ -3313,6 +3313,162 @@ class SetConfigHandler final : public HttpRequestHandler {
3313
3313
}
3314
3314
};
3315
3315
3316
+ class ShowBufferHandler final : public HttpRequestHandler {
3317
+ public:
3318
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3319
+ auto infinity = Infinity::RemoteConnect ();
3320
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3321
+
3322
+ nlohmann::json json_response;
3323
+ HTTPStatus http_status;
3324
+ QueryResult result = infinity->Query (" show buffer" );
3325
+
3326
+ if (result.IsOk ()) {
3327
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3328
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3329
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3330
+ auto row_count = data_block->row_count ();
3331
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3332
+ for (int row = 0 ; row < row_count; ++row) {
3333
+ nlohmann::json json_table;
3334
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3335
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3336
+ Value value = data_block->GetValue (col, row);
3337
+ const String &column_value = value.ToString ();
3338
+ json_table[column_name] = column_value;
3339
+ }
3340
+ json_response[" buffer" ].push_back (json_table);
3341
+ }
3342
+ }
3343
+ json_response[" error_code" ] = 0 ;
3344
+ http_status = HTTPStatus::CODE_200;
3345
+ } else {
3346
+ json_response[" error_code" ] = result.ErrorCode ();
3347
+ json_response[" error_message" ] = result.ErrorMsg ();
3348
+ http_status = HTTPStatus::CODE_500;
3349
+ }
3350
+
3351
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3352
+ }
3353
+ };
3354
+
3355
+ class ShowProfilesHandler final : public HttpRequestHandler {
3356
+ public:
3357
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3358
+ auto infinity = Infinity::RemoteConnect ();
3359
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3360
+
3361
+ nlohmann::json json_response;
3362
+ HTTPStatus http_status;
3363
+ QueryResult result = infinity->Query (" show profiles" );
3364
+
3365
+ if (result.IsOk ()) {
3366
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3367
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3368
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3369
+ auto row_count = data_block->row_count ();
3370
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3371
+ for (int row = 0 ; row < row_count; ++row) {
3372
+ nlohmann::json json_table;
3373
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3374
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3375
+ Value value = data_block->GetValue (col, row);
3376
+ const String &column_value = value.ToString ();
3377
+ json_table[column_name] = column_value;
3378
+ }
3379
+ json_response[" profiles" ].push_back (json_table);
3380
+ }
3381
+ }
3382
+ json_response[" error_code" ] = 0 ;
3383
+ http_status = HTTPStatus::CODE_200;
3384
+ } else {
3385
+ json_response[" error_code" ] = result.ErrorCode ();
3386
+ json_response[" error_message" ] = result.ErrorMsg ();
3387
+ http_status = HTTPStatus::CODE_500;
3388
+ }
3389
+
3390
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3391
+ }
3392
+ };
3393
+
3394
+ class ShowMemIndexHandler final : public HttpRequestHandler {
3395
+ public:
3396
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3397
+ auto infinity = Infinity::RemoteConnect ();
3398
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3399
+
3400
+ nlohmann::json json_response;
3401
+ HTTPStatus http_status;
3402
+ QueryResult result = infinity->Query (" show memindex" );
3403
+
3404
+ if (result.IsOk ()) {
3405
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3406
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3407
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3408
+ auto row_count = data_block->row_count ();
3409
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3410
+ for (int row = 0 ; row < row_count; ++row) {
3411
+ nlohmann::json json_table;
3412
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3413
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3414
+ Value value = data_block->GetValue (col, row);
3415
+ const String &column_value = value.ToString ();
3416
+ json_table[column_name] = column_value;
3417
+ }
3418
+ json_response[" index" ].push_back (json_table);
3419
+ }
3420
+ }
3421
+ json_response[" error_code" ] = 0 ;
3422
+ http_status = HTTPStatus::CODE_200;
3423
+ } else {
3424
+ json_response[" error_code" ] = result.ErrorCode ();
3425
+ json_response[" error_message" ] = result.ErrorMsg ();
3426
+ http_status = HTTPStatus::CODE_500;
3427
+ }
3428
+
3429
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3430
+ }
3431
+ };
3432
+
3433
+ class ShowQueriesHandler final : public HttpRequestHandler {
3434
+ public:
3435
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3436
+ auto infinity = Infinity::RemoteConnect ();
3437
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3438
+
3439
+ nlohmann::json json_response;
3440
+ HTTPStatus http_status;
3441
+ QueryResult result = infinity->Query (" show queries" );
3442
+
3443
+ if (result.IsOk ()) {
3444
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3445
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3446
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3447
+ auto row_count = data_block->row_count ();
3448
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3449
+ for (int row = 0 ; row < row_count; ++row) {
3450
+ nlohmann::json json_table;
3451
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3452
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3453
+ Value value = data_block->GetValue (col, row);
3454
+ const String &column_value = value.ToString ();
3455
+ json_table[column_name] = column_value;
3456
+ }
3457
+ json_response[" queries" ].push_back (json_table);
3458
+ }
3459
+ }
3460
+ json_response[" error_code" ] = 0 ;
3461
+ http_status = HTTPStatus::CODE_200;
3462
+ } else {
3463
+ json_response[" error_code" ] = result.ErrorCode ();
3464
+ json_response[" error_message" ] = result.ErrorMsg ();
3465
+ http_status = HTTPStatus::CODE_500;
3466
+ }
3467
+
3468
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3469
+ }
3470
+ };
3471
+
3316
3472
class ShowCurrentNodeHandler final : public HttpRequestHandler {
3317
3473
public:
3318
3474
SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
@@ -3449,6 +3605,12 @@ void HTTPServer::Start(const String& ip_address, u16 port) {
3449
3605
3450
3606
router->route (" POST" , " /configs" , MakeShared<SetConfigHandler>());
3451
3607
3608
+ // metrics
3609
+ router->route (" GET" , " /instance/buffer" , MakeShared<ShowBufferHandler>());
3610
+ router->route (" GET" , " /instance/profiles" , MakeShared<ShowProfilesHandler>());
3611
+ router->route (" GET" , " /instance/memindex" , MakeShared<ShowMemIndexHandler>());
3612
+ router->route (" GET" , " /instance/queries" , MakeShared<ShowQueriesHandler>());
3613
+
3452
3614
// variable
3453
3615
router->route (" GET" , " /variables/global" , MakeShared<ShowGlobalVariablesHandler>());
3454
3616
router->route (" GET" , " /variables/global/{variable_name}" , MakeShared<ShowGlobalVariableHandler>());
0 commit comments