背景
創(chuàng)新互聯(lián)建站是一家專業(yè)提供岳普湖企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、H5網(wǎng)站設(shè)計(jì)、小程序制作等業(yè)務(wù)。10年已為岳普湖眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。(1).系統(tǒng)運(yùn)維過程中會(huì)遇到 系統(tǒng)運(yùn)行定制化跟多個(gè)人性配置,個(gè)性化配置屬于私有配置不屬于監(jiān)控平臺(tái)的監(jiān)控范疇,且個(gè)性化指標(biāo)出現(xiàn)異常問題會(huì)導(dǎo)致系統(tǒng)出現(xiàn)不可預(yù)期問題及程序運(yùn)行風(fēng)險(xiǎn); 針對(duì)這種場(chǎng)景 我們會(huì)自己提供檢查系統(tǒng)檢查腳本或者agent 達(dá)到系統(tǒng)保障目的;? 如下就是系統(tǒng)探測(cè)腳本;
2.系統(tǒng)收集實(shí)戰(zhàn)腳本;
#!/bin/bash #系統(tǒng)信息抓取腳本 function?current_date(){ start_current_date="`date?"+%Y-%m-%d?%H:%M:%S"`" echo?${start_current_date} } ? function?init_logs(){ log_dir="/chj/logs/" log_file="/chj/logs/pushData.log" if?[?-f?${log_file}?] then ???echo?${log_file} else ???touch?${log_file}??? ???echo??${log_file} fi??? } ? #1.獲取系統(tǒng)ip地址 function?getSysIp(){ ipaddr=$(/bin/hostname?-i) echo?$ipaddr } ? #2.解析dns檢查是否存在有效dns; function?getSysDns(){ ????domain="do.chj.cloud" ????if?dig?@172.21.2.10?$domain?+short?|grep?'[0-9]'?>/dev/null;then ????????echo?"True" ????else ????????echo?"False" ????fi }? ? #3.獲取系統(tǒng)env環(huán)境變量 function?getSysEnv(){ envfile=/etc/profile.d/chj-common.sh if?[?-f?$envfile?]? then ???env=$(grep?"RUNTIME_ENV="?$envfile?|awk?-F?"="?'{print?$2}') ???echo?$env else ???echo?"none" fi } ? #4.獲取應(yīng)用名稱 ? function?getJavaName(){ appname=$(ps?-ef?|grep?java?|grep?-v?"grep"|head?-1|awk?-F?"-D"?'{print?$2}'|awk?-F?"="?'{print?$2}') echo?$appname } ? ? #5.獲取java應(yīng)用jvm參數(shù) function?getJavaInfo(){ appinfo=$(ps?-ef?|grep?java?|grep?-v?"grep"|head?-1|sed?'s/[[:space:]]/-/g') echo?"$appinfo" } ? ? #6.獲取應(yīng)用端口 function?getAppPort(){ apppid=$(ps?-ef?|grep?java?|grep?-v?"grep"?|?/bin/awk?'{print?$2}'?|head?-1) if?[?!?-z?"$apppid"?] then ????appport=$(netstat?-tulpn?|?grep?"$apppid"?|?awk?-F?":"?'{print?$2}'|/bin/awk?-F?"?"?'{print?$1}') ????echo?"$appport" ????? else ????echo?"none" fi }? ? #7.獲取當(dāng)前連接tcp function?getTcp(){ tcp=$(netstat?-anplt??|grep?-v?tcp6?|grep?-v?"127.0.0.1"|grep?"ESTABLISHED"|sort?|awk?'!a[$5]++{print}'|awk?'{print?$5,$7}'|sed?'s/[[:space:]]/-/g'|sed?'s/\///g'|sed?'s/sshd:/sshd/'|sed?s'/-.-//g') if?[?!?-n?"tcp"?] then ?????echo?"none" else ?????echo?$tcp|sed?'s/[[:space:]]/,/g' fi } ? #8.檢查是否存在nat; function?sysNat(){ ????local?timeout="1" ????local?target="www.badu.com" ????local?ret_code=`curl?-I?-s?--connect-timeout?${timeout}?${target}?-w?%{http_code}?|?tail?-n1` ????if?[?"x$ret_code"?=?"x200"?];?then ????????echo?"1" ????else ????????echo?"0" ????fi } ? #9.調(diào)用動(dòng)態(tài)上傳接口發(fā)送請(qǐng)求數(shù)據(jù) function?reqDynamicData(){ sysipaddr=$1 sysdns=$2 sysenv=$3 appName=$4 appjvm=$5 appPort=$6 conntcp=$7 nat=$8 fetchUrl="http://ops.chj.cloud/dynamic/api/v1" /bin/curl?"$fetchUrl"?-X?POST?-H?"Content-Type:?application/json"?-d?"{\"instance_ip\":?\"$sysipaddr\",\"env\":\"$sysenv\",\"dns\":\"$sysdns\",\"appname\":\"$ppName\",\"appjvm\":\"$appjvm\",\"appport\":\"$appPort\",\"apptcp\":\"$conntcp\",\"nat\":\"$nat\"}" } ? #10.發(fā)送數(shù)據(jù) function?main(){ ip=`getSysIp` dns=`getSysDns` env=`getSysEnv` name=`getJavaName` jvm=`getJavaInfo` port=`getAppPort` tcp=`getTcp` nat=`sysNat` reqDynamicData?$ip?$dns?$env?$name?$jvm?$port?$tcp?$nat log=`init_logs` runTime_date=`current_date` echo?"上傳數(shù)據(jù)時(shí)間:$runTime_date"?>>?$log???? } main3.數(shù)據(jù)庫字段設(shè)計(jì);
?3.1?創(chuàng)建數(shù)據(jù)庫sql; ? ?CREATE?TABLE?`dynamic_Check`?( ??`id`?int(11)?NOT?NULL?AUTO_INCREMENT, ??`ip`?varchar(92)?COLLATE?utf8mb4_bin?DEFAULT?NULL, ??`dns`?varchar(128)?COLLATE?utf8mb4_bin?DEFAULT?NULL, ??`env`?varchar(64)?COLLATE?utf8mb4_bin?DEFAULT?NULL, ??`appname`?text?COLLATE?utf8mb4_bin, ??`appport`?varchar(32)?COLLATE?utf8mb4_bin?DEFAULT?NULL, ??`appjvm`?text?COLLATE?utf8mb4_bin, ??`conn_tcp`?text?COLLATE?utf8mb4_bin, ??`snat`?varchar(32)?COLLATE?utf8mb4_bin?DEFAULT?NULL, ??`run_time`?datetime?DEFAULT?NULL, ??PRIMARY?KEY?(`id`) )?ENGINE=InnoDB?AUTO_INCREMENT=12?DEFAULT?CHARSET=utf8mb4?COLLATE=utf8mb4_bin? 3.2.數(shù)據(jù)庫表結(jié)構(gòu) +----------+--------------+------+-----+---------+----------------+ |?Field????|?Type?????????|?Null?|?Key?|?Default?|?Extra??????????| +----------+--------------+------+-----+---------+----------------+ |?id???????|?int(11)??????|?NO???|?PRI?|?NULL????|?auto_increment?| |?ip???????|?varchar(92)??|?YES??|?????|?NULL????|????????????????| |?dns??????|?varchar(128)?|?YES??|?????|?NULL????|????????????????| |?env??????|?varchar(64)??|?YES??|?????|?NULL????|????????????????| |?appname??|?text?????????|?YES??|?????|?NULL????|????????????????| |?appport??|?varchar(32)??|?YES??|?????|?NULL????|????????????????| |?appjvm???|?text?????????|?YES??|?????|?NULL????|????????????????| |?conn_tcp?|?text?????????|?YES??|?????|?NULL????|????????????????| |?snat?????|?varchar(32)??|?YES??|?????|?NULL????|????????????????| |?run_time?|?datetime?????|?YES??|?????|?NULL????|????????????????| +----------+--------------+------+-----+---------+----------------+另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
名稱欄目:Shell抓取Linux系統(tǒng)指標(biāo)通過api上報(bào)-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://www.rwnh.cn/article32/doespc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站營(yíng)銷、網(wǎng)站設(shè)計(jì)公司、定制開發(fā)、網(wǎng)站制作、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容