Skip to content
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

Feature #329

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/get_bucket_space_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');

$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

$bucket = '';

$beginTime = "20200401000000";
$endTime = "20200424000000";

//5min or hour or day
$granularity = "day";

//存储区域 z0:华东 z1:华北 z2:华南 na0:北美 as0:东南亚
$region = "";

//获取流量数据
list($spaceData, $getSpaceErr) = $bucketManager->getSpaceData($bucket, $beginTime, $endTime, $granularity, $region);
if ($getSpaceErr != null) {
print_r($getSpaceErr);
} else {
echo "get space data success\n";
print_r($spaceData);
}
32 changes: 32 additions & 0 deletions src/Qiniu/Storage/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,38 @@ public function deleteAfterDays($bucket, $key, $days)
return $error;
}

/**
* @param array $bucket 待获取存储空间的 bucket
* @param string $beginTime 起始日期字符串,闭区间 格式类似 20200326105005
* @param string $endDate 结束日期字符串,开区间 格式类似 20200426105005
* @param string $granularity 获取数据的时间间隔(时间粒度),可以是 5min, hour 或者 day
* @param string $region 存储区域 z0:华东 z1:华北 z2:华南 na0:北美 as0:东南亚
*
* @return array 存储数据和错误信息,参考 examples/get_bucket_space_data.php 代码
*
* @link https://developer.qiniu.com/kodo/api/3908/statistic-space
*/
public function getSpaceData(string $bucket, string $beginTime, string $endTime, $granularity, $region)
{
$req = array();
$req['bucket'] = $bucket;
$req['begin'] = $beginTime;
$req['end'] = $endTime;
$req['g'] = $granularity;
$req['region'] = $region;

$url = '/v6/space';
foreach($req as $key => $val){
if($key == array_key_first($req)){
$url .= "?{$key}={$val}";
}else {
$url .= "&{$key}={$val}";
}
}

return $this->apiGet($url);
}

private function getRsfHost()
{
$scheme = "http://";
Expand Down