1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use crate::act::{Action, ActionResults, Gauge, Severity};
6use crate::metrics::fetch::FileDataFetcher;
7use crate::metrics::metric_value::MetricValue;
89mod crashes;
10mod helpers;
11mod memory;
12mod routing;
13mod sandbox_errors;
1415pub trait Plugin {
16/// Returns a unique name for the plugin.
17 ///
18 /// This is the value selected and listed on the command line.
19fn name(&self) -> &'static str;
2021/// Returns a human-readable name for the plugin.
22 ///
23 /// This will be displayed as the label for results from this plugin.
24fn display_name(&self) -> &'static str;
2526/// Run the plugin on the given inputs to produce results.
27fn run(&self, inputs: &FileDataFetcher<'_>) -> ActionResults {
28let mut results = ActionResults::new();
29 results.sort_gauges = false;
30let structured_results = self.run_structured(inputs);
31for action in structured_results {
32match action {
33 Action::Alert(alert) => match alert.severity {
34 Severity::Info => results.infos.push(alert.print),
35 Severity::Warning => results.warnings.push(alert.print),
36 Severity::Error => results.errors.push(alert.print),
37 },
38 Action::Gauge(Gauge { tag: Some(tag), value, .. }) => {
39if let Some(MetricValue::String(raw_value)) = value.cached_value.into_inner() {
40 results.gauges.push(format!("{}: {}", tag, raw_value));
41 }
42 }
43_ => (),
44 }
45 }
46 results
47 }
4849/// Run the plugin on the given inputs to produce results keyed by name.
50fn run_structured(&self, inputs: &FileDataFetcher<'_>) -> Vec<Action>;
51}
5253/// Retrieve the list of all plugins registered with this library.
54pub fn register_plugins() -> Vec<Box<dyn Plugin>> {
55vec![
56 Box::new(crashes::CrashesPlugin {}),
57 Box::new(sandbox_errors::SandboxErrorsPlugin {}),
58 Box::new(routing::RoutingErrorsPlugin {}),
59 Box::new(memory::MemoryPlugin {}),
60 ]
61}