What it covers
CostGraph reads metrics from Grafana for these pages:- Utilization and sparklines on the virtual machine list.
- Metrics on a virtual machine’s detail page.
- Top processes on a virtual machine’s detail page.
costgraph_* series. Each Mac declares where its metrics live in its
agent configuration: a Mac reads from Grafana only if its configuration
names this connection. A Mac that names no connection keeps using the metrics CostGraph
already has for it, and every other host does the same.
Choose how to connect
Grafana Cloud metrics
You need the Prometheus URL and instance ID from your stack’s Prometheus Details
page, plus an access policy token with the
metrics:read scope.A Grafana data source
You need your Grafana stack URL, the UID of the data source with your host metrics, and
a service account token. The service account needs the Viewer role and permission to query
that data source (
datasources:query). If data source permissions are restricted, the
Viewer role alone is not enough.Create the token
For Grafana Cloud metrics, create an access policy on grafana.com:- Sign in at grafana.com and open your organization’s Access Policies page, for example
https://grafana.com/orgs/example-org/access-policies/new. Replaceexample-orgwith your organization’s slug. - Choose the realm that contains your stack.
- Add the
metrics:readscope and create the policy. - Add a token to the policy and copy it. Grafana does not show it again.
Find a data source UID
- In Grafana, open Connections > Data sources.
- Open the data source that holds your host metrics.
- Copy the UID from the page address.
Connect
- Open Settings > Integrations and pick Grafana.
- Choose Grafana Cloud metrics or A Grafana data source.
- Enter the address, the instance ID or data source UID, and the token.
- Set the options in Label filters and Extra matchers.
- Select Connect.
- Copy the connection id from Integrations into each Mac’s agent configuration. See Point a Mac at this connection.
Point a Mac at this connection
Set these in the Mac’s agent configuration file, next toapi_key:
metrics_connection_idis the id of this connection, copied from Integrations.remote_write: falsestops the agent pushing host and process metrics to CostGraph. The Mac still registers, sends heartbeats, and shows up; its metrics are read from Grafana.metrics_instanceis optional. It is theinstancelabel value your scrape produces for this Mac. Leave it out to use the hostname.
metrics_connection_id can be at most 64 characters and metrics_instance at most 255. Neither can contain spaces, quotes, backslashes or braces.
A Mac that names a connection but has no series in it shows that there is no data from the
connection. It pushes nothing to CostGraph, so CostGraph’s own metrics do not stand in.
If Metrics is switched off on the connection, the Mac shows CostGraph’s own metrics, which are empty when remote_write is false. Switch Metrics back on or point the Mac at another connection. If the connection never had metrics on, the agent’s registration is refused with the message in the troubleshooting table.
metrics_only: true cannot be combined with remote_write: false or metrics_connection_id.
The agent refuses to start with that configuration: remove them or set metrics_only to
false. metrics_instance only applies together with metrics_connection_id.
After you connect, the dialog shows these settings ready to copy.
Use one connection for cost and metrics
One connection can serve more than one use. In Integrations, the Used for checkboxes Cost and Metrics turn each use on or off for the connection. A Mac can only name a connection that has Metrics switched on. To use an existing Grafana Cloud cost connection for metrics too, choose Also use for metrics. CostGraph reuses the token stored with that connection, so you enter no second token. Both need a token whose access policy hasmetrics:read, as in
Create the token. Otherwise add the scope to the policy, or reconnect
with a token that has it.
Set the instance label
Scrape the CostGraph agent on each Mac and setinstance to the bare hostname, or to the value you put in metrics_instance. You can
copy these snippets before you connect.
With Prometheus:
<mac-hostname> with each Mac’s hostname, or list all your Macs as targets.
A Mac matches when the instance label equals its hostname, with or without :port and with or without .local. Only the .local suffix is matched without regard to case; hostnames are otherwise case-sensitive. If you scrape by IP address or by a DNS name that is not the Mac’s hostname, set metrics_instance in the agent file to that exact instance value.
Label filters
Use Label filters when your store holds series for more than one environment or workspace. Each filter is a label name and a value, and CostGraph adds all of them to every query. For example, the filterenv = production reads only series labelled
env="production".
- Add at most 10 filters.
- A label name uses letters, digits, and underscores, and does not start with a digit.
- A value cannot be empty and can be at most 256 characters.
- You cannot filter on
instance,tenant_id, or any label that starts with__orcostgraph_.
Extra matchers
Use Extra matchers for filters that a label name and value cannot express. Enter optional PromQL-style label matchers, for exampleregion=~"eu-.*". CostGraph adds them to
every query after the label filters, so a series must satisfy all of them. Extra matchers
can be at most 1024 characters and cannot select a metric name.
CostGraph refuses a query that it cannot tie to your workspace’s hosts, instead of running
it. A refused query shows as an error on the page.
Macs that share the same instance value in your store cannot be told apart. Give each Mac
a different value.
Charts on Grafana
Charts that your series support fill in from Grafana: CPU, memory, load, disk space, network, and top processes. Some charts stay empty for macOS hosts: pressure, disk I/O, steal, and iowait. macOS does not report these, so Grafana has nothing to return. Top processes are computed from the raw process series, so you do not need recording rules in your store.Security
- The token is stored encrypted and is not shown again.
- Only public
httpsaddresses are allowed. An address with a username or password in it is refused; put the token in the token field. - Queries are read-only. CostGraph does not write to your Grafana.
- CostGraph queries your Grafana only for your own workspace’s hosts.
Check the connection
- Open Settings > Integrations and check the Grafana connection shows no error.
- Open a Mac that names this connection. Its metrics load from Grafana.
- If Grafana stops answering, the connection shows an error and affected pages report that metrics could not be read. Fix the cause and open a page again.