Telegraf+Influxdb+grafana 輕量級服務器監控 前言:公司要做監控,指定要用Grafana+Telegraf+Influxdb監控,研究了幾天遇到了很多坑,在此記錄下配置監控服務器的部署 一、創建存放軟件目錄 ## /software/grafana [root@localhost /]# mkdir -p /software/grafana [root@localhost /]# wget https://dl.influxdata.com/telegraf/releases/telegraf-1.6.0-1.x86_64.rpm [root@localhost /]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.2.x86_64.rpm [root@localhost /]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.4-1.x86_64.rpm
二、安裝 [root@localhost /software/grafana]# rpm -ivh grafana-4.6.3-1.x86_64.rpm [root@localhost /software/grafana]# rpm -ivh influxdb-1.5.2.x86_64.rpm [root@localhost /software/grafana]# rpm -ivh telegraf-1.6.0-1.x86_64.rpm [root@localhost /software/grafana]# systemctl start grafana-server [root@localhost /software/grafana]# systemctl start influxdb [root@localhost /software/grafana]# systemctl start telegraf 三、設置開啓啓動; [root@localhost /software/grafana]# systemctl enable grafana-server [root@localhost /software/grafana]# systemctl enable influxdb [root@localhost /software/grafana]# systemctl enable telegraf 四、查看啓動情況 [root@localhost /software/grafana]# systemctl status influxdb influxdb.service - InfluxDB is an open-source, distributed, time series database Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled) Active: active (running) since 三 2018-11-07 14:36:38 CST; 2 days ago Docs: https://docs.influxdata.com/influxdb/ Main PID: 25855 (influxd) CGroup: /system.slice/influxdb.service └─25855 /usr/bin/influxd -config /etc/influxdb/influxdb.conf 五、進入數據庫 [root@localhost /software/grafana]# influx
六、配置採取數據文件:telegraf.conf [root@localhost /software/grafana]# sed '/#.*$/d; /^ *$/d' /etc/telegraf/telegraf.conf 採集數據到influxdb: [[outputs.influxdb]] urls = ["http://localhost:8086"] # required,這個url改成自己host database = "telegraf" # 這個會在influx庫創建一個庫
七、頁面訪問grafana (默認賬號和密碼都是 admin) 你要配置grafana連接數據庫的賬號和密碼 訪問地址:http:/youip:3000
八、Tomcat
由於telegraf收集Tomcat相關數據需要配置訪問權限,這裏我們選擇Tomcat7做配置說明。
修改位於conf下的tomcat-users.xml文件:
<tomcat-users> <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status"/> </tomcat-users> 重啓tomcat
九、配置採集tomcat 數據(配置文件:/etc/telegraf/telegraf.conf ) 服務器有多個tomcat要做標籤分類如下;host = "tomcat-server" host = "tomcat-bbs"
十、導入模板或自己添加圖表; 這是模板地址:https://grafana.com/dashboards
然後從別人編輯好面板複製https://grafana.com/dashboards/928ID到上面
出圖效果如下:
模板自己也能配置如下:
點擊 graph,點擊panel Title 在點擊 Edit
i出現如下配置參數 選擇 DataSource 你的數據庫名字
根據自己服務器的情況做配置。