logrotate测试_「测试」 - 测试环境接入netdata监控

一、netdata概述

由于今年的大环境原因,公司也是开源节流,不再增加测试服务器的审批,要物尽其用。所以对机器资源的利用率得提高,还是需要把机器资源监控起来。

之前在测试环境搭建过zabbix,但是因为服务器物理硬件损坏,这个监控就不了了之了。相比起搭建PHP的Zabbix,找了一款更为方便的监控工具Netdata。

Netdata是一款秒级数据收集与可视化呈现的Linux服务器性能监测工具,对优化应用性能,保证服务器健康运行有着极为重要的作用。

Netdata特点:

  • 高实时性,Netdata及插件为C编写,资源占用及效率都符合要求
  • 不占系统IO,除日志系统,Netdata不使用任何磁盘的IO资源,也可以通过配置文件禁用日志系统
  • 不需要root权限
  • 自带Web服务
  • 安装便捷、开箱即用,不需要额外写任何配置
  • 动态图表化显示
  • 告警系统,通过配置文件,可以配置Netdata在某些指标达到阀值时进行告警

具体参考Netdata的GitHub以及官方文档。

二、安装

A、公网安装(168环境)

# 安装依赖
yum install -y autoconf automake curl gcc git libmnl-devel libuuid-devel lm_sensors make MySQL-python nc pkgconfig python python-psycopg2 PyYAML zlib-devel

# 拉取git仓库
git clone https://github.com/netdata/netdata.git --depth=1

# 执行安装脚本
./netdata-installer.sh

# 执行中提示
It will be installed at these locations:

   - the daemon     at /usr/sbin/netdata
   - config files   in /etc/netdata
   - web files      in /usr/share/netdata
   - plugins        in /usr/libexec/netdata
   - cache files    in /var/cache/netdata
   - db files       in /var/lib/netdata
   - log files      in /var/log/netdata
   - pid file       at /var/run/netdata.pid
   - logrotate file at /etc/logrotate.d/netdata

B、内网安装(132环境)

# 132机器内网拷贝
scp -r root@10.255.242.168:/var/www/netdata /data01/soft/

# 内网环境,需要在内网部署以下文件,修改启动脚本HOST
go.d.plugin-v0.4.0.linux-amd64
config.tar.gz

# 修改ngxix.conf
server {
    listen       8001;
    server_name  10.255.242.135;
    charset utf-8;               # 避免中文乱码
    location / {
        root /data01/app/;       # 存放文件的目录
        autoindex on; # 索引
        autoindex_exact_size on; # 显示文件大小
        autoindex_localtime on;  # 显示文件时间
    }
}

vim netdata-installer.sh
http://10.255.242.135:8001/netdata/go.d.plugin/releases/download/v0.4.0/go.d.plugin-v0.4.0.linux-amd64
http://10.255.242.135:8001/netdata/go.d.plugin/releases/download/v0.4.0/config.tar.gz

# 同公网执行后续

三、集群

Netdata本身不存在主从服务,搭建集群需要在每一个节点上完整部署Netdata,流数据汇总到一台主服务器上。数据处理全部在主服务器上进行,各个节点服务器不打开19999端口供查看,只是把收集到的数据发送到主服务器上,具体参考官网文档。

A、从节点服务器

1、修改netdata.conf

vim netdata.conf

[global]
    memory mode = none
    hostname = slave-132
[web]
    mode = none
[health]
    enabled = no

关闭web,增加主机名。

2、新增stream.conf

vim stream.conf  

[stream]
    enabled = yes
    destination = 10.255.242.168:19999
    api key = 23f03114-33e9-43ed-9881-a590b8b91b6e

destination为主服务器的IP地址和netdata端口(默认19999);api key是一个uuid格式的字符串,可以使用uuidgen命令生成,主服务器需要使用。

B、主服务器

1、修改netdata.conf

vim netdata.conf
[global]
     hostname = Master

2、新增stream.conf

vim stream.conf

[23f03114-33e9-43ed-9881-a590b8b91b6e]
    enabled = yes
    default history = 3600
    default memory mode = save
    health enabled by default = auto
    allow from = *

API_KEY对应节点服务器的api key(uuid)。

C、重启主从服务

# CentOS 6
service netdata restart

# CentOS 7
systemctl restart netdata

访问http://IP:19999/访问即可,看到监控数据,在左上角可以对集群机器进行切换。

