博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
shell脚本抓取用户存储quota写道mysql并展现到grafana面板
阅读量:6676 次
发布时间:2019-06-25

本文共 2171 字,大约阅读时间需要 7 分钟。

通过shell脚本抓取存储home用户的空间使用情况,写到excel文件里,再导入到mysql数据库,最后通过grafana进行展示

vi aa.sh

#!/bin/bash

Date=date +"%Y-%m-%d %H:%M:%S"

Date2=date +"%Y-%m-%d"

Dir=/logs/Homes

/bin/rm -rf $Dir/quota2.txt

/bin/touch $Dir/quota2.txt

/usr/bin/ssh 10.0.0.10 "quota report -x" | grep home > $Dir/quota.txt

/usr/bin/ssh 10.0.0.20 "quota report -x" | grep home2 >> $Dir/quota.txt

/bin/cat $Dir/quota.txt | awk -F[:" "]+ '{print $2}' | tr -d "*" | grep -v -w "root" > $Dir/users.txt

for i in cat $Dir/users.txt

do
Used=cat $Dir/quota.txt | grep -w $i | awk -F[:" "]+ '{print $5}'
Home=cat $Dir/quota.txt | grep -w $i | awk -F[:" "]+ '{print $3}'
Filen=cat $Dir/quota.txt | grep -w $i | awk -F[:" "]+ '{print $8}'
/bin/echo "$Date,$i,$Home,$Used,$Filen" >> $Dir/quota2.txt
done

/bin/cat $Dir/quota2.txt | grep $Date2 > $Dir/quota3.txt

/bin/cat $Dir/quota3.txt | tr -s '[:blank:]' > $Dir/quota4.csv

/usr/bin/mysql -h 10.0.0.2 -u icinga2 -p'xxxx' --local-infile=1 ming -e "LOAD DATA LOCAL INFILE '/logs/Homes/quota4.csv' INTO TABLE userquota FIELDS TERMINATED BY ','"

:wq

mysql -u root -p'xxxx'

create database ming default character set utf8;

create table userquota(time datetime,user char(50),home char(50),used float,filen float);
grant all on ming.* to aa@'localhost' identified by 'xxxx';
exit

grafana配mysql略

查询用户总数:

select UNIX_TIMESTAMP(time) as time_sec, count(*) as Total from userquota group by time_sec;

查询各home用户数:

select UNIX_TIMESTAMP(time) as time_sec, count(*) as home8 from userquota where home='home8' group by time_sec;

查询单个人空间使用情况语句:

SELECT UNIX_TIMESTAMP(time) as time_sec, used as 'zhi.yang' FROM userquota WHERE user='zhi.yang';

查询平均空间使用情况语句:

select Unix_timestamp(time) as time_sec, avg(used) from userquota group by time_sec;

统计各空间段的人数:

select unix_timestamp(time) as time_sec, count(*) as '=0' from userquota where used = '0' group by time_sec;

select unix_timestamp(time) as time_sec, count(*) as '<=50G' from userquota where used > '0' and used <= '52144000' group by time_sec;

select unix_timestamp(time) as time_sec, count(*) as '50G<N<100G' from userquota where used > '52144000' and used <= '112144000' group by time_sec;

转载于:https://blog.51cto.com/yangzhiming/2300272

你可能感兴趣的文章
ubuntu12.04中shell脚本无法使用source的原因及解决方法
查看>>
【题目】求n以内的素数个数
查看>>
VS 项目(c#)引用了 DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称...
查看>>
BZOJ 2599: [IOI2011]Race [点分治]
查看>>
面状县级行政区划转地级行政区划,并关联属性字段
查看>>
HDU 2092 整数解
查看>>
BZOJ 2882: 工艺 [后缀自动机+map]
查看>>
BZOJ 3527: [Zjoi2014]力 [快速傅里叶变换]
查看>>
Sql 列转行 三种方法对比
查看>>
SmartRoute之远程接口调用和负载
查看>>
Asp.net mvc 知多少(七)
查看>>
备忘录模式
查看>>
git 如何更改某个提交内容/如何把当前改动追加到某次commit上? git rebase
查看>>
eclipse里将java工程改web工程
查看>>
amazon redshift 分析型数据库特点——本质还是列存储
查看>>
rabbitmq heartbeat missing with heartbeat = N seconds原因总结
查看>>
docker hub下载慢解决方法 使用daocloud的mirror
查看>>
C#编程(二十四)----------修饰符
查看>>
Elasticsearch之es学习工作中遇到的坑(陆续更新)
查看>>
[内核]procfs和sysfs
查看>>