- TypeScript
- Go
- Rust
Copy
Ask AI
// Account-level: active basins over the last 30 days
const accountMetrics = await s2.metrics.account({
set: "active-basins",
start: new Date(Date.now() - 30 * 24 * 3600 * 1000),
end: new Date(),
});
// Basin-level: storage usage with hourly resolution
const basinMetrics = await s2.metrics.basin({
basin: "events",
set: "storage",
start: new Date(Date.now() - 6 * 3600 * 1000),
end: new Date(),
interval: "hour",
});
// Stream-level: storage for a specific stream
const streamMetrics = await s2.metrics.stream({
basin: "events",
stream: "user-actions",
set: "storage",
start: new Date(Date.now() - 3600 * 1000),
end: new Date(),
interval: "minute",
});
Copy
Ask AI
now := time.Now().Unix()
thirtyDaysAgo := now - 30*24*3600
sixHoursAgo := now - 6*3600
hourAgo := now - 3600
// Account-level: active basins over the last 30 days
accountMetrics, _ := client.Metrics.Account(ctx, &s2.AccountMetricsArgs{
Set: s2.AccountMetricSetActiveBasins,
Start: &thirtyDaysAgo,
End: &now,
})
// Basin-level: storage usage with hourly resolution
hourInterval := s2.TimeseriesIntervalHour
basinMetrics, _ := client.Metrics.Basin(ctx, &s2.BasinMetricsArgs{
Basin: "events",
Set: s2.BasinMetricSetStorage,
Start: &sixHoursAgo,
End: &now,
Interval: &hourInterval,
})
// Stream-level: storage for a specific stream
minuteInterval := s2.TimeseriesIntervalMinute
streamMetrics, _ := client.Metrics.Stream(ctx, &s2.StreamMetricsArgs{
Basin: "events",
Stream: "user-actions",
Set: s2.StreamMetricSetStorage,
Start: &hourAgo,
End: &now,
Interval: &minuteInterval,
})
Copy
Ask AI
use std::time::{Duration, SystemTime};
let now = SystemTime::now();
let thirty_days_ago = now - Duration::from_secs(30 * 24 * 3600);
let six_hours_ago = now - Duration::from_secs(6 * 3600);
let hour_ago = now - Duration::from_secs(3600);
// Account-level: active basins over the last 30 days
let account_metrics = s2
.get_account_metrics(GetAccountMetricsInput::active_basins(thirty_days_ago, now))
.await?;
// Basin-level: storage usage with hourly resolution
let basin_metrics = s2
.get_basin_metrics(
GetBasinMetricsInput::storage("events".parse()?, six_hours_ago, now)
.with_interval(TimeseriesInterval::Hour),
)
.await?;
// Stream-level: storage for a specific stream
let stream_metrics = s2
.get_stream_metrics(
GetStreamMetricsInput::storage("events".parse()?, "user-actions".parse()?, hour_ago, now)
.with_interval(TimeseriesInterval::Minute),
)
.await?;

