通过shell抓取mysql应用的CPU内存负载
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过shell抓取mysql应用的CPU内存负载相关的知识,希望对你有一定的参考价值。
通过shell抓取mysql应用的CPU、内存负载vi dbload.sh
#!/bin/bash
Date=date +"%Y-%m-%d %H:%M:%S"
Datee=date +%Y-%m-%d
Se=/bin/hostname
Cp=/bin/ps aux | grep ‘mysql.sock‘ | head -n 1 | awk -F[:" "]+ ‘{print $3}‘
Me=/bin/ps aux | grep ‘mysql.sock‘ | head -n 1 | awk -F[:" "]+ ‘{print $4}‘
/bin/echo "$Date,$Se,$Cp,$Me" > /log/dbload.txt
/bin/cat /log/dbload.txt | tr -s ‘[:blank:]‘ > /log/dbload2.csv
/usr/bin/mysql -h 10.0.0.2 -u icinga2 -p‘xxxxxxx‘ --local-infile=1 dbload -e "LOAD DATA LOCAL INFILE ‘/log/dbload2.csv‘ INTO TABLE loadavg FIELDS TERMINATED BY ‘,‘"
:wq
mysql部分:
create database dbload default character set utf8;
create table loadvag(time datetime,server char(50),cpu float,mem float);
grant all on dbload.* to [email protected]‘10.%‘ identified by ‘xxxxx‘;
flush privileges;
exit
grafana语句:
select UNIX_TIMESTAMP(Time) as time, cpu as "db2" from loadavg where server="db2";
以上是关于通过shell抓取mysql应用的CPU内存负载的主要内容,如果未能解决你的问题,请参考以下文章