Skip to content
Snippets Groups Projects
Verified Commit 8a558256 authored by Markus Koller's avatar Markus Koller
Browse files

Create missing data source for InfluxDB Internal

parent 36329fcd
No related branches found
No related tags found
1 merge request!242Grafana improvements
#!/usr/bin/env ruby
require 'socket'
require 'net/http'
require 'json'
 
def main
host = '127.0.0.1'
Loading
Loading
@@ -11,21 +12,8 @@ def main
 
abort "#$0: could not connect to Grafana at #{host}:#{port}" unless wait_socket(host, port)
 
http = Net::HTTP.new(host, port)
request = Net::HTTP::Post.new('/api/datasources')
request.basic_auth('admin', 'admin')
request.add_field('Content-Type', 'application/json')
request.body = <<EOS
{
"name": "InfluxDB",
"type": "influxdb",
"url": "http://localhost:8086",
"access": "direct",
"database": "gitlab",
"isDefault": true
}
EOS
puts http.request(request).body
create_data_source(host, port, name: 'InfluxDB', database: 'gitlab', isDefault: true)
create_data_source(host, port, name: 'InfluxDB Internal', database: '_internal')
ensure
[grafana_pid, db_pid].each do |pid|
Process.kill('TERM', pid)
Loading
Loading
@@ -33,6 +21,21 @@ ensure
end
end
 
def create_data_source(host, port, options)
options = {
type: 'influxdb',
url: 'http://localhost:8086',
access: 'direct'
}.merge(options)
http = Net::HTTP.new(host, port)
request = Net::HTTP::Post.new('/api/datasources')
request.basic_auth('admin', 'admin')
request.add_field('Content-Type', 'application/json')
request.body = JSON.dump(options)
puts http.request(request).body
end
def wait_socket(host, port)
30.times do
begin
Loading
Loading
@@ -49,4 +52,4 @@ if !ARGV.empty?
abort "Usage: #$0"
end
 
main
\ No newline at end of file
main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment