分析运维数据的一些预处理操作
来源:互联网 发布:发那科攻丝编程 编辑:程序博客网 时间:2024/05/21 17:56
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* @author Administrator
*
*/
/**
* @author Administrator
*
*/
public class DataAnalyze {
public static void main(String[] args) {
// TODO Auto-generated method stub
String TimeSortedLogFile = "/home/wdl/test/result.txt";
List<String> record = new ArrayList<String>();
List<List<String>> typeGroupRecord = new ArrayList<List<String>>();
List<Double> gropCount = new ArrayList<Double>();
double count = 0;
double totalCount = 0;
// 扫描文件,将记录存储到List中
try {
File File = new File(TimeSortedLogFile);
BufferedReader wReader = new BufferedReader(new InputStreamReader(
new FileInputStream(TimeSortedLogFile), "UTF-8"));
String line = null;
while ((line = wReader.readLine()) != null) {
if ("".equals(line.trim())) { // 遇空行,略过继续执行
continue;
}
record.add(line);
}
wReader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
// 找出所有类型,如(a,f)
Map<List<String>, Integer> typePair = new HashMap<List<String>, Integer>();
List<String> satisfiedEqualIPEvent = new ArrayList<String>();
for (int i = 0; i < record.size(); i++) {
List<String> type = new ArrayList<String>(); // 记录不包含IP的日志类型
String[] logArr = record.get(i).split("\t");
for (int j = 0; j < logArr.length - 1; j++) {
String[] sublogArr = logArr[j - 1].split("_"); // sublogArr大小为2
type.add(sublogArr[1]);
}
typePair.put(type, 0);
}
// 遍历每一种类型
for (Entry<List<String>, Integer> entry : typePair.entrySet()) {
count = 0;
totalCount = 0;
satisfiedEqualIPEvent = resolvePair(entry.getKey(), record);
typeGroupRecord.add(satisfiedEqualIPEvent);
for (String tempStr : satisfiedEqualIPEvent) {
String[] str = tempStr.split("\t");
count = Double.parseDouble(str[str.length - 1]);
totalCount = totalCount + count;
}
gropCount.add(totalCount);
}
}
/**
* 对于每一对类型,找到同一台ip出现此故障的记录
*
* @param type
* @param record
* @return
*/
public static List<String> resolvePair(List<String> type,
List<String> record) {
Boolean ipEqualFlag = false;
Boolean typeEqualFlag = true;
List<String> satisfiedEqualIPEvent = new ArrayList<String>();
for (int i = 0; i < record.size(); i++) {
typeEqualFlag = true;
ipEqualFlag = false;
String[] logArr = record.get(i).split("\t");
List<String> singleType = new ArrayList<String>();
List<String> ip = new ArrayList<String>();
for (int j = 0; j < logArr.length - 1; j++) {
String[] sublogArr = logArr[j - 1].split("_"); // sublogArr大小为2
ip.add(sublogArr[0]);
singleType.add(sublogArr[1]);
}
Set s = new HashSet(ip); // 观察每一项的ip是否相同
if (s.size() > 1) {
ipEqualFlag = false;
} else {
ipEqualFlag = true;
}
if (type.size() == singleType.size()) { // 在所有记录中提取所有相同类型
for (int k = 0; k < type.size(); k++)
if (type.get(k).equals(singleType.get(k)) == false) {
ipEqualFlag = false;
break;
}
}
if (ipEqualFlag == true && typeEqualFlag == true) { // 若结果中同一条规则中事件的ip相同
satisfiedEqualIPEvent.add(record.get(i));
}
}
return satisfiedEqualIPEvent;
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* @author Administrator
*
*/
/**
* @author Administrator
*
*/
public class DataAnalyze {
public static void main(String[] args) {
// TODO Auto-generated method stub
String TimeSortedLogFile = "/home/wdl/test/result.txt";
List<String> record = new ArrayList<String>();
List<List<String>> typeGroupRecord = new ArrayList<List<String>>();
List<Double> gropCount = new ArrayList<Double>();
double count = 0;
double totalCount = 0;
// 扫描文件,将记录存储到List中
try {
File File = new File(TimeSortedLogFile);
BufferedReader wReader = new BufferedReader(new InputStreamReader(
new FileInputStream(TimeSortedLogFile), "UTF-8"));
String line = null;
while ((line = wReader.readLine()) != null) {
if ("".equals(line.trim())) { // 遇空行,略过继续执行
continue;
}
record.add(line);
}
wReader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
// 找出所有类型,如(a,f)
Map<List<String>, Integer> typePair = new HashMap<List<String>, Integer>();
List<String> satisfiedEqualIPEvent = new ArrayList<String>();
for (int i = 0; i < record.size(); i++) {
List<String> type = new ArrayList<String>(); // 记录不包含IP的日志类型
String[] logArr = record.get(i).split("\t");
for (int j = 0; j < logArr.length - 1; j++) {
String[] sublogArr = logArr[j - 1].split("_"); // sublogArr大小为2
type.add(sublogArr[1]);
}
typePair.put(type, 0);
}
// 遍历每一种类型
for (Entry<List<String>, Integer> entry : typePair.entrySet()) {
count = 0;
totalCount = 0;
satisfiedEqualIPEvent = resolvePair(entry.getKey(), record);
typeGroupRecord.add(satisfiedEqualIPEvent);
for (String tempStr : satisfiedEqualIPEvent) {
String[] str = tempStr.split("\t");
count = Double.parseDouble(str[str.length - 1]);
totalCount = totalCount + count;
}
gropCount.add(totalCount);
}
}
/**
* 对于每一对类型,找到同一台ip出现此故障的记录
*
* @param type
* @param record
* @return
*/
public static List<String> resolvePair(List<String> type,
List<String> record) {
Boolean ipEqualFlag = false;
Boolean typeEqualFlag = true;
List<String> satisfiedEqualIPEvent = new ArrayList<String>();
for (int i = 0; i < record.size(); i++) {
typeEqualFlag = true;
ipEqualFlag = false;
String[] logArr = record.get(i).split("\t");
List<String> singleType = new ArrayList<String>();
List<String> ip = new ArrayList<String>();
for (int j = 0; j < logArr.length - 1; j++) {
String[] sublogArr = logArr[j - 1].split("_"); // sublogArr大小为2
ip.add(sublogArr[0]);
singleType.add(sublogArr[1]);
}
Set s = new HashSet(ip); // 观察每一项的ip是否相同
if (s.size() > 1) {
ipEqualFlag = false;
} else {
ipEqualFlag = true;
}
if (type.size() == singleType.size()) { // 在所有记录中提取所有相同类型
for (int k = 0; k < type.size(); k++)
if (type.get(k).equals(singleType.get(k)) == false) {
ipEqualFlag = false;
break;
}
}
if (ipEqualFlag == true && typeEqualFlag == true) { // 若结果中同一条规则中事件的ip相同
satisfiedEqualIPEvent.add(record.get(i));
}
}
return satisfiedEqualIPEvent;
}
}
阅读全文
0 0
- 分析运维数据的一些预处理操作
- 数据预处理的一些方法
- 数据预处理的一些知识
- 常用的数据预处理操作
- python . 数据分析1 数据的预处理
- 数据预处理一些笔记
- 一些数据预处理方法
- 数据预处理及相应的Rapidminer操作
- pandas做数据分析(三):常用预处理操作
- 数据分析之数据预处理
- 【数据挖掘】数据预处理与Rapidminer相应的操作
- Python数据分析模块 | pandas做数据分析(二):常用预处理操作
- 神经网络训练中图像数据预处理的一些方式(一)
- 深度学习-----数据预处理是必要的,一些经验化的预处理措施
- pandas数据预处理之dataframe的groupby操作
- R 语言实现股票数据的预处理及分析
- 图像的预处理操作
- 数据分析的一些思考
- C++11可变模板参数
- 计算几何常用算法总结
- 疑难解答
- 目标追踪-背景分割
- 【IOS学习之常见问题】 app维护可能遇到的问题
- 分析运维数据的一些预处理操作
- android开发简单图片浏览器
- java中堆内存和栈内存的区别
- 如何撰写学术论文
- 告诉你真实的跳跃表
- 习题 5.13 用迭代法求x=根号a。
- Android编译系统
- 算法系列——Set Matrix Zeroes
- Spring使用@PostConstruct注解完成子类注入父类私有变量