Deploy Graphite with Grafana on Ubuntu 14.04 (Part Ⅱ)

Grafana 是 Graphite仪表盘和图形编辑器。Grafana 是开源的、功能齐全的度量仪表盘和图形编辑器,支持 Graphite,InfluxDB 和 OpenTSDB。

Grafana 主要特性:

  • 灵活丰富的图形化选项;
  • 可以混合多种风格;
  • 支持白天和夜间模式;
  • 多个数据源;
  • Graphite 和 InfluxDB 查询编辑器等等。

    Install and Configure Grafana

1. Add Grafana’s repository to sources.list:
添加安装Grafana所需的源

1
echo 'deb https://packagecloud.io/grafana/stable/debian/ wheezy main' |  sudo tee -a /etc/apt/sources.list

2. Add the Package Cloud key to install signed packages:

1
curl https://packagecloud.io/gpg.key | sudo apt-key add -

3. Update apt and install Grafana:
更新源,通过apt-get安装Grafana

1
sudo apt-get update && sudo apt-get install grafana

4. Configure Grafana to use the PostgreSQL database created earlier:
配置Grafana使用之前创建的PostgreSQL数据库
File excerpt: /etc/grafana/grafana.ini

1
2
3
4
5
6
7
[database]
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = postgres
host = 127.0.0.1:5432
name = grafana
user = graphite
password = graphiteuserpassword

5. Also in /etc/grafana/grafana.ini, configure the domain and root_url, and set a strong admin password and secret key:
配置WEB端口及帐号密码:
File excerpt: **/etc/grafana/grafana.ini

1
2
3
4
5
6
7
8
9
10
11
12
[server]
protocol = http
http_addr = 127.0.0.1
http_port = 3000
domain = example.com
enforce_domain = true
root_url = %(protocol)s://%(domain)s/

[security]
admin_user = admin
admin_password = SecureAdminPass
secret_key = somelongrandomstringkey

6. Enable proxy modules for Apache reverse proxying to work:

1
sudo a2enmod proxy proxy_http xml2enc

7. Create an Apache site configuration file to proxy requests to Grafana. Remember to change example.com to your own domain:
通过Apache 使用80端口对Grafana进行访问
File excerpt: /etc/apache2/sites-available/apache2-grafana.conf

1
2
3
4
5
6
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ServerName example.com
</VirtualHost>

8. Enable Grafana’s site configuration with:
启用Grafana的Apache配置:

1
sudo a2ensite apache2-grafana

9. Configure Grafana to run after boot and then start service:
设置Grafana开机启动:

1
2
sudo update-rc.d grafana-server defaults 95 10
sudo service grafana-server start

Restart Apache to load the new modules and configuration changes:
重启Apache,以应用最新配置:

1
sudo service apache2 restart

At this point, you should be able to open your Linode’s domain or IP address in a browser to see Grafana’s login page.
至些,可以从浏览中通过访问主机80端口来访问Grafana界面。

Add a Graphite Data Source to Grafana

为Grafa添加数据源,即连接Graphite
1. Log in into Grafana using the admin credentials you specified in grafana.ini above.
使用前面设置的帐号密码来登录Grafana,默认帐号密码是:admin/admin
2. Click on Data Sources and select Add new. Fill in all the fields as shown in the screenshot below:
Add Data Source dialog

Click Save to create the new Data Source.
3. Now, before creating a graph, add more test data for the test.count metric by again running:
在添加新的监控图表之前,生成一份新测试数据:

1
for i in 4 6 8 16 2; do echo "test.count $i `date +%s`" | nc -q0 127.0.0.1 2003; sleep 6; done

4. Create a new dashboard by clicking the Home button and then + New:
添加一个Dashboard:
Create new dashboard

5. Add a Graph panel to the newly created dashboard:
在新创建的dashboard中添加新图:
Create new graph panel

6. Edit the Graph panel properties by clicking the tab with the words no title (click here). Then click Edit:
向图中添加数据
Edit graph panel

7. Make sure the graphite data source you’ve created is chosen in the dropdown box at the bottom right (marked as 1 in the screenshot below). In the dropdown at the top right corner (marked as 2), choose Last 15 minutes.
Click select metric. Choose test and then count (marked as 3) to add the test metric you previously created. At this point, the sample data should appear on the graph.
Finally, click the Save button (marked as 4) to save the dashboard you just created.
选择需要监控的数据源。
一图胜千言。
Add test metric to the panel

Grafana图片界面展示:http://play.grafana-zabbix.org/dashboard/db/grafana-zabbix-demo

The pure English Version: https://www.linode.com/docs/uptime/monitoring/deploy-graphite-with-grafana-on-ubuntu-14-04

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
下面是一引起扩展资料,有兴趣的可以做为扩展阅读。