linux服务器巡检性能与Java 进程脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux服务器巡检性能与Java 进程脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#作者:洪永坚
echo -e "33[31m211服务器时间: 33[0m"
date +%F" "%H:%M #获取脚本执行的时间
echo -e "33[31m服务器ip地址: 33[0m"
ifconfig eno1 | awk ‘/inet/‘ | awk ‘{print $2}‘#获取IP
#检查CPU状态
hong=$(vmstat | awk ‘NR==3{print $15}‘)
yong=$(vmstat | awk ‘NR==3{print $14}‘)
jian=$(vmstat | awk ‘NR==3{print $13}‘)
echo -e "33[31mCPU情况 :CPU空闲:${hong} 内核空间:${yong} 用户空间:${jian}33[0m"
for i in $honc
do
if [ $i -lt 10 ]; then
echo -e "33[35m CPU空间不足 10% 请检查 33[0m"
fi
done
#检查free空间状态
h=$(free -h |awk ‘/Mem:/‘|awk ‘NR==1{print $4}‘)
y=$(free -h |awk ‘/Mem:/‘|awk ‘NR==1{print $6}‘)
j=$(free -h |awk ‘/Mem:/‘|awk ‘NR==1{print $7}‘)
hong=$(free -h |awk ‘/Mem:/‘|awk ‘NR==1{print $4}‘|cut -d G -f 1)
echo -e "33[33mfree -h Mem: free内存:${h} 缓存内存:${y} available内存:${j}33[0m"
for i in $honr
do
if [ $i -lt 10 ]; then
echo -e "33[35m free空间不足 10G 请检查 33[0m"
fi
done
#检查swap交换空间状态
hon=$(free -h |awk ‘/Swap:/‘|awk ‘NR==1{print $2}‘)
yon=$(free -h |awk ‘/Swap:/‘|awk ‘NR==1{print $3}‘)
jia=$(free -h |awk ‘/Swap:/‘|awk ‘NR==1{print $4}‘)
wang=$(free -h |awk ‘/Swap:/‘|awk ‘NR==1{print $4}‘|cut -d G -f 1)
echo -e "33[33mfree -h swap:总内存:${hon} 已用内存:${yon} free内存:${jia}33[0m"
for i in $wanr
do
if [ $i -lt 2 ]; then
echo " swap空间不足 2G 请检查 "
fi
done

echo -e "33[34m服务器重要进程:33[0m"
echo -e "33[36mhbase进程:33[0m"
jps -l |grep hbase
mei=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $mei
do
if [ $i -gt 0 ]; then
echo -e "33[35m>>>>no hbase,进程挂了,请注意!... 33[0m"
fi
done

echo -e "33[31mMpp进程(2个):33[0m"
jps -l |grep MppService_232
wan=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wan
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no MppService_232,进程挂了,请注意!...33[0m"
fi
done

jps -l |grep MppService-0
wah=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wah
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no MppService,进程挂了,请注意!...33[0m"
fi
done

echo -e "33[31mkafka的进程: 33[0m"
jps -l |grep kafka
waho=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $waho
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no kafka,进程挂了,请注意!...33[0m"

fi
done
echo -e "33[31mstorm进程:33[0m"
jps -l |grep org.apache.storm.daemon.supervisor.Supervisor
wahon=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wahww
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no storm,进程挂了,请注意!...33[0m"
fi
done
echo -e "33[31mzookeeper进程:33[0m"
jps -l |grep zookeeper
wahong=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wahop
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no zookeeper,进程挂了,请注意!...33[0m"
fi
done
echo -e "33[31mredis微服务进程:33[0m"
jps -l |grep redis
wanhong=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wanhon
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no redis,进程挂了,请注意!...33[0m"
fi
done
echo -e "33[31mhadoop进程(3个):33[0m"
jps -l |grep org.apache.hadoop.hdfs.server.datanode.DataNode
wangLhong=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wLhow
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no hdfs DataNode,进程挂了,请注意!...33[0m"
fi
done
jps -l |grep org.apache.hadoop.yarn.server.nodemanager.NodeManager
wlh=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wlgwh
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no yarn NodeManagtr,进程挂了,请注意!...33[0m"
fi
done
jps -l |grep org.apache.hadoop.hbase.regionserver.HRegionServer
wloh=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wloh
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no hbase HRegionServer,进程挂了,请注意!...33[0m"
fi
done

echo -e "33[31m硬盘空间使用情况:33[0m"
df -Th
echo -e "33[31m查看solr进程:33[0m"
ps -ef |grep solr |grep /opt/java/jdk1.8.0_112/bin/java
jps -l|grep start.jar
wanghong=$(echo $?|awk ‘NR==1{print $1}‘)
for i in $wanghp
do
if [ $i -gt 0 ]; then
echo -e "33[35m >>>>no solr,进程挂了,请注意!...33[0m"
fi
done

以上是关于linux服务器巡检性能与Java 进程脚本的主要内容,如果未能解决你的问题,请参考以下文章

windows上配置rsync服务器收集linux主机巡检报告

关于linux系统调优这一篇文章就够了

关于linux系统调优这一篇文章就够了

linux服务器巡检脚本

linux系统安全巡检脚本

求一个DB2 v9.7的日常巡检脚本! for Linux and AIX 如果实用的,额外奖励大虾50分!