Terraform
Collect organization metrics
HCP Terraform provides an API endpoint that you can use to gather metrics related to your HCP Terraform organization.
Note: Metrics are available in HCP Terraform Standard and Premium editions. Refer to HCP Terraform pricing for details.
Introduction
When you create a metrics service token, HCP Terraform automatically begins gathering metrics from your organization and makes them available in a Prometheus-compatible format. If your organization has no valid metrics service tokens, HCP Terraform stops gathering metrics until you create a new valid token.
Workflow
To gather metrics from your HCP Terraform organization, complete the following steps:
- Create a metrics service API token. Refer to Create a metrics service token for more information.
- Configure your metrics collection software to gather metrics from HCP Terraform. Refer to Gather metrics for more information.
Requirements
To manage your organization's metrics service API token, you must be a member of your organization's owners team. Refer to the Organization owners documentation for more information on the owners team.
Create a metrics service token
To gather metrics from HCP Terraform, you must provide a metrics service token for your organization. Complete the follow steps to generate a metrics service API token:
- Sign in to HCP Terraform and navigate to your organization.
- Choose Settings from the sidebar, then API tokens.
- Choose the Metrics Service Tokens tab.
- Click Generate a token.
- Give the token a Name and Expiration.
- Click Generate.
Save this token in a safe place since HCP Terraform only displays it once. You must present the token to authenticate your metrics collection software.
You can also manage your metrics service API tokens with the HCP Terraform API. Refer to the Metrics service tokens API reference for more information.
Gather metrics
To read metrics from HCP Terraform, configure your metrics collection software to send a GET request with your organization ID and metrics service token to the /metrics endpoint. You must present the metrics service token you generated in Generate metrics service token to call the endpoint.
For example:
prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'hcp_telemetry'
scheme: https
metrics_path: '/telemetry/hcpt/org-XXXXXXXXXXXXX/metrics'
authorization:
type: 'Bearer'
credentials: 'hcpt_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
static_configs:
- targets:
- 'api.cloud.hashicorp.com:443
Metrics reference
HCP Terraform collects the following metrics:
| Metric | Labels | Type | Description | Update Interval |
|---|---|---|---|---|
terraform_vcs_egress_request_total | organization_id, workspace, project, status, vcs.provider | count | Total number of requests from HCP Terraform to VCS providers | 60s |
terraform_vcs_webhook_exists_check_total | organization_id, workspace, project, status, vcs.provider | count | Total number of checks that verify existing webhooks from HCP Terraform to VCS providers | 60s |
terraform_vcs_ingress_request_total | organization_id, workspace, project, status, vcs.provider | count | Webhook requests from VCS providers to HCP Terraform | 60s |
terraform_vcs_egress_request_duration_seconds | organization_id, workspace, project, vcs.provider | histogram | Duration of HCP Terraform-to-VCS API requests in seconds | 60s |
terraform_vcs_webhook_exists_check_duration_seconds | organization_id, workspace, project, vcs.provider | histogram | Duration in seconds of checks that verify existing webhooks | 60s |
tfc_terraform_agent_count | organization_id, status (idle/busy/unknown/errored/exited), agent_pool_id | gauge | Number of agents in any status by pool. | 60s |
terraform_run_phase_transitions_total | organization_id, workspace_id, phase | count | Cumulative count of run transitions into each Terraform execution phase | 60s |
terraform_run_status_total | organization_id, workspace_id, run_status | count | Cumulative count of completed runs by final status | 60s |
terraform_run_phase_duration_seconds | organization_id, workspace_id, phase | histogram | Time spent in each Terraform run phase, recorded on phase exit | 60s |
terraform_workspace_resource_count | organization_id, workspace_id | gauge | Current number of managed resources in a workspace | 60s |