4977ff305ede3583d5c8a885be752e5f.png

四、Grafana接入

Netdata的内容太全了,以至于不好确认重点,但是不会js,所以也没法定制开发dashboard。

在官方文档看上下图,可以接入Grafana,上手搞起。

4fcc2cb150aee639be188797bb5a9548.png

A、安装InfluxDB

sudo vi  /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository
baseurl = https://repos.influxdata.com/rhel/7/x86_64/stable/
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

yum makecache

yum -y install influxdb

B、修改netdata.conf配置

vim /etc/netdata/netdata.conf
[backend]
enabled = yes
type = opentsdb
destination = localhost:4242

C、修改influxdb.conf配置

vim /etc/influxdb/influxdb.conf
[[opentsdb]]
enabled = true
bind-address = ":4242"
database = "opentsdb"

D、重启Netdata和InfluxDB

systemctl restart influxdb
systemctl restart netdata

E、登录InfluxDB查看是否成功建库

influx

Connected to http://localhost:8086 version 1.7.6
InfluxDB shell version: 1.7.6
Enter an InfluxQL query

> SHOW DATABASES
name: databases
name
----
_internal
opentsdb

> USE opentsdb
Using database opentsdb

> SHOW MEASUREMENTS LIMIT 10
name: measurements
name
----
netdata.apps.cpu.apps.plugin
netdata.apps.cpu.build
netdata.apps.cpu.containers
netdata.apps.cpu.cron
netdata.apps.cpu.email
netdata.apps.cpu.go.d.plugin
netdata.apps.cpu.java
netdata.apps.cpu.kernel
netdata.apps.cpu.ksmd
netdata.apps.cpu.logs

78d4f6b842ec3599883621ca4f046e77.png

已经能把数据写入db,后续只要配置Grafana展示数据即可。

工具链接:https://github.com/CymaticLabs/InfluxDBStudio/releases/tag/v0.2.0-beta.1

F、配置Grafana

# grafana 6下载
wget https://dl.grafana.com/oss/release/grafana-6.1.6-1.x86_64.rpm 
sudo yum localinstall grafana-6.1.6-1.x86_64.rpm 

# 重启grafana 
systemctl restart grafana-server

登录http://10.255.242.168:3000,默认密码admin/admin,登陆后修改即可。

后续操作不想截图了,参考文末最后三个URL,里面有详细步骤及截图。

后续有什么调整,再继续补充。

netdata原生:http://10.255.242.168:19999

14d8a628cd41f2da0fe641c0683a6b48.png

Grafana接入:http://10.255.242.168:3000

c277c1ec1941e6cd467c26023164748e.png

五、踩坑

A、Netdata安装文件使用了netstat用户及用户组,如果通过root修改了web目录下的js,需要重新赋予权限。否则会报Cannot load required JS library netdata错误。

/usr/share/netdata/web
localhost netdata/web » chown netdata dashboard_info.js dashboard_info_custom.js
localhost netdata/web » chgrp netdata dashboard_info.js dashboard_info_custom.js

涉及到自定义dashboard,都会尝试修改js,看来不只一个人踩坑。

https://github.com/netdata/netdata/issues/2445

https://github.com/netdata/netdata/issues/3104

B、自定义dashboard

Customizing the standard dashboards

Charts information is stored at /usr/share/netdata/web/dashboard_info.js. This file includes information that is rendered on the dashboard, controls chart colors, section and subsection heading, titles, etc.

If you change that file, your changes will be overwritten when Netdata is updated. You can preserve your settings by creating a new such file (there is /usr/share/netdata/web/dashboard_info_custom.example.js you can use to start with).

You have to copy the example file under a new name, so that it will not be overwritten with Netdata updates.

To configure your info file set in netdata.conf:

[web] 
custom dashboard_info.js = your_file_name.js

参考:

https://docs.netdata.cloud/

https://github.com/netdata/netdata

https://github.com/netdata/netdata/wiki

https://github.com/netdata/netdata/blob/master/docs/Add-more-charts-to-netdata.md#add-more-charts-to-netdata

https://github.com/netdata/netdata/tree/master/health#Health-monitoring

https://kiswo.com/article/1020

https://kmonsoor.github.io/netdata-influx-grafana/

https://computingforgeeks.com/monitor-linux-server-with-netdata-and-grafana/

https://blog.sqdyy.cn/2018/05/13/ops-telegraf-influxdb-grafana/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值