通过grafana面板展示各home存储的空间使用率及文件数使用率
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过grafana面板展示各home存储的空间使用率及文件数使用率相关的知识,希望对你有一定的参考价值。
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 [email protected]‘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";
以上是关于通过grafana面板展示各home存储的空间使用率及文件数使用率的主要内容,如果未能解决你的问题,请参考以下文章
如何通过 REST API 更新 Grafana 面板中的指标值