windows下eclipse项目KPIUrlViewerCounter操作hadoop2.8.3 mapreduce(4)

本文详细介绍了在Windows环境下使用Eclipse进行KPIUrlViewerCounter项目的Hadoop MapReduce操作。首先提到了hadoop环境的搭建,数据准备来源于指定链接,并要求将数据上传到HDFS的特定路径。接着,文章描述了如何根据数据样例设计相关类,进行数据解析与过滤,并计算页面访问量。最后,阐述了运行该项目所需的知识和查看结果的方法。

hadoop环境搭建详情见hadoop系列第一篇与第三篇博客(hadoop配置直接影响到本程序的运行) 

数据准备(https://download.youkuaiyun.com/download/elmo66/10636257):

[hadoop@yourname ~]$ hadoop dfs -mkdir /UrlViewerCounter
[hadoop@yourname ~]$ hadoop dfs -mkdir /UrlViewerCounter/input
[hadoop@yourname ~]$ hadoop dfs -copyFromLocal access.log.10 /UrlViewerCounter/input/

yourname详见hadoop系列第一篇博客;hadoop是登录linux系统的用户名;~指/home/hadoop目录;test.txt是在/home/hadoop目录下,上传到hdfs中/UrlViewerCounter/input/目录下

数据样例:

60.208.6.156 - - [18/Sep/2013:06:49:48 +0000] "GET /wp-content/uploads/2013/07/rcassandra.png HTTP/1.0" 200 185524 "http://cos.name/category/software/packages/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"

根据样例设计类:

public class KPI {
    private String clientAddr;// 记录客户端的ip地址
    private String clientName;// 记录客户端用户名称,忽略属性"-"
    private String clientRequestTime;// 记录访问时间与时区
    
    private String clientRequestMethod;// 记录请求的方式
    private String clientRequestUrl;// 记录请求的url
    private String clientRequestProtocol;// 记录请求的http协议
    
    private String responseStatus;// 记录请求状态;成功是200
    private String responseBytes;// 记录发送给客户端文件主体内容大小
    private String urlReferer;// 用来记录从那个页面链接访问过来的
    private String httpAgent;// 记录客户浏览器的相关信息

    private boolean valid = true;// 判断数据是否合法

    public String getClientAddr() {
		return clientAddr;
	}
	public void setClientAddr(String clientAddr) {
		this.clientAddr = clientAddr;
	}
	public String getClientName() {
		return clientName;
	}
	public void setClientName(String clientName) {
		this.clientName = clientName;
	}
	public String getClientRequestTime() {
		return clientRequestTime;
	}
	public void setClientRequestTime(String clientRequestTime) {
		this.clientRequestTime = clientRequestTime;
	}
	public String getClientRequestMethod() {
		return clientRequestMethod;
	}
	public void setClientRequestMethod(String clientRequestMethod) {
		this.clientRequestMethod = clientRequestMethod;
	}
	public String getClientRequestUrl() {
		return clientRequestUrl;
	}
	public void setClientRequestUrl(String clientRequestUrl) {
		this.clientRequestUrl = clientRequestUrl;
	}
	public String getClientRequestProtocol() {
		return clientRequestProtocol;
	}
	public void setClientRequestProtocol(String clientRequestProtocol) {
		this.clientRequestProtocol = clientRequestProtocol;
	}
	public String getResponseStatus() {
		return responseStatus;
	}
	public void setResponseStatus(String responseStatus) {
		this.responseStatus = responseStatus;
	}
	public String getResponseBytes() {
		return responseBytes;
	}
	public void setResponseBytes(String responseBytes) {
		this.responseBytes = responseBytes;
	}
	public String getUrlReferer() {
		return urlReferer;
	}
	public void setUrlReferer(String urlReferer) {
		this.urlReferer = urlReferer;
	}
	public String getHttpAgent() {
		return httpAgent;
	}
	public void setHttpAgent(String httpAgent) {
		this.httpAgent = httpAgent;
	}
	public boolean isValid() {
		return valid;
	}
	public void setValid(boolean valid) {
		this.valid = valid;
	}
	
	@Override
	public String toString() {
		return "KPI [clientAddr=" + clientAddr + ", clientName=" + clientName + ", clientRequestTime="
				+ clientRequestTime + ", clientRequestMethod=" + clientRequestMethod + ", clientRequestUrl="
				+ clientRequestUrl + ", clientRequestProtocol=" + clientRequestProtocol + ", responseStatus="
				+ responseStatus + ", responseBytes=" + responseBytes + ", urlReferer=" + urlReferer + ", httpAgent="
				+ httpAgent + ", valid=" + valid + "]";
	}
}

 数据解析与过滤:

public class KPIUtils {
	
	public static KPI kpiParse(String line) {
        System.out.println(line);
        KPI kpi = new KPI();
        String[] arr = line.split(" ");
        if (arr.length >= 12) {
	        kpi.setClientAddr(arr[0]);
	        kpi.setClientName(arr[1]);
	        kpi.setClientRequestTime(arr[3].replace("[", ""));
	        kpi.setClientRequestMethod(arr[5].replace("\"", ""));
	        kpi.setClientRequestUrl(arr[6]);
	        kpi.setClientRequestProtocol(arr[7].replace("\"", ""));
	        kpi.setResponseStatus(arr[8]);
	        kpi.setResponseBytes(arr[9]);
	        kpi.setUrlReferer(arr[10]);
	        kpi.setHttpAgent(arr[11]);
            
            kpi.setValid(true);
        } else {
            kpi.setValid(false);
        }
        return kpi;
    }

	public static KPI urlFilter(String line) {
        KPI kpi = kpiParse(line);
        
        Set<String> urls = new HashSet<String>();
        //数据量大的情况下,list的contaions效率慢
        //List<String> urls = new ArrayList<String>();
        urls.add("/about");
        urls.add("/black-ip-list/");
        urls.add("/cassandra-clustor/");
        urls.add("/finance-rhive-repurchase/");
        urls.add("/hadoop-family-roadmap/");
        urls.add("/hadoop-hive-intro/");
        urls.add("/hadoop-zookeeper-intro/");
        urls.add("/hadoop-mahout-roadmap/");

        if (!urls.contains(kpi.getClientRequestUrl())) {
            kpi.setValid(false);
        }
        return kpi;
    }

}

页面(url)访问量:

package com.hadoop.kpi;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class KPIUrlViewerCounter { 

    public static class KPIUrlViewerMapper extends Mapper<Object, Text, Text, IntWritable> {
        private IntWritable one = new IntWritable(1);
        private Text word = new Text();

        @Override
        protected void map(Object key, Text value, Mapper<Object, Text, Text, IntWritable>.Context context)
        		throws IOException, InterruptedException {
        	KPI kpi = KPIUtils.urlFilter(value.toString());
            if (kpi.isValid()) {
                word.set(kpi.getClientRequestUrl());
                context.write(word, one);
            }
        }
    }

    public static class KPIUrlViewerReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
        private IntWritable result = new IntWritable();

        @Override
        protected void reduce(Text key, Iterable<IntWritable> values,
        		Reducer<Text, IntWritable, Text, IntWritable>.Context output) throws IOException, InterruptedException {
        	int sum = 0;
        	for(IntWritable value : values){
        		sum += value.get();
        	}
            result.set(sum);
            output.write(key, result);
        }
    }

    public static void main(String[] args) throws Exception {
    	String input = "hdfs://192.168.1.101:9000/UrlViewerCounter/input";
        String output = "hdfs://192.168.1.101:9000/UrlViewerCounter/output";
        
        Configuration conf = new Configuration();
        //配置信息不可缺少
        conf.set("mapreduce.framework.name","yarn");
        conf.set("yarn.resourcemanager.hostname","192.168.1.101");
        conf.set("fs.defaultFS","hdfs://192.168.1.101:9000/");
        conf.set("mapreduce.app-submission.cross-platform", "true");
        conf.set("mapreduce.jobhistory.address", "192.168.1.101:10020");
        
        Job job = Job.getInstance(conf);
        job.setJarByClass(KPIUrlViewerCounter.class);
        //先打包再运行
        job.setJar("E:/KPIUrlViewerCounter.jar");
        job.setJobName("KPIUrlViewerCounter");
        
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
 
        job.setMapperClass(KPIUrlViewerMapper.class);
        job.setCombinerClass(KPIUrlViewerReducer.class);
        job.setReducerClass(KPIUrlViewerReducer.class);
 
        FileInputFormat.addInputPath(job, new Path(input));
        FileOutputFormat.setOutputPath(job, new Path(output));
 
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }

}

