-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrument RustyVault with Prometheus #76
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wa5i
requested changes
Sep 18, 2024
wa5i
requested changes
Sep 20, 2024
|
|
The Windows test case has failed. |
The metric In system_metric.rs test case, skip the assert of load average on Windows platform. // load average is not available on Windows
if cfg!(target_os = "windows") {
gauge_map.remove("load_average");
} |
…on Windows platform.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instrument RustyVault with Prometheus
Design
To monitor the system's performance effectively, I applied both the USE and RED methods for metrics collection in RustyVault.
USE Method (Utilization, Saturation, Errors):
Track resource utilization and detect bottlenecks. Metrics related to system resources have been added to ensure the system's health is continuously monitored:
CPU Utilization: Measures the percentage of CPU usage by the RustyVault service.
Memory Utilization: Tracks memory usage, including total, free, and cached memory.
Disk I/O Saturation: Monitors disk read/write speed and detects potential bottlenecks.
Network I/O Saturation: Tracks the amount of data sent and received.
RED Method (Rate, Errors, Duration)
Track the behavior of requests within the application:
Rate: We implemented requests_total to track the rate of requests coming into the system. This allows us to monitor the overall throughput.
Errors: The errors_total counter tracks the number of failed requests and helps monitor the system's error rate.
Duration: Using request_duration_seconds, we measure the time taken to process each request, enabling us to analyze latency and potential performance issues.
Implemented Metrics
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
<Gauge, AtomicU64>
struct HttpLabel {path:String, method:MetricsMethod, status:u16}
Family<HttpLabel, Counter>
Family<HttpLabel, Histogram>
Changes
MetricsManager
inmanager.rs
to store Prometheus Registry, system metrics (system_metrics
), and HTTP API metrics (http_metrics
).metrics_manager
into the server insrc/cli/command/server.rs
by inserting it intoapp_data
.init_metrics_service
in metrics.rs, Sets up the /metrics service by configuring a route in the ServiceConfig.Associates the /metrics route with
metrics_handler
to handle GET requests and respond with Prometheus metrics in text format.System Metrics Collection:
SystemMetrics
struct insystem_metrics.rs
to gather CPU, memory, load, and disk metrics using thesysinfo
crate.collect_metrics
function to collect and store system information.start_collecting
method inserver.block_on
to periodically collect system metrics.HTTP Middleware:
MetricsMiddleware
inmiddleware.rs
as a function middleware to capture HTTP request metrics.src/cli/command/server.rs
to apply the middleware using.wrap(from_fn(metrics_middleware))
.MetricsMethod
enum, trackingGET
,POST
,PUT
,DELETE
, and categorizing others asOTHER
.HTTP Metrics:
HttpMetrics
struct inhttp_metrics.rs
to handle HTTP request counting and duration observation.requests
counter andhistogram
for request durations.increment_request_count
andobserve_duration
for tracking requests and their durations, labeled by HTTP method and path.Testing Steps
curl
to visithttp://localhost:<PORT>/metrics
./login
and/register
.requests_total
andrequest_duration_seconds
increment appropriately.errors_total
increments accordingly./metrics
endpoint to the Prometheus configuration.