sudo yum install influxdb sudo systemctl start influxdb
判斷已經安裝完成,輸入下面的命令,能夠進入influxDB的界面node
> influx
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.9.1_linux_amd64.tar.gz tar xf telegraf-1.9.1_linux_amd64.tar.gz telegraf -version
config: /etc/telegraf/telegraf.conflinux
sudo systemctl start telegraf sudo systemctl status telegraf sudo systemctl enable telegraf
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.2-1.x86_64.rpm
systemctl enable grafana-server systemctl start grafana-server
# 配置文件 /etc/grafana/grafana.ini # systemd服務名 grafana-server.service # 默認日誌文件 /var/log/grafana/grafana.log # 默認數據庫文件 /var/lib/grafana/grafana.db
添加插件nginx
sudo grafana-cli plugins install grafana-clock-panel sudo systemctl restart grafana-server
For Mode there are three options:git
The default option is Time and means the x-axis represents time and that the data is grouped by time (for example, by hour or by minute).github
The Series option means that the data is grouped by series and not by time. The y-axis still represents the value.
The Histogram option converts the graph into a histogram. A Histogram is a kind of bar chart that groups numbers into ranges,
often called buckets or bins.
Taller bars show that more data falls in that range. Histograms and buckets are described in more detail here.正則表達式
Variables are shown as dropdown select boxes at the top of the dashboard. These dropdowns make it easy to change the data being displayed in your dashboard.redis
時間間隔docker
1. 選擇 New 按鈕新建一個模板變量 2. 選擇 Interval 變量類型,咱們能夠用這種變量表達時間間隔,同時設置 Name 和 Label,Name 是變量名稱,實際引用的時候用$變量名稱進行引用;Label 自己無實際做用,主要是用來展現在界面,讓用戶更加容易理解的。 3. 能夠看到在 Values 中,已經有大量預置的時間間隔,咱們能夠在其中增長,諸如 1m(1分鐘),1h(1小時),1d(1天)等時間間隔變量 在界面,咱們能夠見到已經生成了名爲時間間隔的下拉框列表,列表中包括了咱們設置的時間間隔預設值 4. 將時序查詢的 interval 設置爲 $t (t 爲咱們設置的變量Name)。此時在下拉框裏選擇不一樣的時間間隔,圖表將隨之進行切換。
基於查詢結果的下拉列表數據庫
前置步驟請參考時間間隔變量設置 選擇Query 類型 Data source 選擇你查詢的目標數據源 Query 是查詢全部可能值的查詢語句,ES/Logdb 的查詢方式是{"find": "terms", "field": "status"},其中status 是咱們查詢的目標字段,在這裏能夠替換成你須要的字段。更深刻的語法請參考 ES 官方文檔。 Regex 能夠選擇對於返回的狀態值進行正則表達式過濾 Sort 選擇排序方式 Multi-value 控制下拉框是否能夠支持多選,若是不選中則只能單選 Include all value 控制是否能夠支持All選項,支持全選全部的值,只在多選的模式下有效果 Preview of values 能夠預覽這個字段的全部值
templatingvim
# folder that contains provisioning config files that grafana will apply on startup and while running. ;provisioning = conf/provisioning
/etc/grafana/provisioning/dashborads
and /etc/grafana/provisioning/databases
for example, nodename
Custom Variables
,name as nodename
var-nodename=「test」
,such asUse Url http://servername:3000/dashboard/db/dashboard?refresh=10s&var-nodename=「test」
WHERE nodename =$nodename
you can see the output
select * from table where nodename ="test"
grafana配置nginx反向代理
將grafana配到www.myserver.com域名的/grafana/的location下
location /grafana/ { proxy_pass http://grafana_server:3000/; proxy_set_header Host $host; }
#在/etc/grafana/grafana.ini配置文件中修改 domain = www.myserver.com root_url = %(protocol)s://%(domain)s/grafana
#Configuration for influxdb server to send metrics to [[outputs.influxdb]] urls = [「http://1x.xxx:8086」] #influxdb地址 database = 「telegraf_ali」 # required #influxdb數據庫 retention_policy = 「」#數據保留策略 write_consistency = 「any」 #數據寫入策略,僅適用於集羣模式 timeout = 「5s」 #寫入超時策略 username = 「telegraf_ali」 #數據庫用戶名 password = 「gPHhbeh」 #數據庫密碼 #user_agent = 「telegraf」 #採集器代理名稱
influxdb+telegraf
> influx > use telegraf; > SHOW TAG VALUES FROM system WITH KEY=host # 能夠看到一臺主機的信息
telegraf
telegraf
influxdb
地址,使用默認telegraftelegraf
機器進入A機器
> influx > use telegraf; > SHOW TAG VALUES FROM system WITH KEY=host
POLICY
> CREATE RETENTION POLICY "2h0m0s" ON "telegraf" DURATION 2h REPLICATION 1 DEFAULT > SHOW RETENTION POLICIES ON telegraf name duration shardGroupDuration replicaN default ---- -------- ------------------ -------- ------- autogen 0s 168h0m0s 1 false 2h0m0s 2h0m0s 1h0m0s 1 true
SELECT time,host,usage_system FROM "autogen".cpu limit 2 name: cpu time host usage_system ---- ---- ------------ 1526008670000000000 VM_42_233_centos 1.7262947210419817 1526008670000000000 VM_42_233_centos 1.30130130130254
SELECT 100 - usage_idel FROM "autogen"."cpu" WHERE time > now() - 1m and "cpu"='cpu0'
SHOW MEASUREMENTS --查詢當前數據庫中含有的表 SHOW FIELD KEYS --查看當前數據庫全部表的字段 SHOW series from pay --查看key數據 SHOW TAG KEYS FROM "pay" --查看key中tag key值 SHOW TAG VALUES FROM "pay" WITH KEY = "merId" --查看key中tag 指定key值對應的值 SHOW TAG VALUES FROM cpu WITH KEY IN ("region", "host") WHERE service = 'redis' DROP SERIES FROM <measurement_name[,measurement_name]> WHERE <tag_key>='<tag_value>' --刪除key SHOW CONTINUOUS QUERIES --查看連續執行命令 SHOW QUERIES --查看最後執行命令 KILL QUERY <qid> --結束命令 SHOW RETENTION POLICIES ON mydb --查看保留數據 查詢數據 SELECT * FROM /.*/ LIMIT 1 --查詢當前數據庫下全部表的第一行記錄 select * from pay order by time desc limit 2 select * from db_name."POLICIES name".measurement_name --指定查詢數據庫下數據保留中的表數據 POLICIES name數據保留 刪除數據 delete from "query" --刪除表全部數據,則表就不存在了 drop MEASUREMENT "query" --刪除表(注意會把數據保留刪除使用delete不會) DELETE FROM cpu DELETE FROM cpu WHERE time < '2000-01-01T00:00:00Z' DELETE WHERE time < '2000-01-01T00:00:00Z' DROP DATABASE 「testDB」 --刪除數據庫 DROP RETENTION POLICY "dbbak" ON mydb --刪除保留數據爲dbbak數據 DROP SERIES from pay where tag_key='' --刪除key中的tag SHOW SHARDS --查看數據存儲文件 DROP SHARD 1 SHOW SHARD GROUPS SHOW SUBSCRIPTIONS
- [Puppet](https://forge.puppet.com/puppet/grafana) - [Ansible](https://github.com/cloudalchemy/ansible-grafana) - [Chef](https://github.com/JonathanTron/chef-grafana) - [Saltstack](https://github.com/salt-formulas/salt-formula-grafana) - [Jsonnet](https://github.com/grafana/grafonnet-lib/) - [quick install](https://github.com/samuelebistoletti/docker-statsd-influxdb-grafana)
Centos 7 docker 啓動grafana容器報"iptables No chain/target/match by that name"
docker run -d -p 3000:3000 grafana/grafana:5.1.0 Error response from daemon: Cannot start container 565c06efde6cd4411e2596ef3d726817c58dd777bc5fd13762e0c34d86076b9e: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3888 -j DNAT --to-destination 192.168.42.11:3888 ! -i docker0: iptables: No chain/target/match by that name
vim /etc/sysconfig/iptables
*nat :PREROUTING ACCEPT [27:11935] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [598:57368] :POSTROUTING ACCEPT [591:57092] :DOCKER - [0:0] -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :DOCKER - [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -s 10.0.0.0/8 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT -A INPUT -s 172.16.0.0/12 -j ACCEPT -A INPUT -s 192.168.0.0/16 -j ACCEPT -A INPUT -p icmp -m icmp --icmp-type 8 -j DROP -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 36091 -j ACCEPT -A INPUT -j DROP -A FORWARD -j DROP -A OUTPUT -j ACCEPT COMMIT
卸載命令:
[root@localhost shared]# rpm -q influxdb influxdb-0.8.7-1.x86_64 [root@localhost shared]# rpm -e influxdb [root@localhost shared]# rpm -q influxdb package influxdb is not installed
參數說明:
首先經過 rpm -q <關鍵字> 能夠查詢到rpm包的名字
而後 調用 rpm -e <包的名字> 刪除特定rpm包
若是遇到依賴,沒法刪除,使用 rpm -e --nodeps <包的名字> 不檢查依賴,直接刪除rpm包
若是剛好有多個包叫一樣的名字,使用 rpm -e --allmatches --nodeps <包的名字> 刪除全部相同名字的包, 並忽略依賴
刪除完後,清除已有文件:
[root@localhost opt]# ls influxdb [root@localhost opt]# rm -rf influxdb [root@localhost opt]# ls
處理端口占用
name=$(lsof -i:8086|tail -1|awk '"$1"!=""{print $2}') if [ -z $name ] then echo "No process can be used to killed!" exit 0 fi id=$(lsof -i:8086|tail -1|awk '"$1"!=""{print $2}') kill -9 $id echo "Process name=$name($id) kill!" exit 0
移除命令
sudo yum remove grafana
sudo yum remove telegraf