Create a beautiful Grafana dashboard with realtime performance stats:
Install InfluxDB and Grafana
1 2 3 4
Versions at the time of this writing:
- InfluxDB: 1.0
- Grafana: 3.1.1
- 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”
Edit telegraf conf
/usr/local/etc/telegraf.conf in your favorite text editor and uncomment the entire statsd server section:
1 2 3 4 5 6
Set the database to use the “db” database created earlier, under the
outputs.influxdb section of the telegraf config
1 2 3 4 5 6 7 8
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”.
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.
- Install the g2s client library via:
- Here is some sample code to push data points to the
statdstelegraf process from your go program:
1 2 3 4 5 6 7 8 9 10
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
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).