Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Exports stats #57

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/base_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ where
take_until(period())
}

pub(crate) fn till_equals<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
take_until(equals())
}

pub(crate) fn string_to<I>(x: &'static str, y: &'static str) -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
Expand Down Expand Up @@ -120,6 +112,16 @@ where
.message("while getting param")
}

pub(crate) fn param_period<I>(x: &'static str) -> impl Parser<I, Output = Param>
RDruon marked this conversation as resolved.
Show resolved Hide resolved
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
attempt(string(x).skip(token('.')))
.map(|x| Param(x.to_string()))
.message("while getting param")
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -131,4 +133,14 @@ mod tests {

assert_eq!(result, Ok((Param("memused".to_string()), "77991501\n")))
}

#[test]
fn test_param_period() {
let result = param_period("exports").parse("exports.1.2.3.130@o2ib.stats=Y\n");

assert_eq!(
result,
Ok((Param("exports".to_string()), "1.2.3.130@o2ib.stats=Y\n"))
)
}
}
56 changes: 56 additions & 0 deletions src/exports_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2023 DDN. All rights reserved.
jgrund marked this conversation as resolved.
Show resolved Hide resolved
jgrund marked this conversation as resolved.
Show resolved Hide resolved
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{
base_parsers::{equals, period},
stats_parser::stats,
ExportStats,
};
use combine::{
attempt,
error::ParseError,
many, many1,
parser::char::{alpha_num, string},
stream::Stream,
token, Parser,
};

/// Parses a single nid
pub(crate) fn nid<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
many1::<String, _, _>(alpha_num().or(period())),
token('@'),
many1::<String, _, _>(alpha_num()),
)
.map(|(ip, _, lnet)| format!("{ip}@{lnet}"))
.message("while parsing nid")
}

/// Parses a single obdfilter.*OST*.exports.*.stats line
fn exports_stat<I>() -> impl Parser<I, Output = ExportStats>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
attempt((
nid().skip(period()),
string("stats").skip(equals()),
stats(),
))
.map(|(nid, _, stats)| ExportStats { nid, stats })
.message("while parsing export_stats")
}

/// Parses multiple obdfilter.*OST*.exports.*.stats lines
pub(crate) fn exports_stats<I>() -> impl Parser<I, Output = Vec<ExportStats>>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(many(exports_stat())).map(|x| x)
}
Loading
Loading