Skip to content
SakibpediaPublic

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

anomalyd

Rust 1.70+ crates.io dependencies: 0 License: MIT

Statistical log anomaly detection in pure Rust, with zero dependencies. Part of the AI Security Lab collection.

anomalyd learns what "normal" looks like in a log file, then flags lines that deviate from that baseline. It extracts six cheap features per line — length, digit ratio, uppercase ratio, symbol ratio, token count and byte entropy — fits a mean and standard deviation, and scores each line by its average absolute z-score.

No crates, no model download, no network. One static binary.

Features

  • Unsupervised — no labels needed; train on the log itself.
  • Explainable-ish — features are named, and the score is a mean z-score you can reason about.
  • Fast — one pass to fit, one pass to score, O(lines × 6).
  • Safe — blank lines are ignored; feature deviations have a floor so constant features cannot explode.
  • CI-ready — JSON output and exit status 1 when anomalies are found.
  • Tested — unit tests in the library plus integration tests for scoring and line numbers.

Install

cargo install --path .

Or:

git clone https://github.com/Sakibpedia/anomalyd.git
cd anomalyd
cargo build --release

Usage

# Detect anomalies in a log file (train on the same file)
anomalyd application.log

# Read from stdin
journalctl -u sshd --no-pager | anomalyd --threshold 3.0

# Top 10 most unusual lines as JSON
anomalyd --json --top 10 auth.log > anomalies.json

Exit status is 1 when at least one anomaly is reported, 0 when clean.

Options

Option Default Meaning
--threshold N 2.5 Score cutoff (higher = stricter)
--top N all Keep only the N highest-scoring lines
--json off Emit JSON objects with line, score, text
--help — Show help

Library

use anomalyd::{AnomalyModel, Detector};

let baseline = ["INFO request ok", "INFO health check ok"];
let model = AnomalyModel::fit(&baseline)?;
let detector = Detector::new(model, 2.5)?;

for anomaly in detector.detect(["INFO request ok", "!!!QQQ999$$$888"]) {
    println!("line {}: {:.2}", anomaly.line, anomaly.score);
}

How scoring works

features(line) -> [f64; 6]
z_i = |feature_i - mean_i| / max(stddev_i, 0.05)
score = mean(z_0 ... z_5)

A score of 2.5 means the line is, on average, 2.5 standard deviations from the baseline across the six features. The 0.05 floor keeps constant features from producing infinite scores.

Limitations

Training on the file you scan means anomalies that dominate the file will raise the baseline and hide themselves. For real deployments, train on a known-clean window and score a different window. This is a triage aid, not a detection guarantee.

Testing

cargo test

The suite covers feature extraction, model fitting, scoring and line numbering.

Project layout

anomalyd/
├── src/features.rs       feature extraction + unit tests
├── src/model.rs          fitting, scoring, detection + unit tests
├── src/main.rs           CLI
└── tests/integration.rs  end-to-end scoring tests

License

MIT © S M Nazmuz Sakib (2026).

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages