Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Cacti 1.2 plugin that brings resources and metrics from public cloud providers into Cacti as ordinary devices, data sources, and graphs. Cloud workloads then sit next to the network that carries them, under Cacti's permissions, and Thold and Maint can alert on and suppress them. One plugin covers every provider, with a driver per provider: DigitalOcean, AWS, Google Cloud, and Azure first.

> **Status: in development, no release yet.** Milestone 2 (foundation) is merged on `main`. The plugin installs, stores accounts and credentials, and runs its collector, but no provider driver is merged, so it collects nothing. Milestone 3 (DigitalOcean and Cacti objects) is in progress and not yet on `main`. Do not run it in production.
> **Status: milestone 3 (DigitalOcean and Cacti objects), in review.** The milestone adds the DigitalOcean driver, Cacti templates, a scope device per account with a data query per resource type, the script server input, and a request estimate on New Graphs and the health page. Initial checks against a live DigitalOcean account are recorded in [provider facts](docs/research/provider-facts.md). Do not run it in production.

## Why

Expand All @@ -26,7 +26,7 @@ The plugin reads each provider's monitoring API on a Cacti poller, caches the la
| Phase | Scope | Milestones | Status |
|---|---|---|---|
| 0, research | Provider fact confirmation, metric catalogs, cost and rate model, signing test vectors, transport spike | [M1](https://github.com/somethingwithproof/plugin_cloud/milestone/1) | Done, except the checks that need a live provider account |
| 1, core and DigitalOcean | Accounts, credential vault, transport, collector, observation cache, Cacti objects, health page, DigitalOcean Droplets and load balancers | [M2](https://github.com/somethingwithproof/plugin_cloud/milestone/2), [M3](https://github.com/somethingwithproof/plugin_cloud/milestone/3), [M4](https://github.com/somethingwithproof/plugin_cloud/milestone/4) | M2 merged ([#81](https://github.com/somethingwithproof/plugin_cloud/pull/81)); M3 in progress, not on `main`; M4 not started |
| 1, core and DigitalOcean | Accounts, credential vault, transport, collector, observation cache, Cacti objects, health page, DigitalOcean Droplets and load balancers | [M2](https://github.com/somethingwithproof/plugin_cloud/milestone/2), [M3](https://github.com/somethingwithproof/plugin_cloud/milestone/3), [M4](https://github.com/somethingwithproof/plugin_cloud/milestone/4) | M2 done ([#81](https://github.com/somethingwithproof/plugin_cloud/pull/81)); M3 driver, templates, and scope devices merged; request estimates, permissions, and performance checks in review; M4 not started |
| 2, AWS | Signature Version 4, `AssumeRole`, instance roles, CloudWatch `GetMetricData`, regional inventory | [M5](https://github.com/somethingwithproof/plugin_cloud/milestone/5) | Not started |
| 3, Google Cloud | Service account JWT, metadata server, Cloud Monitoring `timeSeries.list` | [M6](https://github.com/somethingwithproof/plugin_cloud/milestone/6) | Not started |
| 4, Azure | Entra client credentials, managed identity, Resource Graph, `metrics:getBatch` | [M7](https://github.com/somethingwithproof/plugin_cloud/milestone/7) | Not started |
Expand Down
1 change: 1 addition & 0 deletions cloud_health.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
api_user_realm_auth('cloud_accounts.php'),
(int) read_config_option('poller_interval')
);
cloud_estimate_view()->render(cloud_accounts()->all());
bottom_footer();
2 changes: 1 addition & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ flowchart TB

| Component | Responsibility | Interfaces | Failure behavior |
|---|---|---|---|
| Plugin pages | Accounts, credentials, inventory, graph selection with cost estimate, health | Cacti page framework, csrf-magic, realms | Show cached data with its age; never call a provider during a page request except Verify |
| Plugin pages | Accounts, credentials, inventory, health with the request estimate, an estimate link and summary on New Graphs for scope devices | Cacti page framework, csrf-magic, realms | Show cached data with its age; never call a provider during a page request except Verify |
| Collector (`poller_cloud.php`) | For each due account: refresh credentials, run discovery when due, read metrics for enabled data sources, update the cache and health | `poller_bottom`, `exec_background()`, `register_process_start()`, filtered by `poller_id` | One instance per poller; time budget per run; per-account lease; resumes next cycle |
| Provider driver | Authentication, endpoints, discovery, metric reads, cost and request estimates for one provider | `ProviderDriver` interface | Returns typed errors (`auth`, `permission`, `throttled`, `transient`, `malformed`, `config`); never throws provider text into pages |
| Transport | One HTTPS request at a time with timeouts, size cap, no redirects, outbound allowlist | `HttpTransport` interface | A refused URL never resolves a name or opens a socket |
Expand Down
140 changes: 140 additions & 0 deletions lib/CostPreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/*
* SPDX-FileCopyrightText: 2026 Thomas Vincent <thomasvincent@gmail.com>
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of plugin_cloud, a plugin for Cacti.
* https://github.com/somethingwithproof/plugin_cloud
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
namespace Somethingwithproof\Cloud;

/**
* Usage estimates for what an account could graph and what it collects
* (REQ-COST-001, REQ-COST-002, ADR 0005). Every figure comes from the
* provider driver's own estimate, from cached inventory only; nothing here
* calls a provider.
*/
final class CostPreview {
private const SECONDS_PER_HOUR = 3600;

public function __construct(
private readonly ResourceRepository $resources,
private readonly SeriesRepository $series,
) {
}

/**
* One row per graph the account's resources can have: the cost of that
* graph on one resource, and on every resource of its type.
*
* @return list<array{graph: string, type: string, title: string, resources: int,
* perResource: UsageEstimate, all: UsageEstimate}>
*/
public function graphs(Account $account, ProviderDriver $driver): array {
if ($account->provider !== Provider::DigitalOcean) {
return [];
}

$rows = [];
$served = [];

foreach (DigitalOceanCatalog::GRAPHS as $graph => [$type, $title, , , $fields]) {
$served[$type] ??= $this->resources->served($account->id, $type);
$metrics = self::metrics($fields);
$example = [['id' => 0, 'providerId' => '0']];

$rows[] = [
'graph' => $graph,
'type' => $type,
'title' => $title,
'resources' => count($served[$type]),
'perResource' => $driver->estimate(self::requests($example, $type, $metrics), $account->collectInterval),
'all' => $driver->estimate(self::requests($served[$type], $type, $metrics), $account->collectInterval),
];
}

return $rows;
}

/**
* Every graph on every resource the account has.
*/
public function everything(Account $account, ProviderDriver $driver): UsageEstimate {
$requests = [];

if ($account->provider === Provider::DigitalOcean) {
$metrics = [];

foreach (DigitalOceanCatalog::GRAPHS as [$type, , , , $fields]) {
$metrics[$type] = array_merge($metrics[$type] ?? [], self::metrics($fields));
}

foreach ($metrics as $type => $names) {
$requests = array_merge(
$requests,
self::requests($this->resources->served($account->id, $type), $type, $names)
);
}
}

return $driver->estimate($requests, $account->collectInterval);
}

/**
* The metric series that fit the collector budget. Discovery requests
* already spent by a run reduce the allowance in exactly the same way.
*/
public function collected(Account $account, ProviderDriver $driver, int $discoveryRequests = 0): UsageEstimate {
[$fit] = RequestBudget::split($account, $driver, $this->series->enabledFor($account->id), $discoveryRequests);

return $driver->estimate($fit, $account->collectInterval);
}

public function requested(Account $account, ProviderDriver $driver): UsageEstimate {
return $driver->estimate($this->series->enabledFor($account->id), $account->collectInterval);
}

public static function perHour(UsageEstimate $estimate, int $collectInterval): int {
return (int) ceil($estimate->requestsPerCollection * self::SECONDS_PER_HOUR / max(1, $collectInterval));
}

/**
* The fields of a graph that read a metric; age reads nothing.
*
* @param list<string> $fields
* @return list<string>
*/
private static function metrics(array $fields): array {
return array_values(array_filter(
$fields,
static fn (string $field): bool => DigitalOceanCatalog::metric($field) !== null
));
}

/**
* @param list<array{id: int, providerId: string}> $resources
* @param list<string> $metrics
* @return list<MetricRequest>
*/
private static function requests(array $resources, string $type, array $metrics): array {
$requests = [];

foreach ($resources as $resource) {
foreach ($metrics as $metric) {
$requests[] = new MetricRequest($resource['id'], $type, $resource['providerId'], $metric);
}
}

return $requests;
}
}
12 changes: 11 additions & 1 deletion lib/DigitalOceanDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ final class DigitalOceanDriver implements ProviderDriver {

private const MONTH = 2592000;

/** Where the rate limit is documented and no API charge is (provider facts DO10). */
private const PRICE_SOURCE = 'https://docs.digitalocean.com/reference/api/reference/openapi.json';
private const PRICE_CHECKED = '2026-11-14';

/** The longest wait a provider may impose through Retry-After or ratelimit-reset. */
private const MAX_WAIT = 3600;

Expand Down Expand Up @@ -248,7 +252,13 @@ public function collect(Account $account, Secret $credential, array $requests):
public function estimate(array $requests, int $intervalSeconds): UsageEstimate {
$perCollection = count($requests);

return new UsageEstimate($perCollection, (int) ceil($perCollection * self::MONTH / max(1, $intervalSeconds)), 0.0);
return new UsageEstimate(
$perCollection,
(int) ceil($perCollection * self::MONTH / max(1, $intervalSeconds)),
0.0,
self::PRICE_SOURCE,
self::PRICE_CHECKED
);
}

/**
Expand Down
Loading
Loading