diff --git a/api/operator_usage.go b/api/operator_usage.go index e47d4b53e037a..8977449ddd361 100644 --- a/api/operator_usage.go +++ b/api/operator_usage.go @@ -10,6 +10,7 @@ type Usage struct { // ServiceUsage contains information about the number of services and service instances for a datacenter. type ServiceUsage struct { + Nodes int Services int ServiceInstances int ConnectServiceInstances map[string]int diff --git a/command/operator/usage/instances/usage_instances.go b/command/operator/usage/instances/usage_instances.go index 5e8dba201ce87..615771e21bfad 100644 --- a/command/operator/usage/instances/usage_instances.go +++ b/command/operator/usage/instances/usage_instances.go @@ -72,6 +72,7 @@ func (c *cmd) Run(args []string) int { } billableTotal := 0 + nodesTotal := 0 var datacenterBillableTotals []string usage, _, err := client.Operator().Usage(&api.QueryOptions{Global: c.allDatacenters}) if err != nil { @@ -80,13 +81,16 @@ func (c *cmd) Run(args []string) int { } for dc, usage := range usage.Usage { billableTotal += usage.BillableServiceInstances + nodesTotal += usage.Nodes datacenterBillableTotals = append(datacenterBillableTotals, - fmt.Sprintf("%s Billable Service Instances: %d", dc, usage.BillableServiceInstances)) + fmt.Sprintf("%s Billable Service Instances: %d", dc, usage.BillableServiceInstances), + fmt.Sprintf("%s Nodes: %d", dc, usage.Nodes)) } // Output billable service counts if !c.onlyConnect { c.UI.Output(fmt.Sprintf("Billable Service Instances Total: %d", billableTotal)) + c.UI.Output(fmt.Sprintf("Nodes Total: %d", nodesTotal)) sort.Strings(datacenterBillableTotals) for _, datacenterTotal := range datacenterBillableTotals { c.UI.Output(datacenterTotal) diff --git a/command/operator/usage/instances/usage_instances_test.go b/command/operator/usage/instances/usage_instances_test.go index 8ad38e1b0c53a..094f07dbfc3ff 100644 --- a/command/operator/usage/instances/usage_instances_test.go +++ b/command/operator/usage/instances/usage_instances_test.go @@ -48,7 +48,7 @@ func TestUsageInstancesCommand(t *testing.T) { }{ { name: "basic output", - output: "Billable Service Instances Total: 2", + output: "Billable Service Instances Total: 2\nNodes Total: 1\ndc1 Billable Service Instances: 2\ndc1 Nodes: 1", }, { name: "billable and connect flags together are invalid", diff --git a/website/content/commands/operator/usage.mdx b/website/content/commands/operator/usage.mdx index 56d364862690a..e11ae4bd39295 100644 --- a/website/content/commands/operator/usage.mdx +++ b/website/content/commands/operator/usage.mdx @@ -44,7 +44,9 @@ The output looks like this: ```text $ consul operator usage instances Billable Service Instances Total: 3 +Nodes Total: 1 dc1 Billable Service Instances: 3 +dc1 Nodes: 1 Billable Services Services Service instances @@ -64,8 +66,11 @@ With the `-all-datacenters` flag: ```text $ consul operator usage instances -all-datacenters Billable Service Instances Total: 4 +Nodes Total: 2 dc1 Billable Service Instances: 3 +dc1 Nodes: 1 dc2 Billable Service Instances: 1 +dc2 Nodes: 1 Billable Services Datacenter Services Service instances