运行必备知识、查看结果方式详见上一篇博客

运行结果(对错可以对比原数据):

/about	5
/black-ip-list/	2
/cassandra-clustor/	3
/finance-rhive-repurchase/	13
/hadoop-family-roadmap/	13
/hadoop-hive-intro/	14
/hadoop-mahout-roadmap/	20
/hadoop-zookeeper-intro/	6

 

如果本篇博客对你有帮助,请记得打赏给小哥哥哦丷丷。

下载前可以先看下教程 https://pan.quark.cn/s/a426667488ae 标题“仿淘宝jquery图片左右切换带数字”揭示了这是一个关于运用jQuery技术完成的图片轮播机制,其特色在于具备淘宝在线平台普遍存在的图片切换表现,并且在整个切换环节中会展示当前图片的序列号。 此类功能一般应用于电子商务平台的产品呈现环节,使用户可以便捷地查看多张商品的照片。 说明中的“NULL”表示未提供进一步的信息,但我们可以借助标题来揣摩若干核心的技术要点。 在构建此类功能时,开发者通常会借助以下技术手段:1. **jQuery库**:jQuery是一个应用广泛的JavaScript框架,它简化了HTML文档的遍历、事件管理、动画效果以及Ajax通信。 在此项目中,jQuery将负责处理用户的点击动作(实现左右切换),并且制造流畅的过渡效果。 2. **图片轮播扩展工具**:开发者或许会采用现成的jQuery扩展,例如Slick、Bootstrap Carousel或个性化的轮播函数,以达成图片切换的功能。 这些扩展能够辅助迅速构建功能完善的轮播模块。 3. **即时数字呈现**:展示当前图片的序列号,这需要通过JavaScript或jQuery来追踪并调整。 每当图片切换时,相应的数字也会同步更新。 4. **CSS美化**:为了达成淘宝图片切换的视觉效果,可能需要设计特定的CSS样式,涵盖图片的排列方式、过渡效果、点状指示器等。 CSS3的动画和过渡特性(如`transition`和`animation`)在此过程中扮演关键角色。 5. **事件监测**:运用jQuery的`.on()`方法来监测用户的操作,比如点击左右控制按钮或自动按时间间隔切换。 根据用户的交互,触发相应的函数来执行...
垃圾实例分割数据集 一、基础信息 • 数据集名称:垃圾实例分割数据集 • 图片数量: 训练集:7,000张图片 验证集:426张图片 测试集:644张图片 • 训练集:7,000张图片 • 验证集:426张图片 • 测试集:644张图片 • 分类类别: 垃圾(Sampah) • 垃圾(Sampah) • 标注格式:YOLO格式,包含实例分割的多边形点坐标,适用于实例分割任务。 • 数据格式:图片文件 二、适用场景 • 智能垃圾检测系统开发:数据集支持实例分割任务,帮助构建能够自动识别和分割图像中垃圾区域的AI模型,适用于智能清洁机器人、自动垃圾桶等应用。 • 环境监控与管理:集成到监控系统中,用于实时检测公共区域的垃圾堆积,辅助环境清洁和治理决策。 • 计算机视觉研究:支持实例分割算法的研究和优化,特别是在垃圾识别领域,促进AI在环保方面的创新。 • 教育与实践:可用于高校或培训机构的AI课程,作为实例分割技术的实践数据集,帮助学生理解计算机视觉应用。 三、数据集优势 • 精确的实例分割标注:每个垃圾实例都使用详细的多边形点进行标注,确保分割边界准确,提升模型训练效果。 • 数据多样性:包含多种垃圾物品实例,覆盖不同场景,增强模型的泛化能力和鲁棒性。 • 格式兼容性强:YOLO标注格式易于与主流深度学习框架集成,如YOLO系列、PyTorch等,方便研究人员和开发者使用。 • 实际应用价值:直接针对现实世界的垃圾管理需求,为自动化环保解决方案提供可靠数据支持,具有重要的社会意义。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值