Collectd & InfluxDb & Grafana 之一: 常用系统统计

Collectd

安装

apt-get install collected

配置

# vi /etc/collectd/collectd.conf
Hostname "localhost"
FQDNLookup true
Interval 5
Timeout         4
LoadPlugin syslog

        LogLevel info

LoadPlugin battery
LoadPlugin cpu
LoadPlugin cpufreq
LoadPlugin df
LoadPlugin disk
LoadPlugin entropy
LoadPlugin interface
LoadPlugin irq
LoadPlugin load
LoadPlugin memory
LoadPlugin network
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin swap
LoadPlugin users

        FSType rootfs
        FSType sysfs
        FSType proc
        FSType devtmpfs
        FSType devpts
        FSType tmpfs
        FSType fusectl
        FSType cgroup
        IgnoreSelected true
        ReportByDevice true
        ReportInodes true
        ValuesAbsolute true
        ValuesPercentage true


        Interface "eno1"
        IgnoreSelected false

# 网络插件, 把Collectd搜集的数据通过接口eno1发往192.168.212.127:25826

       
                Interface "eno1"
        


        DataDir "/var/lib/collectd/rrd"


        Filter "*.conf"

InfluxDB

安装

wget https://dl.influxdata.com/influxdb/releases/influxdb_1.0.0_amd64.deb
sudo dpkg -i influxdb_1.0.0_amd64.deb

启动

root@ubuntu:~# service influxdb status
influxdb process is not running [ FAILED ]
root@ubuntu:~# service influxdb start
Starting influxdb...
influxdb process was started [ OK ]

运行客户端influx创建数据库

➜  ~ influx
> CREATE DATABASE "collectdb"

编辑 /etc/influxdb/influxdb.conf, 找到 [[collectd]]部分, 修改如下

[[collectd]]
  enabled = true
  # 在 `192.168.212.127:25826` 上监听从 Collectd 发过来的数据.
  bind-address = "192.168.212.127:25826" 
  database = "collectdb"
  typesdb = "/usr/share/collectd/types.db"
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "10s"
  read-buffer = 0

重启

service influxdb restart

Grafana

安装

# vi /etc/apt/source.list.d/grafana.list
deb https://packagecloud.io/grafana/stable/debian/ wheezy main
curl https://packagecloud.io/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana

配置

http://docs.grafana.org/insta...

网络流量统计

切换编辑模式, 然后输入自定义SQL查询

输入查询语句

SELECT derivative("value") AS "value" FROM "interface_rx" WHERE "host" = 'localhost' AND "type" = 'if_octets' AND "instance" = 'eno1'

函数 derivative 意为导数, 微积分中的概念. value 为传输总量(字节), derivative("value")value 在时间上的增量.

其中

  • host = localhost

  • type = if_octets

  • instance = eno1

系统负载

SELECT mean("value") FROM "load_longterm" WHERE "host" = 'localhost' AND $timeFilter GROUP BY time($interval) fill(null)
SELECT mean("value") FROM "load_midterm" WHERE "host" = 'localhost' AND $timeFilter GROUP BY time($interval) fill(null)
SELECT mean("value") FROM "load_shortterm" WHERE "host" = 'localhost' AND $timeFilter GROUP BY time($interval) fill(null)

内存用量

SELECT mean("value") FROM "memory_value" WHERE "type_instance" = 'used' AND $timeFilter GROUP BY time($interval) fill(null)

你可能感兴趣的:(grafana,influxdb)