shell脚本抓取各home存储的空间使用率及文件数使用率,写道excel文件里,再写到mysql里,最后通过grafana面板展示
vi aa.sh
#!/bin/bash
Date=date +"%Y-%m-%d %H:%M:%S"
Dir=/logs/Homes
Home1=df -h /home1 | tail -n 1 | awk -F[:" "]+ '{print $5}' | tr -d "%"
Homei1=df -i /home1 | tail -n 1 | awk -F[:" "]+ '{print $5}'| tr -d "%"
Home2=df -h /home2 | tail -n 1 | awk -F[:" "]+ '{print $5}' | tr -d "%"
Homei2=df -i /home2 | tail -n 1 | awk -F[:" "]+ '{print $5}' | tr -d "%"
/bin/echo "$Date,home1,$Home1,$Homei1" > $Dir/Homeavg.txt
/bin/echo "$Date,home2,$Home2,$Homei2" >> $Dir/Homeavg.txt
/bin/cat $Dir/Homeavg.txt | tr -s '[:blank:]' > $Dir/Homeavg.csv
/usr/bin/mysql -h 10.0.0.2 -u icinga2 -p'xxxxxx' --local-infile=1 jenkins_log2 -e "LOAD DATA LOCAL INFILE '/logs/Homes/Homeavg.csv' INTO TABLE homesavg FIELDS TERMINATED BY ','"
:wq
mysql -u root -p'xxx'
create database ming default character set utf8;
create table homesavg(time datetime,home char(50),homeavg float,homeiavg float);
grant all on ming.* to aa@'localhost' identified by 'xxxx';
exit
grafana配mysql略
查询空间使用率:
select UNIX_TIMESTAMP(Time) as time, homeavg as "home1" from homesavg where home="home1";
查询文件数使用率:
select UNIX_TIMESTAMP(Time) as time, homeiavg as "home1" from homesavg where home="home1";
转载于:https://blog.51cto.com/yangzhiming/2300389