irms模拟数据生成及数据分析
生活随笔
收集整理的這篇文章主要介紹了
irms模拟数据生成及数据分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、數據準備
1、每天生成隨機一個文本,每小時向文本中追加2次數據,每次10萬條
隨機數據生成:
2,32? * * * *? bash /mnt/jediael/irms/signalGenerator/signalGenerator.sh >> /home/jediael/sg.log 2>&1
類:SignalGenerator
2、每天將前一天生成的數據文本導入HDFS
32 0 * * * bash /mnt/jediael/irms/signalGenerator/copySignalToHdfs.sh >>/home/jediael/sg.log 2>&1
二、數據分析
1、每天執行一次數據分析,將結果輸出到hdfs文本中。
42 0 * * * bash /mnt/jediael/irms/signalparser/signalParser.sh >>/home/jediael/sg.log 2>&1
類:SignalParser
程序文件:
/mnt/jediael/irms/signalGenerator/signalGenerator.sh
#!/bin/bash export JAVA_HOME=/usr/java/jdk1.7.0_51 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=$CLASSPATH:/mnt/jediael/irms/signalGenerator/ java SignalGenerator/mnt/jediael/irms/signalGenerator/copySignalToHdfs.sh
#!/bin/bash export JAVA_HOME=/usr/java/jdk1.7.0_51 PATH=/mnt/jediael/hadoop-1.2.1/bin/:/mnt/jediael/hbase-0.94.26/bin:/mnt/jediael/tomcat-7.0.54/bin:$JAVA_HOME/bin:$PATH hadoop fs -copyFromLocal /mnt/jediael/irms/signalGenerator/`date -d "-1 day" +%Y%m%d`.txt /irms/signal >> sg.log/mnt/jediael/irms/signalparser/signalParser.sh #!/bin/bashexport JAVA_HOME=/usr/java/jdk1.7.0_51 PATH=/mnt/jediael/hadoop-1.2.1/bin/:/mnt/jediael/hbase-0.94.26/bin:/mnt/jediael/tomcat-7.0.54/bin:$JAVA_HOME/bin:$PATH hadoop jar signalgenerator.jar /irms/signal/`date -d "-1 day" +%Y%m%d`.txt /irms/result/`date -d "-1 day" +%Y%m%d`
SignalGenerator.java
package com.gmcc.irms.util;import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Random;//此類用于模擬生成信令數據,每次生成100000條public class SignalGenerator {// 業務類型,如呼入、呼出、發短信、收短信、上網、WLAN等private int activeType = 0;private String getNextSign() {String sign = "";Random rand = new Random();activeType = rand.nextInt(6);// 主叫號碼String callNum = "1390222" + rand.nextInt(9) + rand.nextInt(9)+ rand.nextInt(9) + rand.nextInt(9);// 被叫號碼String beCallNum = "1390222" + rand.nextInt(9) + rand.nextInt(9)+ rand.nextInt(9) + rand.nextInt(9);// 時長、或者是流量String callDuration = "";for (int i = 0; i < 16; i++) {callDuration += rand.nextInt(9);}sign = activeType + callNum + beCallNum + callDuration;for (int i = 0; i < 800; i++) {sign += rand.nextInt(9);}return sign;}public static void main(String[] args) throws IOException {SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");long time = System.currentTimeMillis();String fileName = sdf.format(time) + ".txt";OutputStream os = new FileOutputStream(fileName, true);SignalGenerator sg = new SignalGenerator();String newline = System.getProperty("line.separator");for (int i = 0; i < 100000; i++) {os.write((sg.getNextSign() + newline).getBytes());}os.flush();os.close();}}SignalParser.java
總結
以上是生活随笔為你收集整理的irms模拟数据生成及数据分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: crontab经验
- 下一篇: 使用ganglia监控hadoop及hb