DataStage通過分析日志獲取Job插入目標(biāo)表的記錄數(shù)
創(chuàng)新新互聯(lián),憑借十載的成都網(wǎng)站建設(shè)、做網(wǎng)站經(jīng)驗,本著真心·誠心服務(wù)的企業(yè)理念服務(wù)于成都中小企業(yè)設(shè)計網(wǎng)站有成百上千案例。做網(wǎng)站建設(shè),選成都創(chuàng)新互聯(lián)。
這只是一種不太好的方法,也許還有更好、更簡便的方法。這種方法要求每次運行Job之前刪除已有的日志信息,否則無法統(tǒng)計出正確的記錄數(shù)。當(dāng)然,在Job跑完之后,可以在shell備份本次Job運行的日志到服務(wù)器磁盤。
登錄Datastage Administrator,選擇對應(yīng)項目,項目屬性->記錄,勾選“自動清除作業(yè)日志”,設(shè)置為自動清理上次及以前的日志。
Figure 1 Administrator日志清理設(shè)置
在shell里用dsjob調(diào)起來Job,Job運行之后,將本次Job的日志備份到磁盤。
$DSHOME/bin/dsjob -logsum $projectName $jobName > $sysLogDir/$jobName.txt
注意到往目標(biāo)表里寫記錄的時候會有關(guān)鍵字“Number of rows inserted:”或“Number of rows rejected:”,后面跟記錄的數(shù)目。考慮到可能有多個節(jié)點,因此可以將各個節(jié)點的數(shù)據(jù)都加起來。
#inserted rows
insertedRows=`cat $sysLogDir/$jobName.txt | grep "Number of rows inserted:" | awk -F: '{print $3}' | sed 's/,/''/' | awk '{sum=sum+$1;} END {print sum}'`
#rejected rows
rejectedRows=`cat $sysLogDir/$jobName.txt | grep "Number of rows rejected:" | awk -F: '{print $3}' | sed 's/,/''/' | awk '{sum1=sum1+$1;} END {print sum1}'`
考慮到Job可能沒進數(shù)就終止了,需要在接下來做處理。例如為空的話賦值0。
if [ ! -n "$insertedRows" ]; then
insertedRows=0
fi
監(jiān)控可能還要些Job運行起止時間、結(jié)束狀態(tài)等等,可以一并加上,然后寫入一個日志文件。
其中起止時間可以在Job運行前后記錄,Job的運行裝可以用dsjob –run –status獲取。
jobsta=$($DSHOME/bin/dsjob -run -mode NORMAL $jobParameters -warn 0 -jobstatus $projectName $jobName 2>&1 | awk -F= '/^Status code/{print $2}')
Job執(zhí)行完畢之后,將該Job的一些監(jiān)控信息寫入日志。
echo $projectName $jobName $jobsta `date +%Y-%m-%d" "%H:%M:%S` $startTime $insertedRows $rejectedRows >> $logdir/job_run_` date +%Y%m%d`.log
當(dāng)所有的Job都執(zhí)行完之后,可以建立一個Job,將記錄在$logdir/job_run_` date +%Y%m%d`.log中的數(shù)據(jù)抽取到一個表,用于查看。
//日志表
create table DSLog
(
id INTEGER NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 1, INCREMENT BY 1) primary key ,
prjName varchar (20),
jobName varchar (50),
state varchar (20),
rDate date ,
startTime time,
endTime time,
insertedRows integer,
rejectedRows integer
)
//日志狀態(tài)表
create table DSLogState
(
state varchar (20),
mark varchar (50 ),
des varchar (500)
)
http://publib.boulder.ibm.com/infocenter/iisinfsv/v8r7/topic/com.ibm.swg.im.iis.ds.cliapi.ref.doc/topics/r_dsvjbref_Error_Codes.html
https://www-304.ibm.com/support/docview.wss?uid=swg21469644
#!/bin/bash
########################################
#
# runJob.sh 2012-08-19
# run a job with parameters
#
#######################################
# if the number of input parameters is less than 2,then output the help document and exit
if [ $# -lt 2 ] ; then
cat << HELP
runJob --run a job UASGE: runJob projectName jobName jobParameters
EXAMPLE: runJob dsstage1 DD_Test '-param endDT=20120819'
HELP
exit 0
fi
projectName="$1"
jobName="$2"
jobParameters="$3"
#echo $projectName
#echo $jobName
echo $jobParameters
#exit 0
logdir=/DS/DSLogs #directory to store logs
workdate=`date +%Y%m%d`
sysLogDir=/DS/DSLogs/sysLogsBK/`date +%Y%m%d` #directory to back everyday datastage log.Datastage Administrator is setted to delete the logs before run a job.
#solve the problem of $DSHOME is null
source /mistel/IBM/InformationServer/Server/DSEngine/dsenv
#logdir processing.If log folder not exists,create folder.
if [ -d $logdir ]; then
echo "$logdir is exist,continue..."
else
echo "$logdir is not exist,creating $logdir..."
mkdir -p $logdir
fi
#create datastage logs backup direcotry
if [ ! -d $sysLogDir ]; then
mkdir -p $sysLogDir
fi
#job state processing.If job state is not finished ok,then reset the job
jobsta=$($DSHOME/bin/dsjob -jobinfo $projectName $jobName 2>&1 | awk -F: '/^Job Status/{print $2}')
echo 'last status: ' $jobsta
if [ "$jobsta" == " RUN FAILED (3)" -o "$jobsta" == " STOPPED (97)" ];then
echo "Reset before run job $jobname"
$DSHOME/bin/dsjob -run -mode RESET $projectName $jobName >>${logdir}/job_init_` date +%Y%m%d`.log
sleep 5
fi
#job start run time
startTime=`date +%H:%M:%S`
#run a job
jobsta=$($DSHOME/bin/dsjob -run -mode NORMAL $jobParameters -warn 0 -jobstatus $projectName $jobName 2>&1 | awk -F= '/^Status code/{print $2}')
#backup datastage logs
$DSHOME/bin/dsjob -logsum $projectName $jobName > $sysLogDir/$jobName.txt
#calculate the inserted rows and rejected rows from the back up log file
#inserted rows
insertedRows=`cat $sysLogDir/$jobName.txt | grep "Number of rows inserted:" | awk -F: '{print $3}' | sed 's/,/''/' | awk '{sum=sum+$1;} END {print sum}'`
#rejected rows
rejectedRows=`cat $sysLogDir/$jobName.txt | grep "Number of rows rejected:" | awk -F: '{print $3}' | sed 's/,/''/' | awk '{sum1=sum1+$1;} END {print sum1}'`
if [ ! -n "$insertedRows" ]; then
insertedRows=0
fi
if [ ! -n "$rejectedRows" ]; then
rejectedRows=0
fi
echo 'this run status code [1:Finished;2:Finished (see log);3:Aborted;97:Stopped] : ' $jobsta
#log
echo $projectName $jobName $jobsta `date +%Y-%m-%d" "%H:%M:%S` $startTime $insertedRows $rejectedRows >> $logdir/job_run_` date +%Y%m%d`.log
網(wǎng)站題目:datastage分析日志獲取表記錄條數(shù)
鏈接分享:http://www.rwnh.cn/article38/psgisp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、App設(shè)計、網(wǎng)站內(nèi)鏈、外貿(mào)建站、用戶體驗、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)