void Stats::CrowRoute()

in platform/statistic/stats.cpp [123:219]


void Stats::CrowRoute() {
  crow::SimpleApp app;
  while (!stop_) {
    try {
      CROW_ROUTE(app, "/consensus_data")
          .methods("GET"_method)([this](const crow::request& req,
                                        crow::response& res) {
            LOG(ERROR) << "API 1";
            res.set_header("Access-Control-Allow-Origin",
                           "*");  // Allow requests from any origin
            res.set_header("Access-Control-Allow-Methods",
                           "GET, POST, OPTIONS");  // Specify allowed methods
            res.set_header(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");  // Specify allowed headers

            // Send your response
            res.body = consensus_history_.dump();
            res.end();
          });
      CROW_ROUTE(app, "/get_status")
          .methods("GET"_method)([this](const crow::request& req,
                                        crow::response& res) {
            LOG(ERROR) << "API 2";
            res.set_header("Access-Control-Allow-Origin",
                           "*");  // Allow requests from any origin
            res.set_header("Access-Control-Allow-Methods",
                           "GET, POST, OPTIONS");  // Specify allowed methods
            res.set_header(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");  // Specify allowed headers

            // Send your response
            res.body = IsFaulty() ? "Faulty" : "Not Faulty";
            res.end();
          });
      CROW_ROUTE(app, "/make_faulty")
          .methods("GET"_method)([this](const crow::request& req,
                                        crow::response& res) {
            LOG(ERROR) << "API 3";
            res.set_header("Access-Control-Allow-Origin",
                           "*");  // Allow requests from any origin
            res.set_header("Access-Control-Allow-Methods",
                           "GET, POST, OPTIONS");  // Specify allowed methods
            res.set_header(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");  // Specify allowed headers

            // Send your response
            if (enable_faulty_switch_) {
              make_faulty_.store(!make_faulty_.load());
            }
            res.body = "Success";
            res.end();
          });
      CROW_ROUTE(app, "/transaction_data")
          .methods("GET"_method)([this](const crow::request& req,
                                        crow::response& res) {
            LOG(ERROR) << "API 4";
            res.set_header("Access-Control-Allow-Origin",
                           "*");  // Allow requests from any origin
            res.set_header("Access-Control-Allow-Methods",
                           "GET, POST, OPTIONS");  // Specify allowed methods
            res.set_header(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");  // Specify allowed headers

            nlohmann::json mem_view_json;
            int status =
                getrusage(RUSAGE_SELF, &transaction_summary_.process_stats_);
            if (status == 0) {
              mem_view_json["resident_set_size"] = GetRSS();
              mem_view_json["max_resident_set_size"] =
                  transaction_summary_.process_stats_.ru_maxrss;
              mem_view_json["num_reads"] =
                  transaction_summary_.process_stats_.ru_inblock;
              mem_view_json["num_writes"] =
                  transaction_summary_.process_stats_.ru_oublock;
            }

            mem_view_json["ext_cache_hit_ratio"] =
                transaction_summary_.ext_cache_hit_ratio_;
            mem_view_json["level_db_stats"] =
                transaction_summary_.level_db_stats_;
            mem_view_json["level_db_approx_mem_size"] =
                transaction_summary_.level_db_approx_mem_size_;
            res.body = mem_view_json.dump();
            mem_view_json.clear();
            res.end();
          });
      app.port(8500 + transaction_summary_.port).multithreaded().run();
      sleep(1);
    } catch (const std::exception& e) {
    }
  }
  app.stop();
}