Last active
October 30, 2017 07:09
-
-
Save virtualstaticvoid/b91811ef0425c4e9defd to your computer and use it in GitHub Desktop.
Vagrant - InfluxDb + Nginx + Grafana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant - InfluxDb + Nginx + Grafana |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'influxdb' | |
user='admin' | |
password='admin' | |
influxdb = InfluxDB::Client.new | |
influxdb.create_database('test_development') | |
influxdb.create_database_user('test_development', user, password) | |
influxdb.create_database('grafana') | |
influxdb.create_database_user('grafana', user, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.create_database(Vars.database) | |
influxdb.create_database_user(Vars.database, Vars.username, Vars.password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.delete_database(Vars.database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.delete_database_user(Vars.database, Vars.username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.get_cluster_admin_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.get_database_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.get_database_user_info(Vars.database, Vars.username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new | |
influxdb.get_database_user_list(Vars.database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new Vars.database, :username => Vars.username, :password => Vars.password | |
value = (0..360).to_a.map {|i| Math.sin(i / 10.0) * 10 }.each | |
loop do | |
data = { | |
:value => value.next | |
} | |
influxdb.write_point('random_data', data) | |
sleep 0.1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'vars' | |
require 'influxdb' | |
influxdb = InfluxDB::Client.new Vars.database, :username => Vars.username, :password => Vars.password | |
influxdb.query 'select * from /.*/' do |name, points| | |
puts "#{name} => #{points}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem 'influxdb' | |
gem 'pry' | |
gem 'pry-byebug' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
byebug (3.5.1) | |
columnize (~> 0.8) | |
debugger-linecache (~> 1.2) | |
slop (~> 3.6) | |
coderay (1.1.0) | |
columnize (0.8.9) | |
debugger-linecache (1.2.0) | |
influxdb (0.1.8) | |
json | |
json (1.8.1) | |
method_source (0.8.2) | |
pry (0.10.1) | |
coderay (~> 1.1.0) | |
method_source (~> 0.8.1) | |
slop (~> 3.4) | |
pry-byebug (2.0.0) | |
byebug (~> 3.4) | |
pry (~> 0.10) | |
slop (3.6.0) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
influxdb | |
pry | |
pry-byebug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == Configuration | |
// config.js is where you will find the core Grafana configuration. This file contains parameter that | |
// must be set before Grafana is run for the first time. | |
define(['settings'], | |
function (Settings) { | |
return new Settings({ | |
/* Data sources | |
* ======================================================== | |
* Datasources are used to fetch metrics, annotations, and serve as dashboard storage | |
* - You can have multiple of the same type. | |
* - grafanaDB: true marks it for use for dashboard storage | |
* - default: true marks the datasource as the default metric source (if you have multiple) | |
* - basic authentication: use url syntax http://username:password@domain:port | |
*/ | |
// InfluxDB example setup (the InfluxDB databases specified need to exist) | |
datasources: { | |
influxdb: { | |
type: 'influxdb', | |
url: "http://localhost:8096/db/test_development", | |
username: 'admin', | |
password: 'admin', | |
default: true | |
}, | |
grafana: { | |
type: 'influxdb', | |
url: "http://localhost:8096/db/grafana", | |
username: 'admin', | |
password: 'admin', | |
grafanaDB: true | |
}, | |
}, | |
// Graphite & Elasticsearch example setup | |
/* | |
datasources: { | |
graphite: { | |
type: 'graphite', | |
url: "http://my.graphite.server.com:8080", | |
}, | |
elasticsearch: { | |
type: 'elasticsearch', | |
url: "http://my.elastic.server.com:9200", | |
index: 'grafana-dash', | |
grafanaDB: true, | |
} | |
}, | |
*/ | |
// OpenTSDB & Elasticsearch example setup | |
/* | |
datasources: { | |
opentsdb: { | |
type: 'opentsdb', | |
url: "http://opentsdb.server:4242", | |
}, | |
elasticsearch: { | |
type: 'elasticsearch', | |
url: "http://my.elastic.server.com:9200", | |
index: 'grafana-dash', | |
grafanaDB: true, | |
} | |
}, | |
*/ | |
/* Global configuration options | |
* ======================================================== | |
*/ | |
// specify the limit for dashboard search results | |
search: { | |
max_results: 20 | |
}, | |
// default home dashboard | |
default_route: '/dashboard/file/default.json', | |
// set to false to disable unsaved changes warning | |
unsaved_changes_warning: true, | |
// set the default timespan for the playlist feature | |
// Example: "1m", "1h" | |
playlist_timespan: "1m", | |
// If you want to specify password before saving, please specify it bellow | |
// The purpose of this password is not security, but to stop some users from accidentally changing dashboards | |
admin: { | |
password: '' | |
}, | |
// Change window title prefix from 'Grafana - <dashboard title>' | |
window_title_prefix: 'Grafana - ', | |
// Add your own custom panels | |
plugins: { | |
// list of plugin panels | |
panels: [], | |
// requirejs modules in plugins folder that should be loaded | |
// for example custom datasources | |
dependencies: [], | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
location / { | |
root /vagrant/grafana; | |
index index.html; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# All Vagrant configuration is done here. The most common configuration | |
# options are documented and commented below. For a complete reference, | |
# please see the online documentation at vagrantup.com. | |
# Every Vagrant virtual environment requires a box to build off of. | |
config.vm.box = "trusty64" | |
# Disable automatic box update checking. If you disable this, then | |
# boxes will only be checked for updates when the user runs | |
# `vagrant box outdated`. This is not recommended. | |
# config.vm.box_check_update = false | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine. In the example below, | |
# accessing "localhost:8080" will access port 80 on the guest machine. | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
config.vm.network "forwarded_port", guest: 80, host: 8080 # nginx | |
config.vm.network "forwarded_port", guest: 8086, host: 8096 # influxdb | |
# Create a private network, which allows host-only access to the machine | |
# using a specific IP. | |
# config.vm.network "private_network", ip: "192.168.33.10" | |
# Create a public network, which generally matched to bridged network. | |
# Bridged networks make the machine appear as another physical device on | |
# your network. | |
# config.vm.network "public_network" | |
# If true, then any SSH connections made will enable agent forwarding. | |
# Default value: false | |
# config.ssh.forward_agent = true | |
# Share an additional folder to the guest VM. The first argument is | |
# the path on the host to the actual folder. The second argument is | |
# the path on the guest to mount the folder. And the optional third | |
# argument is a set of non-required options. | |
# config.vm.synced_folder "../data", "/vagrant_data" | |
# Provider-specific configuration so you can fine-tune various | |
# backing providers for Vagrant. These expose provider-specific options. | |
# Example for VirtualBox: | |
# | |
# config.vm.provider "virtualbox" do |vb| | |
# # Don't boot with headless mode | |
# vb.gui = true | |
# | |
# # Use VBoxManage to customize the VM. For example to change memory: | |
# vb.customize ["modifyvm", :id, "--memory", "1024"] | |
# end | |
# | |
# View the documentation for the provider you're using for more | |
# information on available options. | |
# Update APT | |
config.vm.provision :shell do |s| | |
s.inline = "sudo apt-get update" | |
end | |
# Nginx | |
config.vm.provision :shell do |s| | |
s.inline = "sudo apt-get install -y nginx" | |
end | |
# InfluxDB | |
config.vm.provision :shell do |s| | |
s.inline = <<-SCRIPT | |
cd /vagrant | |
if [ ! -f "influxdb_latest_amd64.deb" ]; then | |
wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb | |
fi | |
sudo dpkg -i influxdb_latest_amd64.deb | |
sudo /etc/init.d/influxdb start | |
SCRIPT | |
end | |
# Grafana | |
config.vm.provision :shell do |s| | |
s.inline = <<-SCRIPT | |
cd /vagrant | |
if [ ! -f "grafana-1.8.1.tar.gz" ]; then | |
wget http://grafanarel.s3.amazonaws.com/grafana-1.8.1.tar.gz | |
fi | |
tar -xzf grafana-1.8.1.tar.gz | |
mv grafana-1.8.1 grafana | |
cd grafana | |
ln -s ../grafana-config.js config.js | |
SCRIPT | |
end | |
# RVM + Ruby | |
config.vm.provision :shell, :privileged => false do |s| | |
s.inline = <<-SCRIPT | |
# RVM | |
curl -L https://get.rvm.io | bash | |
source $HOME/.rvm/scripts/rvm | |
# Ruby | |
rvm install ruby-2.1 | |
rvm use --default ruby-2.1 | |
gem install bundler | |
# App | |
cd /vagrant | |
bundle install | |
SCRIPT | |
end | |
# Grafana (Nginx configuration) | |
config.vm.provision :shell do |s| | |
s.inline = <<-SCRIPT | |
sudo adduser www-data vagrant | |
sudo rm /etc/nginx/sites-enabled/default | |
sudo ln -s /vagrant/grafana-nginx.conf /etc/nginx/sites-enabled/grafana | |
sudo nginx -s reload | |
SCRIPT | |
end | |
# Create InfluxDb databases and users | |
config.vm.provision :shell, :privileged => false do |s| | |
s.inline = <<-SCRIPT | |
cd /vagrant | |
bundle exec ruby ./create_databases.rb | |
SCRIPT | |
end | |
# Extras | |
config.vm.provision :shell do |s| | |
s.inline = "sudo apt-get install -y htop" | |
end | |
# Enable provisioning with CFEngine. CFEngine Community packages are | |
# automatically installed. For example, configure the host as a | |
# policy server and optionally a policy file to run: | |
# | |
# config.vm.provision "cfengine" do |cf| | |
# cf.am_policy_hub = true | |
# # cf.run_file = "motd.cf" | |
# end | |
# | |
# You can also configure and bootstrap a client to an existing | |
# policy server: | |
# | |
# config.vm.provision "cfengine" do |cf| | |
# cf.policy_server_address = "10.0.2.15" | |
# end | |
# Enable provisioning with Puppet stand alone. Puppet manifests | |
# are contained in a directory path relative to this Vagrantfile. | |
# You will need to create the manifests directory and a manifest in | |
# the file default.pp in the manifests_path directory. | |
# | |
# config.vm.provision "puppet" do |puppet| | |
# puppet.manifests_path = "manifests" | |
# puppet.manifest_file = "default.pp" | |
# end | |
# Enable provisioning with chef solo, specifying a cookbooks path, roles | |
# path, and data_bags path (all relative to this Vagrantfile), and adding | |
# some recipes and/or roles. | |
# | |
# config.vm.provision "chef_solo" do |chef| | |
# chef.cookbooks_path = "../my-recipes/cookbooks" | |
# chef.roles_path = "../my-recipes/roles" | |
# chef.data_bags_path = "../my-recipes/data_bags" | |
# chef.add_recipe "mysql" | |
# chef.add_role "web" | |
# | |
# # You may also specify custom JSON attributes: | |
# chef.json = { mysql_password: "foo" } | |
# end | |
# Enable provisioning with chef server, specifying the chef server URL, | |
# and the path to the validation key (relative to this Vagrantfile). | |
# | |
# The Opscode Platform uses HTTPS. Substitute your organization for | |
# ORGNAME in the URL and validation key. | |
# | |
# If you have your own Chef Server, use the appropriate URL, which may be | |
# HTTP instead of HTTPS depending on your configuration. Also change the | |
# validation key to validation.pem. | |
# | |
# config.vm.provision "chef_client" do |chef| | |
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME" | |
# chef.validation_key_path = "ORGNAME-validator.pem" | |
# end | |
# | |
# If you're using the Opscode platform, your validator client is | |
# ORGNAME-validator, replacing ORGNAME with your organization name. | |
# | |
# If you have your own Chef Server, the default validation client name is | |
# chef-validator, unless you changed the configuration. | |
# | |
# chef.validation_client_name = "ORGNAME-validator" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Vars | |
class << self | |
def database | |
'test_development' | |
end | |
def username | |
'admin' | |
end | |
def password | |
'admin' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment