feat(service): custom product, lịch sử giám sát VM và mã hoá response theo phiên
- Dịch vụ custom: bảng custom_products + services.custom_product_id; createService nhận
custom{} thay product_id, giá = đơn giá tháng x số tháng chu kỳ (1/3/6/12/24/36),
gia hạn tính theo cùng đơn giá, ServiceClientDetailResource trả custom_product và specs.
- Giám sát VM: GET v1/system/vm-metrics/history gom lịch sử về tối đa 240 điểm;
lỗi lấy dung lượng đĩa không còn làm hỏng cả thẻ metrics.
- SealResponse: AES-256-GCM theo khoá phiên do proxy Next cấp qua header x-seal-key
(HMAC của session id). Client opt-in bằng x-seal; chi tiết dịch vụ, mật khẩu VM và
console ticket luôn được mã hoá. Body gửi lên dạng {enc} được giải mã trước validate;
khoá lệch trả 428 để client lấy khoá mới. Đây là che mắt DevTools, không phải bảo mật
chống chính chủ tài khoản.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8108e8fe53
commit
6315a392c0
@@ -11,7 +11,11 @@ class VmMetricsService
|
||||
public function get(string $vmwareId, ?int $memoryTotalMb = null, ?int $cpuCores = null): array
|
||||
{
|
||||
$stats = $this->portalMonitor->vmMetrics($vmwareId);
|
||||
$storage = $this->portalMonitor->vmStorage($vmwareId);
|
||||
try {
|
||||
$storage = $this->portalMonitor->vmStorage($vmwareId);
|
||||
} catch (\RuntimeException) {
|
||||
$storage = [];
|
||||
}
|
||||
$provisionedDiskBytes = collect($storage['disks'] ?? [])->sum(
|
||||
fn ($disk) => is_array($disk) ? (int) ($disk['capacity_bytes'] ?? 0) : 0
|
||||
);
|
||||
@@ -38,4 +42,36 @@ class VmMetricsService
|
||||
'stale' => (bool) ($stats['stale'] ?? false),
|
||||
];
|
||||
}
|
||||
|
||||
private const HISTORY_FIELDS = [
|
||||
'cpu' => 'cpu_usage_percent',
|
||||
'mem' => 'guest_memory_usage_percent',
|
||||
'disk_read_bps' => 'disk_read_bps',
|
||||
'disk_write_bps' => 'disk_write_bps',
|
||||
'net_rx_bps' => 'network_rx_bps',
|
||||
'net_tx_bps' => 'network_tx_bps',
|
||||
];
|
||||
|
||||
public function history(string $vmwareId, \DateTimeInterface $from, \DateTimeInterface $to, int $maxPoints = 240): array
|
||||
{
|
||||
$rows = $this->portalMonitor->vmHistory($vmwareId, $from, $to);
|
||||
$span = max(1, $to->getTimestamp() - $from->getTimestamp());
|
||||
$bucket = max(1, (int) ceil($span / $maxPoints));
|
||||
|
||||
return collect($rows)
|
||||
->filter(fn ($row) => is_array($row) && isset($row['timestamp']))
|
||||
->groupBy(fn ($row) => intdiv(strtotime($row['timestamp']), $bucket))
|
||||
->map(function ($group, $key) use ($bucket) {
|
||||
$point = ['t' => gmdate('c', $key * $bucket + intdiv($bucket, 2))];
|
||||
foreach (self::HISTORY_FIELDS as $name => $source) {
|
||||
$values = $group->pluck($source)->filter(fn ($v) => $v !== null);
|
||||
$point[$name] = $values->isEmpty() ? null : round($values->avg(), 2);
|
||||
}
|
||||
|
||||
return $point;
|
||||
})
|
||||
->sortKeys()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user