Struct swanling::metrics::SwanlingMetrics [−][src]
pub struct SwanlingMetrics { pub hash: u64, pub started: Option<DateTime<Local>>, pub duration: usize, pub users: usize, pub requests: SwanlingRequestMetrics, pub tasks: SwanlingTaskMetrics, pub errors: SwanlingErrorMetrics, // some fields omitted }
Expand description
All metrics optionally collected during a Swanling load test.
By default, Swanling collects metrics during a load test in a SwanlingMetrics
object
that is returned by
SwanlingAttack::execute()
when a load
test finishes.
Example
use swanling::prelude::*; fn main() -> Result<(), SwanlingError> { let swanling_metrics: SwanlingMetrics = SwanlingAttack::initialize()? .register_taskset(taskset!("ExampleUsers") .register_task(task!(example_task)) ) // Set a default host so the load test will start. .set_default(SwanlingDefault::Host, "http://localhost/")? // Set a default run time so this test runs to completion. .set_default(SwanlingDefault::RunTime, 1)? .execute()?; // It is now possible to do something with the metrics collected by Swanling. // For now, we'll just pretty-print the entire object. println!("{:#?}", swanling_metrics); /** // For example: $ cargo run -- -H http://example.com -v -u1 -t1 SwanlingMetrics { hash: 0, started: Some( 2021-06-15T09:32:49.888147+02:00, ), duration: 1, users: 1, requests: { "GET /": SwanlingRequestMetricAggregate { 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: [ [ SwanlingTaskMetricAggregate { 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./": SwanlingErrorMetric { 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: &SwanlingUser) -> SwanlingTaskResult { let _swanling = user.get("/").await?; Ok(()) }
Fields
hash: u64
A hash of the load test, primarily used to validate all Workers in a Regatta are running the same load test.
started: Option<DateTime<Local>>
An optional system timestamp indicating when the load test started.
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: SwanlingRequestMetrics
Tracks details about each request made during the load test.
Can be disabled with the --no-metrics
run-time option, or with
SwanlingDefault::NoMetrics.
tasks: SwanlingTaskMetrics
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
SwanlingDefault::NoTaskMetrics or
SwanlingDefault::NoMetrics.
errors: SwanlingErrorMetrics
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
SwanlingDefault::NoErrorSummary or
SwanlingDefault::NoMetrics.
Implementations
Consumes and display all enabled metrics from a completed load test.
Example
use swanling::prelude::*; fn main() -> Result<(), SwanlingError> { SwanlingAttack::initialize()? .register_taskset(taskset!("ExampleUsers") .register_task(task!(example_task)) ) // Set a default host so the load test will start. .set_default(SwanlingDefault::Host, "http://localhost/")? // Set a default run time so this test runs to completion. .set_default(SwanlingDefault::RunTime, 1)? .execute()? .print(); Ok(()) } async fn example_task(user: &SwanlingUser) -> SwanlingTaskResult { let _swanling = user.get("/").await?; Ok(()) }
Trait Implementations
Returns the “default value” for a type. Read more
Implement format trait to allow displaying metrics.
Auto Trait Implementations
impl RefUnwindSafe for SwanlingMetrics
impl Send for SwanlingMetrics
impl Sync for SwanlingMetrics
impl Unpin for SwanlingMetrics
impl UnwindSafe for SwanlingMetrics
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V