Struct goose::metrics::GooseMetrics[][src]

pub struct GooseMetrics {
    pub hash: u64,
    pub starting: Option<DateTime<Local>>,
    pub started: Option<DateTime<Local>>,
    pub stopping: Option<DateTime<Local>>,
    pub stopped: Option<DateTime<Local>>,
    pub duration: usize,
    pub users: usize,
    pub requests: GooseRequestMetrics,
    pub tasks: GooseTaskMetrics,
    pub errors: GooseErrorMetrics,
    pub hosts: HashSet<String>,
    // some fields omitted
}
Expand description

All metrics optionally collected during a Goose load test.

By default, Goose collects metrics during a load test in a GooseMetrics object that is returned by GooseAttack::execute() when a load test finishes.

Example

use goose::prelude::*;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    let goose_metrics: GooseMetrics = GooseAttack::initialize()?
        .register_taskset(taskset!("ExampleUsers")
            .register_task(task!(example_task))
        )
        // Set a default host so the load test will start.
        .set_default(GooseDefault::Host, "http://localhost/")?
        // Set a default run time so this test runs to completion.
        .set_default(GooseDefault::RunTime, 1)?
        .execute()
        .await?;

    // It is now possible to do something with the metrics collected by Goose.
    // For now, we'll just pretty-print the entire object.
    println!("{:#?}", goose_metrics);

    /**
    // For example:
    $ cargo run -- -H http://example.com -v -u1 -t1
    GooseMetrics {
        hash: 0,
        started: Some(
            2021-06-15T09:32:49.888147+02:00,
        ),
        duration: 1,
        users: 1,
        requests: {
            "GET /": GooseRequestMetricAggregate {
                path: "/",
                method: Get,
                response_times: {
                    3: 14,
                    4: 163,
                    5: 36,
                    6: 8,
                },
                min_response_time: 3,
                max_response_time: 6,
                total_response_time: 922,
                response_time_counter: 221,
                status_code_counts: {},
                success_count: 0,
                fail_count: 221,
                load_test_hash: 0,
            },
        },
        tasks: [
            [
                GooseTaskMetricAggregate {
                    taskset_index: 0,
                    taskset_name: "ExampleUsers",
                    task_index: 0,
                    task_name: "",
                    times: {
                        3: 14,
                        4: 161,
                        5: 38,
                        6: 8,
                    },
                    min_time: 3,
                    max_time: 6,
                    total_time: 924,
                    counter: 221,
                    success_count: 221,
                    fail_count: 0,
                },
            ],
        ],
        errors: {
            "503 Service Unavailable: /.GET./": GooseErrorMetric {
                method: Get,
                name: "/",
                error: "503 Service Unavailable: /",
                occurrences: 221,
            },
        },
        final_metrics: true,
        display_status_codes: false,
        display_metrics: true,
    }
    **/

    Ok(())
}

async fn example_task(user: &mut GooseUser) -> GooseTaskResult {
    let _goose = user.get("/").await?;

    Ok(())
}

Fields

hash: u64

A hash of the load test, primarily used to validate all Workers in a Gaggle are running the same load test.

starting: Option<DateTime<Local>>

Tracks when the load test first started with an optional system timestamp.

started: Option<DateTime<Local>>

Tracks when all GooseUser threads fully started with an optional system timestamp.

stopping: Option<DateTime<Local>>

Tracks when the load test first began stopping with an optional system timestamp.

stopped: Option<DateTime<Local>>

Tracks when the load test stopped with an optional system timestamp.

duration: usize

Total number of seconds the load test ran.

users: usize

Total number of users simulated during this load test.

This value may be smaller than what was configured at start time if the test didn’t run long enough for all configured users to start.

requests: GooseRequestMetrics

Tracks details about each request made during the load test.

Can be disabled with the --no-metrics run-time option, or with GooseDefault::NoMetrics.

tasks: GooseTaskMetrics

Tracks details about each task that is invoked during the load test.

Can be disabled with either the --no-task-metrics or --no-metrics run-time options, or with either the GooseDefault::NoTaskMetrics or GooseDefault::NoMetrics.

errors: GooseErrorMetrics

Tracks and counts each time an error is detected during the load test.

Can be disabled with either the --no-error-summary or --no-metrics run-time options, or with either the GooseDefault::NoErrorSummary or GooseDefault::NoMetrics.

hosts: HashSet<String>

Tracks all hosts that the load test is run against.

Implementations

Consumes and display all enabled metrics from a completed load test.

Example
use goose::prelude::*;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    GooseAttack::initialize()?
        .register_taskset(taskset!("ExampleUsers")
            .register_task(task!(example_task))
        )
        // Set a default host so the load test will start.
        .set_default(GooseDefault::Host, "http://localhost/")?
        // Set a default run time so this test runs to completion.
        .set_default(GooseDefault::RunTime, 1)?
        .execute()
        .await?
        .print();

    Ok(())
}

async fn example_task(user: &mut GooseUser) -> GooseTaskResult {
    let _goose = user.get("/").await?;

    Ok(())
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Implement format trait to allow displaying metrics.

Formats the value using the given formatter. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.