gigadrive 2.12.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -32,7 +32,7 @@ var import_effect31 = require("effect");
32
32
  // package.json
33
33
  var package_default = {
34
34
  name: "gigadrive",
35
- version: "2.12.0",
35
+ version: "2.13.0",
36
36
  repository: {
37
37
  type: "git",
38
38
  url: "https://github.com/Gigadrive/sdk.git",
@@ -3518,6 +3518,36 @@ var getCommand = import_cli12.Command.make(
3518
3518
  for (const line of describeMicroVm(vm)) yield* import_effect24.Console.log(line);
3519
3519
  }).pipe(reportErrors2("get the microVM"))
3520
3520
  ).pipe(import_cli12.Command.withDescription("Show a microVM"));
3521
+ var formatGigabytes = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
3522
+ var describeMicroVmMetrics = (metrics) => {
3523
+ const latest = metrics.cpu.at(-1);
3524
+ const peak = metrics.cpu.reduce((max, point) => Math.max(max, point.cpuPercent), 0);
3525
+ return [
3526
+ `CPU (last ${metrics.windowMinutes} min, ${metrics.vcpus} vCPU): ${latest ? `${latest.cpuPercent}% at ${latest.time}, peak ${peak}%` : "no samples"}`,
3527
+ metrics.current ? `Memory: ${formatGigabytes(metrics.current.memoryUsedBytes)} of ${formatGigabytes(metrics.current.memoryTotalBytes)}` : "Memory: unavailable (not running, or no answer)",
3528
+ metrics.current ? `Disk: ${formatGigabytes(metrics.current.diskUsedBytes)} of ${formatGigabytes(metrics.current.diskTotalBytes)}` : "Disk: unavailable (not running, or no answer)"
3529
+ ];
3530
+ };
3531
+ var metricsCommand = import_cli12.Command.make(
3532
+ "metrics",
3533
+ {
3534
+ microvmId: microvmIdArg,
3535
+ window: import_cli12.Options.integer("window").pipe(
3536
+ import_cli12.Options.withDescription("Minutes of CPU history, 1 to 1440 (default: 15)"),
3537
+ import_cli12.Options.optional
3538
+ ),
3539
+ json: jsonOption2
3540
+ },
3541
+ ({ microvmId, window, json }) => import_effect24.Effect.gen(function* () {
3542
+ const apiClient = yield* ApiClientService;
3543
+ const windowMinutes = import_effect24.Option.getOrUndefined(window);
3544
+ const metrics = yield* apiClient.request(
3545
+ (client) => client.microvms.getMetrics(microvmId, windowMinutes === void 0 ? {} : { windowMinutes })
3546
+ );
3547
+ if (json) return yield* import_effect24.Console.log(JSON.stringify(metrics, null, 2));
3548
+ for (const line of describeMicroVmMetrics(metrics)) yield* import_effect24.Console.log(line);
3549
+ }).pipe(reportErrors2("read the microVM metrics"))
3550
+ ).pipe(import_cli12.Command.withDescription("Show a microVM's CPU, memory and disk use"));
3521
3551
  var execInMicroVm = (flags, io = nodeSessionIo()) => import_effect24.Effect.gen(function* () {
3522
3552
  const env = yield* keyValues("--env", flags.env);
3523
3553
  const timeout = yield* optionalDuration("--timeout", flags.timeout);
@@ -3919,6 +3949,7 @@ var SUBCOMMANDS = [
3919
3949
  createCommand,
3920
3950
  listCommand2,
3921
3951
  getCommand,
3952
+ metricsCommand,
3922
3953
  execCommand,
3923
3954
  shellCommand,
3924
3955
  copyCommand,