天天看點

influxdb+grafana監控網絡情況

日常的伺服器監控中,網絡監控是必不可少的,而influxdb+grafana是我在工作中經常用到的,接下來做個部署流程記錄,以下伺服器基于centos7:

1.安裝influxdb

下載下傳安裝包進行yum本地安裝

#wget https://dl.influxdata.com/influxdb/releases/influxdb-1.2.2.x86_64.rpm  
#yum localinstall influxdb-1.2.2.x86_64.rpm
#vim /etc/influxdb/influxdb.conf
           

接下來更改influxdb的配置檔案,主要是http子產品,其他子產品預設配置就好

[http]
  enabled = true
  bind-address = ":8086"  
  auth-enabled = false       
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/influxdb.pem"
  max-row-limit = 10000
           

2.啟動influxdb,并且使用

#systemctl start influxdb 
#systemctl enable influxdb
#influx      (進入influxdb控制台)
>create database network (建立資料庫)
>show databases  (列出資料庫)
>drop database network (删除資料庫)
>use network (進入資料庫)
>create measurement ping-loss (建立ping-loss表)
>show measurements (列出所有表)
>drop measurement ping-loss (删除表)
>select * from ping-loss (查表)
>insert ping-loss, region=vn, loss=20 (插入資料,鍵值對形式指派)
>select * from ping-loss where region=vn

>shouw users (檢視使用者)
>create user "username" with password 'password' (建立普通使用者)
>create user "username" with password 'password' with all privileges (建立管理者使用者)
>drop user "username" (删除使用者)
>auth (使用者認證,設定密碼後的登入認證)
           

3.腳本監控ping丢包和延時

把監控收集的ping值入庫到influxdb

#!/bin/bash

#!/bin/bash
declare -A dic

dic=([VN]="ip1" [ID]="ip2" [BR]="ip3" ...)  #字典

for key in $(echo ${!dic[*]});do
    ping -fc10 ${dic[$key]} > /tmp/ping_result/ping${key}log
    b=`cat /tmp/ping_result/ping${key}log |grep packet|awk -F "," '{print $3}'|awk -F "%" '{print $1}'|sed 's/^[ \t]*//g'`
    c=`cat /tmp/ping_result/ping${key}log  |grep rtt |awk -F',' '{print $1}' |awk -F'=' '{print $2}' |cut -d'/' -f2`
    curl -i -X POST "http://$influxdb_ip:port/write?db=network" -u test:network --data-binary "SG_${key}loss loss=$b"
    curl -i -X POST "http://$influxdb_ip:port/write?db=network"  -u test:network  --data-binary "SG_${key}laten laten=$c"
           

4.安裝grafana

我就使用預設的配置啟動grafana

#wget https://dl.grafana.com/oss/release/grafana-6.4.3-1.x86_64.rpm
#yum localinstall grafana-6.4.3-1.x86_64.rpm
#systemctl start grafana-server
#systemctl enable grafana-server
           

5.grafana展示出圖

配置datasource

influxdb+grafana監控網絡情況

配置好資料源,然後添加面闆展示資料

influxdb+grafana監控網絡情況

最後的結果如下

influxdb+grafana監控網絡情況

最後通路grafana的web頁面登入,預設使用者名密碼是admin,端口是3000.

繼續閱讀