-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgrafana_cloud.alloy
111 lines (92 loc) · 2.98 KB
/
grafana_cloud.alloy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Module Components: grafana_cloud
Description: Grafana Cloud Receiver Provider
*/
declare "grafana_cloud" {
/*
To create a token:
1. Navigate to the Grafana Cloud Portal: https://grafana.com/profile/org
2. Go to either the Access Policies or API Keys page, located in the Security section
3. Create an Access Policy or API token with the correct permissions
The token must have permissions to read stack information. The setup of these permissions depends on the type of token:
Access Policies need the stacks:read scope
API Keys need at least the the MetricsPublisher role
*/
/***************************************************
* ARGUMENTS
***************************************************/
argument "stack_name" {
comment = "Name of your stack as shown in the account console"
}
argument "token" {
comment = "Access policy token or API Key."
}
/***************************************************
* External information
***************************************************/
remote.http "json_config" {
url = "https://grafana.com/api/instances/" + argument.stack_name.value
client {
bearer_token = argument.token.value
}
poll_frequency = "24h"
}
/***************************************************
* Setup Receivers
***************************************************/
prometheus.remote_write "grafana_cloud" {
endpoint {
url = json_decode(remote.http.json_config.content)["hmInstancePromUrl"] + "/api/prom/push"
basic_auth {
username = json_decode(remote.http.json_config.content)["hmInstancePromId"]
password = argument.token.value
}
}
}
loki.write "grafana_cloud" {
endpoint {
url = json_decode(remote.http.json_config.content)["hlInstanceUrl"] + "/loki/api/v1/push"
basic_auth {
username = json_decode(remote.http.json_config.content)["hlInstanceId"]
password = argument.token.value
}
}
}
otelcol.auth.basic "grafana_cloud" {
username = json_decode(remote.http.json_config.content)["htInstanceId"]
password = argument.token.value
}
otelcol.exporter.otlp "grafana_cloud" {
client {
endpoint = json_decode(remote.http.json_config.content)["htInstanceUrl"] + ":443"
auth = otelcol.auth.basic.grafana_cloud.handler
}
}
pyroscope.write "grafana_cloud" {
endpoint {
url = json_decode(remote.http.json_config.content)["hpInstanceUrl"]
basic_auth {
username = json_decode(remote.http.json_config.content)["hpInstanceId"]
password = argument.token.value
}
}
}
/***************************************************
* EXPORTS
***************************************************/
export "metrics_receiver" {
value = prometheus.remote_write.grafana_cloud.receiver
}
export "logs_receiver" {
value = loki.write.grafana_cloud.receiver
}
export "traces_receiver" {
value = otelcol.exporter.otlp.grafana_cloud.input
}
export "profiles_receiver" {
value = pyroscope.write.grafana_cloud.receiver
}
export "stack_information" {
value = json_decode(remote.http.json_config.content)
}
}