The Grafana Web UI should be available at localhost:3000 — login with admin/admin
The InfluxDB Web UI should be available at localhost:8083
Create database on influx
Create db named “db”
12
$ influx
> create database db
Edit telegraf conf
Open /usr/local/etc/telegraf.conf in your favorite text editor and uncomment the entire statsd server section:
123456
# Statsd Server
[[inputs.statsd]]
## Address and port to host UDP listener on
service_address = ":8125"
.. etc ..
Set the database to use the “db” database created earlier, under the outputs.influxdb section of the telegraf config
12345678
[[outputs.influxdb]]
## The full HTTP or UDP endpoint URL for your InfluxDB instance.
## Multiple urls can be specified as part of the same cluster,
## this means that only ONE of the urls will be written to each interval.
# urls = ["udp://localhost:8089"] # UDP endpoint example
urls = ["http://localhost:8086"] # required
## The target database for metrics (telegraf will create it if not exists).
database = "db" # required
Restart telegraf
1
brew services restart telegraf
Create Grafana Data Source
Open the Grafana Web UI in your browsers (login with admin/admin)
Use the following values:
Create Grafana Dashboard
Go to Dashboards / + New
Click the green thing on the left, and choose Add Panel / Graph
Delete the test metric, which is not needed, by clicking the trash can to the right of “Test Metric”
Under Panel / Datasource, choose db, and then hit + Add Query, you will end up with this
Push sample data point from command line
In order for the field we want to show up on the grafana dashboard, we need to push some data points to the telegraf statds daemon.
Run this in a shell to push the foo:1|c data point, which is a counter with value increasing by 1 on the key named “foo”.
1
while true; do echo "foo:1|c" | nc -u -w0 127.0.0.1 8125; sleep 1; echo "pushed data point"; done
Create Grafana Dashboard, Part 2
Under select measurement, choose foo from the pulldown
On the top right of the screen near the clock icon, choose “Last 5 minutes” and set Refreshing every to 5 seconds
You should see your data point counter being increased!
Add Go client library and push data points
Here’s how to update to your golang application to push new datapoints.
This will push statsd “timing” data points under the key “open_website”, with the normal sample rate (set to 0.1 to downsample and only take every 10th sample). Run the code in a loop and it will start pushing stats to statsd.
Now, create a new Grafana dashboard with the steps above, but from the select measurement field choose open_website, and under SELECT choose field (mean) instead of field (value).
It didn’t make sense, because they were accessing different fields of the Replication — one was writing to r.EventChan while the other was reading from r.Stats.
I started wandering around the Couchbase office looking for help, and got Steve Yen to help me.
He was asking me about using a pointer receiver vs a value receiver here, and then we realized that by using a value reciever it was copying all the fields, and therefore reading all of the fields, including the r.EventChan field that the other goroutine was concurrently writing to! Hence, the data race that was subtly caused by using a value receiver..
The fix was to convert this over to a pointer reciever, and the data race disappeared!
Check the logs via docker logs <container-id> and they should look something like this
Edit AWS security group
With your instance selected, look for the security groups in the instance details:
Add a new inbound port with the following settings:
Protocol TCP
Port Range 80
Source 0.0.0.0
It should look like this when you’re done:
Verify it’s running
Paste the hostname of your aws instance into your browser (eg, http://ec2-54-163-185-45.compute-1.amazonaws.com), and you should see a page like this:
Login
If you click the login button, you should see:
And then:
Activate a repository
Click one of the repositories you have access to, and you should get an “activate now” option:
which will take you to your project home screen:
Add a .drone.yml file to the root of the repository
In the repository you have chosen (in my case I’m using tleyden/sync_gateway, which is a golang project, and may refer to it later), add a .drone.yml file to the root of the repository with:
123456
build:
image: golang
commands:
- go get
- go build
- go test
Commit your change, but do not push to github yet, that will be in the next step.
and in your drone UI you should see a build in progress:
when it finishes, you’ll see either a pass or a failure. If you get a failure (which I did), it will look like this:
Manually triggering another build
In my case, the above failure was due to a dependency not building. Since nothing else needs to be pushed to the repo to fix the build, I’m just going to manually trigger a build.
On the build failure screen above, there is a Restart button, which triggers a new build.
Now it works!
Setup the Drone CLI
I could run this on my OSX workstation, but I decided to run this on a linux docker container. The rest of the steps assume you have spun up and are inside a linux docker container.
After doing some research, I decided to try gvt since it seemed simple and well documented, and integrated well with exiting tools like go get.
12
$ export GO15VENDOREXPERIMENT=1
$ go get -u github.com/FiloSottile/gvt
Go get target project to be updated
I’m going to update todolite-appserver to use vendored dependencies for some of it’s dependencies, just to see how things go.
1
$ go get -u github.com/tleyden/todolite-appserver
Vendor dependencies
I’m going to vendor the dependency on kingpin since it has transitive dependencies of it’s own (github.com/alecthomas/units, etc). gvt handles this by automatically pulling all of the transitive dependencies.
Also, I updated the README to tell users to set the GO15VENDOREXPERIMENT=1 variable:
123
$ export GO15VENDOREXPERIMENT=1
$ go get -u github.com/tleyden/todolite-appserver
$ todolite-appserver --help
but the instructions otherwise remained the same. If someone tries to use this but forgets to set GO15VENDOREXPERIMENT=1 in Go 1.5, it will still work, it will just use the kingpin dependency in the $GOPATH rather than the vendor/ directory. Ditto for someone using go 1.4 or earlier.
Removing a vendored dependency
As it turns out, I don’t even need kingpin in this project, since I’m using cobra. The kingpin dependency was caused by some leftover code I forgot to cleanup.
In this case, since it was my only dependency, it was easy to identify the transitive dependencies. In general though it looks like it’s up to you as a user to track down which ones to remove. I filed gvt issue 16 to hopefully address that.
Editor annoyances
I have emacs setup using the steps in this blog post, and I’m running into the following annoyances:
When I use godef to jump into the code of vendored dependency, it takes me to source code that lives in the GOPATH, which might be different than what’s under vendor/. Also, if I edit it there, my changes won’t be reflected when I rebuild.
I usually search for things in the project via M-x rgrep, but now it’s searching through every repo under vendor/ and returning things I’m not interested in .. since most of the time I only want to search within my project.
I’m setting up a clean install of El Capitan, and want to get my Octopress blog going. However, I don’t want to install it directly on my OSX workstation — I want to have it contained in a docker container.
Install Docker
That’s beyond the scope of this blog post, but what I ended up doing on my new OSX installation was to:
$ docker run -itd -v ~/Documents/blog/:/blog tleyden5iwx/octopress /bin/bash
What’s in ~/Documents/blog/? Basically, the octopress instance I’d setup as described in Octopress Setup Part I.
Bundle install
From inside the docker container:
12
# cd /blog/octopress
# bundle install
Edit a blog post
On OSX, open up ~/Documents/blog/source/_posts/path-to-post and make some minor edits
Push source
123
# git push origin source
Username for 'https://github.com': [enter your username]
Password for 'https://username@github.com': [enter your password]
Generate and push to master
Attempt 1
12345
# rake generate
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 0.9.6. Using bundle exec may solve this.
/blog/octopress/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)
I have no idea why this is happening, but I just conceded defeat against these ruby weirdisms, wished I was using Go (and thought about converting my blog to Hugo), and took their advice and prefixed every command thereafter with bundle exec.
Attempt 2
123
# bundle exec rake generate && bundle exec rake deploy
Username for 'https://github.com': [enter your username]
Password for 'https://username@github.com': [enter your password]
This walks you through running Uniqush in the cloud (under Docker) and setting up an iOS app to receive messages via APNS (Apple Push Notification Service).
Security note: the above config has Uniqush listening on all interfaces, but depending on your setup you probably want to change that to localhost or something more restrictive.
Docker compose file
Copy and paste this content into docker-compose.yml
Run this curl command outside of the docker container to verify that Uniqush is responding to HTTP requests:
12
$ curl localhost:9898/version
uniqush-push 1.5.2
Create APNS certificate
In my case, I already had an app id for my app (com.couchbase.todolite), but push notifications are not enabled, so I needed to enable them:
Create a new push cert:
Choose the correct app id:
Generate CSR according to instructions in keychain:
This will save a CSR on your file system, and the next wizard step will ask you to upload this CSSR and generate the certificate. Now you can download it:
Double click the downloaded cert and it will be added to your keychain.
This is where I got a bit confused, since I had to also download the cert from the app id section — go to the app id and hit “Edit”, then download the cert and double click it to add to your keychain. (I’m confused because I thought these were the same certs and this second step felt redundant)
Create and use provisioning profile
Go to the Provisioning Profiles / Development section and hit the “+” button:
Choose all certs and all devices, and then give your provisioning profile an easy to remember name.
Download this provisioning profile and double click it to install it.
In xcode under Build Settings, choose this provisioning profile:
Register for push notifications in your app
Add the following code to your didFinishLaunchingWithOptions::
If you now run this app on a simulator, you can expect an error like Error registering device token. Push notifications will not workError.
Run the app on a device you should see a popup dialog in the app asking if it’s OK to receive push notifications, and the following log messages in the xcode console:
Open keychain, select the login keychain and the My Certificates category:
Right click on the certificate (not the private key) “Apple Development Push Services: (your app id)”
Choose Export “Apple Development Push Services: (your app id)″.
Save this as apns-prod-cert.p12 file somewhere you can access it.
When it prompts you for a password, leave it blank (or add one if you want, but this tutorial will assume it was left blank)
Repeat with the private key (in this case, TodoLite Push Notification Cert) and save it as apns-prod-key.p12.
Now they need to be converted from .p12 to .pem format.
123
$ openssl pkcs12 -clcerts -nokeys -out apns-prod-cert.pem -in apns-prod-cert.p12
Enter Import Password: <return>
MAC verified OK
1234
$ openssl pkcs12 -nocerts -out apns-prod-key.pem -in apns-prod-key.p12
Enter Import Password:
MAC verified OK
Enter PEM pass phrase: hello <return>
Remove the PEM passphrase:
123
$ openssl rsa -in apns-prod-key.pem -out apns-prod-key-noenc.pem
Enter pass phrase for apns-prod-key.pem: hello
writing RSA key
Add PEM files to Uniqush docker container
When you call the Uniqush REST API to add a Push Service Provider, it expects to find the PEM files on it’s local file system. Use the following commands to get these files into the running container in the /tmp directory:
Using the cleaned up device token from the previous step 281c87101b029fdb16c8e13439436336116001cebf6519e68edefab523dab1e9, create a subscriber with the name mytestsubscriber via:
First, you need to either background your app by pressing the home button, or add some code like this so that an alert will be shown if the app is foregrounded.
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GRID K520"
CUDA Driver Version / Runtime Version 6.5 / 6.5
... snip ...
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GRID K520
Result = PASS
Verify: Find all your nvidia devices
1
$ ls -la /dev | grep nvidia
You should see:
123
crw-rw-rw- 1 root root 195, 0 Oct 25 19:37 nvidia0
crw-rw-rw- 1 root root 195, 255 Oct 25 19:37 nvidiactl
crw-rw-rw- 1 root root 251, 0 Oct 25 19:37 nvidia-uvm
Go to the AWS console, find the EC2 instance, and find the instance public ip address. It should look like this: ec2-54-161-201-224.compute-1.amazonaws.com. The rest of the instructions will refer to this as
ssh ec2-user@<instance public ip> (this should let you in without prompting you for a password. if not, you chose a key when you launched that you don’t have locally)
2015-11-03T19:37:05.384Z ==== Couchbase Sync Gateway/1.1.0(28;86f028c) ====
2015-11-03T19:37:05.384Z Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <http://localhost:8091>
2015-11-03T19:37:05.384Z Opening Couchbase database sync_gateway on <http://localhost:8091>
2015/11/03 19:37:05 Trying with selected node 0
2015/11/03 19:37:05 Trying with selected node 0
2015-11-03T19:37:05.536Z Using default sync function 'channel(doc.channels)' for database "sync_gateway"
2015-11-03T19:37:05.536Z Reset guest user to config
2015-11-03T19:37:05.536Z Starting profile server on
2015-11-03T19:37:05.536Z Starting admin server on 127.0.0.1:4985
2015-11-03T19:37:05.550Z Starting server on localhost:4984 ...
Verify via curl
From your workstation:
1
$ curl http://<instance public ip>:4984/sync_gateway/
For more advanced Sync Gateway configuration, you will want to create a JSON config file on the EC2 instance itself and pass that to Sync Gateway when you launch it, or host your config JSON on the internet somewhere and pass Sync Gateway the URL to the file.
View Couchbase Server UI
In order to login to the Couchbase Server UI, go to :8091 and use: