Skip to main content

Crate mprobe_diagnostics

Crate mprobe_diagnostics 

Source
Expand description

A library for parsing and reading MongoDB diagnostic data, generated by the Full Time Diagnostic Data Capture (FTDC) mechanism.

§Read the diagnostic data

One can read the diagnostic data by constructing an instance of DiagnosticData, and iterate over it to get the diagnostic metrics. The iterator yields one chunk of the diagnostic data at a time. Each chunk contains a list of metrics and metadata associated with it. The metrics are always returned sorted in ascending order.

The following example shows how to read through the diagnostic data and print the metric names on the standard output.

use std::path::Path;
use std::result::Result;

use mprobe_diagnostics::DiagnosticData;
use mprobe_diagnostics::error::MetricParseError;

fn main() -> Result<(), MetricParseError> {
    // Note: this example needs a valid path
    // that contains diagnostic data for it to run
    let path = Path::new("/path/to/diagnostic/data");
    let diagnostic_data = DiagnosticData::new(&path)?;

    for chunk in diagnostic_data {
        for metric in chunk?.metrics {
            println!("{}", metric.name);
        }
    }

    Ok(())
}

§Filter the diagnostic data

Since the DiagnosticData implements IntoIterator, one could use the Iterator::filter combinator to filter the diagnostic data. However that will be applied to all the diagnostic data contained in the provided path, which can contain a lot of data. When one needs only the diagnostic data of a node, process, or the data in a specific time window, one can use the DiagnosticData::filter function and provide an instance of MetricsFilter.

In the example below it is show how one could use it.

use std::path::Path;
use chrono::{DateTime, Duration, TimeDelta, Utc};
use mprobe_diagnostics::{DiagnosticData, MetricsFilter};

let path = Path::new("/path/to/diagnostic/data");

let node = String::from("node-1");
let start = Utc::now() - Duration::hours(1);
let end = Utc::now();

let filter = MetricsFilter::new(Some(node), Some(start), Some(end));
let diagnostic_data = DiagnosticData::filter(&path, filter).expect("valid path");

Modules§

error
Defines the Error types that this crate uses.
metadata
Defines an API for reading the metadata associated with the diagnostic metrics.
metrics
Defines an API for parsing diagnostic metrics.

Structs§

DiagnosticData
DiagnosticData defines an API for parsing and reading MongoDB diagnostic data.
MetricsFilter
MetricsFilter specifies a filter for the diagnostic data.