Files

67 lines
2.8 KiB
Dart

part of '../dart_appwrite.dart';
class Usage extends Service {
Usage(super.client);
/// Query usage event metrics from the usage database. Returns individual event
/// rows with full metadata. Pass Query objects as JSON strings to filter,
/// paginate, and order results. Supported query methods: equal,
/// greaterThanEqual, lessThanEqual, orderAsc, orderDesc, limit, offset.
/// Supported filter attributes: metric, path, method, status, resource,
/// resourceId, country, userAgent, time (these match the underlying column
/// names — note that the response surfaces `resource` as `resourceType` and
/// `country` as `countryCode`). When no time filter is supplied the endpoint
/// defaults to the last 7 days. Default `limit(100)` is applied if none is
/// given; user-supplied limits are capped at 500. The `total` field is capped
/// at 5000 to keep counts predictable — pass `total=false` to skip the count
/// entirely.
Future<models.UsageEventList> listEvents(
{List<String>? queries, bool? total}) async {
final String apiPath = '/usage/events';
final Map<String, dynamic> apiParams = {
if (queries != null) 'queries': queries,
if (total != null) 'total': total,
};
final Map<String, String> apiHeaders = {
'X-Appwrite-Project': client.config['project'] ?? '',
};
final res = await client.call(HttpMethod.get,
path: apiPath, params: apiParams, headers: apiHeaders);
return models.UsageEventList.fromMap(res.data);
}
/// Query usage gauge metrics (point-in-time resource snapshots) from the usage
/// database. Returns individual gauge snapshots with metric, value, timestamp,
/// resourceType, and resourceId. Pass Query objects as JSON strings to filter,
/// paginate, and order results. Supported query methods: equal,
/// greaterThanEqual, lessThanEqual, orderAsc, orderDesc, limit, offset.
/// Supported filter attributes: metric, time. Use `orderDesc("time"),
/// limit(1)` to fetch the most recent snapshot. When no time filter is
/// supplied the endpoint defaults to the last 7 days. Default `limit(100)` is
/// applied if none is given; user-supplied limits are capped at 500. The
/// `total` field is capped at 5000 to keep counts predictable — pass
/// `total=false` to skip the count entirely.
Future<models.UsageGaugeList> listGauges(
{List<String>? queries, bool? total}) async {
final String apiPath = '/usage/gauges';
final Map<String, dynamic> apiParams = {
if (queries != null) 'queries': queries,
if (total != null) 'total': total,
};
final Map<String, String> apiHeaders = {
'X-Appwrite-Project': client.config['project'] ?? '',
};
final res = await client.call(HttpMethod.get,
path: apiPath, params: apiParams, headers: apiHeaders);
return models.UsageGaugeList.fromMap(res.data);
}
}