google-cloud-storage - 如何衡量每个用户在谷歌云存储上的带宽使用情况?
问题描述
我们希望根据用户数据的流量向用户收费。实际上,他们的数据正在消耗的下行带宽量。
我已经导出了谷歌云存储 access_logs。从日志中,我可以计算文件被访问的次数。(filesize * count 将是带宽使用)
但问题是这不适用于缓存内容。我的计算值远远超过实际使用量。
我采用这种方法是因为我们的流量将是新的并且不会使用缓存,这意味着差异无关紧要。但实际上,这似乎是一个真正的问题。
这是一个常见的用例,我认为应该有更好的方法来解决谷歌云存储的这个问题。
{
"insertId": "-tohip8e1vmvw",
"logName": "projects/bucket/logs/cloudaudit.googleapis.com%2Fdata_access",
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {
"principalEmail": "firebase-storage@system.gserviceaccount.com"
},
"authorizationInfo": [
{
"granted": true,
"permission": "storage.objects.get",
"resource": "projects/_/bucket/bucket.appspot.com/objects/users/2y7aPImLYeTsCt6X0dwNMlW9K5h1/somefile",
"resourceAttributes": {}
},
{
"granted": true,
"permission": "storage.objects.getIamPolicy",
"resource": "projects/_/bucket/bucket.appspot.com/objects/users/2y7aPImLYeTsCt6X0dwNMlW9K5h1/somefile",
"resourceAttributes": {}
}
],
"methodName": "storage.objects.get",
"requestMetadata": {
"destinationAttributes": {},
"requestAttributes": {
"auth": {},
"time": "2019-07-02T11:58:36.068Z"
}
},
"resourceLocation": {
"currentLocations": [
"eu"
]
},
"resourceName": "projects/_/bucket/bucket.appspot.com/objects/users/2y7aPImLYeTsCt6X0dwNMlW9K5h1/somefile",
"serviceName": "storage.googleapis.com",
"status": {}
},
"receiveTimestamp": "2019-07-02T11:58:36.412798307Z",
"resource": {
"labels": {
"bucket_name": "bucket.appspot.com",
"location": "eu",
"project_id": "project-id"
},
"type": "gcs_bucket"
},
"severity": "INFO",
"timestamp": "2019-07-02T11:58:36.062Z"
}
日志条目。
我们现在使用单个存储桶。如果有帮助,也可以使用多个。
解决方案
一种可能性是为每个用户设置一个单独的存储桶,并通过timeseries api获取存储桶的带宽使用情况。
用于此目的的端点是:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list
以下是实现一小时发送字节数的参数(我们可以指定60s以上的时间范围),其总和将是从桶中发送的总字节数。
{
"dataSets": [
{
"timeSeriesFilter": {
"filter": "metric.type=\"storage.googleapis.com/network/sent_bytes_count\" resource.type=\"gcs_bucket\" resource.label.\"project_id\"=\"<<<< project id here >>>>\" resource.label.\"bucket_name\"=\"<<<< bucket name here >>>>\"",
"perSeriesAligner": "ALIGN_SUM",
"crossSeriesReducer": "REDUCE_SUM",
"secondaryCrossSeriesReducer": "REDUCE_SUM",
"minAlignmentPeriod": "3600s",
"groupByFields": [
"resource.label.\"bucket_name\""
],
"unitOverride": "By"
},
"targetAxis": "Y1",
"plotType": "LINE",
"legendTemplate": "${resource.labels.bucket_name}"
}
],
"options": {
"mode": "COLOR"
},
"constantLines": [],
"timeshiftDuration": "0s",
"y1Axis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
推荐阅读
- python - 在 pandas 组中应用多个函数而无需迭代
- java - 如何获取服务基础设施的 proto 文件
- arrays - Brain Bender... 数组公式未使用 FILTER 函数填充单元格
- swift - 如何在 spriteKit(swift) 中使用持续时间?
- amazon-web-services - Cloudformation 将实例附加到 Auto Scaling 组
- python - 无法获得所需的星形图案。我究竟做错了什么?
- javascript - 无法向 Google 表格添加自定义菜单
- r - 设置循环以查找数据框中的唯一值,将它们求和并将它们添加到数据框中的新行
- c - 关于块范围链接,没有错误,没有警告,但结果很惊讶,我不知道为什么
- java - 服务器和客户端程序因未知原因停止