-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-grafana.js
More file actions
41 lines (34 loc) · 928 Bytes
/
setup-grafana.js
File metadata and controls
41 lines (34 loc) · 928 Bytes
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
// Script to configure Grafana with Prometheus data source
const https = require('https');
const http = require('http');
const grafanaUrl = 'http://localhost:3000';
const prometheusUrl = 'http://localhost:9090';
// Create Prometheus data source
const dataSourceConfig = {
name: 'Prometheus',
type: 'prometheus',
url: prometheusUrl,
access: 'proxy',
isDefault: true
};
const options = {
hostname: 'localhost',
port: 3000,
path: '/api/datasources',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic YWRtaW46YWRtaW4=' // admin:admin in base64
}
};
const req = http.request(options, (res) => {
console.log(`Status: ${res.statusCode}`);
res.on('data', (d) => {
console.log('Response:', d.toString());
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
req.write(JSON.stringify(dataSourceConfig));
req.end();