Apollo application and source code analysis: Monitor monitoring-software monitoring-module survival monitoring

Table of contents

code entry

analyze


code entry

class ModuleMonitor : public RecurrentRunner {
 public:
  using NodeManagerPtr = std::shared_ptr<cyber::service_discovery::NodeManager>;
  ModuleMonitor();
  void RunOnce(const double current_time) override;
  void UpdateStatus(const apollo::dreamview::ModuleMonitorConfig& config,
                    const std::string& module_name, ComponentStatus* status);

 private:
  NodeManagerPtr node_manager_ = nullptr;
};

void ModuleMonitor::RunOnce(const double current_time) {
  auto manager = MonitorManager::Instance();
  const auto& mode = manager->GetHMIMode();

  // Check monitored components.
  auto* components = manager->GetStatus()->mutable_components();
  for (const auto& iter : mode.monitored_components()) {
    const std::string& name = iter.first;
    const auto& monitored_component = iter.second;
    if (monitored_component.has_module() &&
        apollo::common::util::ContainsKey(*components, name)) {
      const auto& config = monitored_component.module();
      auto* status = components->at(name).mutable_module_status();
      UpdateStatus(config, name, status);
    }
  }
}

analyze

There is a management class in the module survival detection: node_manager

 node_manager_ =
      cyber::service_discovery::TopologyManager::Instance()->node_manager();

The relationships of simple elements in the network - nodes, channels, services, writers, readers, clients, and servers - are represented by topology. You can imagine a directed graph - nodes are containers of servers/clients/writers/readers, they are the vertices of the graph, channels are the edges that flow from writers to readers, services are flows from servers to the edge of the client. To generate this graph, we use TopologyManager, which has three sub-managers - NodeManager: You can find nodes in this topology ChannelManager: You can find channels, their Writers and Readers in this topology: ServiceManager: You can find them in this topology Services are found in , and their Servers and Clients TopologyManager communicate using fast-rtps' Participant. It can broadcast join or leave messages for these elements. Additionally, you can register your own ' ChangeFunc ' to monitor topology changes.

It can be said that this node_manger contains all the node modules of apollo.

The actual checking logic is relatively simple:

  1. Get all nodes to be monitored;
  2. Status judgment in UpdateStatus
void ModuleMonitor::UpdateStatus(
    const apollo::dreamview::ModuleMonitorConfig& config,
    const std::string& module_name, ComponentStatus* status) {
  status->clear_status();

  bool all_nodes_matched = true;
  for (const std::string& name : config.node_name()) {
    if (!node_manager_->HasNode(name)) {
      all_nodes_matched = false;
      break;
    }
  }
  if (all_nodes_matched) {
    // Working nodes are all matched. The module is running.
    SummaryMonitor::EscalateStatus(ComponentStatus::OK, module_name, status);
    return;
  }

  SummaryMonitor::EscalateStatus(ComponentStatus::FATAL, "", status);
}

The status judgment here is to judge whether the node_manger contains the checked node

 

Guess you like

Origin blog.csdn.net/qq_32378713/article/details/128095018