Integrations
Connect Grafana
Connects the tenant's Grafana so CostGraph can read host metrics from it when pages load. Nothing is copied into CostGraph. The token is checked with a test query and stored encrypted; it is never returned. A host is read from this connection only when its agent config names the connection id; its instance label must equal its metrics_instance setting, or its hostname when that is not set, with or without a trailing .local and :port. Every other host keeps showing CostGraph's own metrics, and a host that names the connection but has no series in it shows no data rather than CostGraph's metrics. label_filters is an object of label name to exact value added to every query, for example {"env": "production"}; at most 10, and instance, tenant_id, costgraph_ and __ labels are reserved. The connection is refused when Grafana does not answer the test query or host metrics cannot be read.
POST
/
api
/
v1
/
integrations
/
grafana
/
connect
Connect Grafana
curl --request POST \
--url https://api.costgraph.ai/api/v1/integrations/grafana/connect \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"tenant_id": "<string>",
"url": "<string>",
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"name": "<string>",
"token": "<string>",
"username": "<string>"
}
'import requests
url = "https://api.costgraph.ai/api/v1/integrations/grafana/connect"
payload = {
"tenant_id": "<string>",
"url": "<string>",
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"name": "<string>",
"token": "<string>",
"username": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
tenant_id: '<string>',
url: '<string>',
datasource_uid: '<string>',
extra_matchers: '<string>',
label_filters: {},
name: '<string>',
token: '<string>',
username: '<string>'
})
};
fetch('https://api.costgraph.ai/api/v1/integrations/grafana/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.costgraph.ai/api/v1/integrations/grafana/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'tenant_id' => '<string>',
'url' => '<string>',
'datasource_uid' => '<string>',
'extra_matchers' => '<string>',
'label_filters' => [
],
'name' => '<string>',
'token' => '<string>',
'username' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.costgraph.ai/api/v1/integrations/grafana/connect"
payload := strings.NewReader("{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.costgraph.ai/api/v1/integrations/grafana/connect")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.costgraph.ai/api/v1/integrations/grafana/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "some message",
"status": "success",
"data": {
"source": {
"auth_mode": "basic",
"connection_id": "<string>",
"connection_modes": [
"cost"
],
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"public_id": "<string>",
"scrape_config": {
"alloy": "<string>",
"prometheus": "<string>"
},
"updated_at": "<string>",
"url": "<string>",
"username": "<string>"
},
"warnings": [
"<string>"
]
}
}{
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}Authorizations
Enter "Bearer {token}"
Body
application/json
Grafana connection
Was this page helpful?
⌘I
Connect Grafana
curl --request POST \
--url https://api.costgraph.ai/api/v1/integrations/grafana/connect \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"tenant_id": "<string>",
"url": "<string>",
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"name": "<string>",
"token": "<string>",
"username": "<string>"
}
'import requests
url = "https://api.costgraph.ai/api/v1/integrations/grafana/connect"
payload = {
"tenant_id": "<string>",
"url": "<string>",
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"name": "<string>",
"token": "<string>",
"username": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
tenant_id: '<string>',
url: '<string>',
datasource_uid: '<string>',
extra_matchers: '<string>',
label_filters: {},
name: '<string>',
token: '<string>',
username: '<string>'
})
};
fetch('https://api.costgraph.ai/api/v1/integrations/grafana/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.costgraph.ai/api/v1/integrations/grafana/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'tenant_id' => '<string>',
'url' => '<string>',
'datasource_uid' => '<string>',
'extra_matchers' => '<string>',
'label_filters' => [
],
'name' => '<string>',
'token' => '<string>',
'username' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.costgraph.ai/api/v1/integrations/grafana/connect"
payload := strings.NewReader("{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.costgraph.ai/api/v1/integrations/grafana/connect")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.costgraph.ai/api/v1/integrations/grafana/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tenant_id\": \"<string>\",\n \"url\": \"<string>\",\n \"datasource_uid\": \"<string>\",\n \"extra_matchers\": \"<string>\",\n \"label_filters\": {},\n \"name\": \"<string>\",\n \"token\": \"<string>\",\n \"username\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "some message",
"status": "success",
"data": {
"source": {
"auth_mode": "basic",
"connection_id": "<string>",
"connection_modes": [
"cost"
],
"datasource_uid": "<string>",
"extra_matchers": "<string>",
"label_filters": {},
"public_id": "<string>",
"scrape_config": {
"alloy": "<string>",
"prometheus": "<string>"
},
"updated_at": "<string>",
"url": "<string>",
"username": "<string>"
},
"warnings": [
"<string>"
]
}
}{
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}