Apollo 10.0
自动驾驶开放平台
module_monitor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "absl/flags/flag.h"
20
21#include "cyber/common/file.h"
22#include "cyber/common/log.h"
26
27ABSL_FLAG(std::string, module_monitor_name, "ModuleMonitor",
28 "Name of the modules monitor.");
29
30ABSL_FLAG(double, module_monitor_interval, 1.5,
31 "Process status checking interval in seconds.");
32
33namespace apollo {
34namespace monitor {
35
37 : RecurrentRunner(absl::GetFlag(FLAGS_module_monitor_name),
38 absl::GetFlag(FLAGS_module_monitor_interval)) {
39 node_manager_ =
40 cyber::service_discovery::TopologyManager::Instance()->node_manager();
41}
42
43void ModuleMonitor::RunOnce(const double current_time) {
44 auto manager = MonitorManager::Instance();
45 const auto& mode = manager->GetHMIMode();
46
47 // Check monitored components.
48 auto* components = manager->GetStatus()->mutable_components();
49 for (const auto& iter : mode.monitored_components()) {
50 const std::string& name = iter.first;
51 const auto& monitored_component = iter.second;
52 if (monitored_component.has_module() &&
53 apollo::common::util::ContainsKey(*components, name)) {
54 const auto& config = monitored_component.module();
55 auto* status = components->at(name).mutable_module_status();
56 UpdateStatus(config, name, status);
57 }
58 }
59}
60
63 const std::string& module_name, ComponentStatus* status) {
64 status->clear_status();
65
66 bool all_nodes_matched = true;
67 for (const std::string& name : config.node_name()) {
68 if (!node_manager_->HasNode(name)) {
69 all_nodes_matched = false;
70 break;
71 }
72 }
73 if (all_nodes_matched) {
74 // Working nodes are all matched. The module is running.
75 SummaryMonitor::EscalateStatus(ComponentStatus::OK, module_name, status);
76 return;
77 }
78
79 SummaryMonitor::EscalateStatus(ComponentStatus::FATAL, "", status);
80}
81
82} // namespace monitor
83} // namespace apollo
void UpdateStatus(const apollo::dreamview::ModuleMonitorConfig &config, const std::string &module_name, ComponentStatus *status)
void RunOnce(const double current_time) override
static void EscalateStatus(const ComponentStatus::Status new_status, const std::string &message, ComponentStatus *current_status)
Some map util functions.
ABSL_FLAG(std::string, module_monitor_name, "ModuleMonitor", "Name of the modules monitor.")
class register implement
Definition arena_queue.h:37