com.aliyun.openservices.log.common.QueriedLog Java Examples

The following examples show how to use com.aliyun.openservices.log.common.QueriedLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdminRequestLogController.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 折线图,当月(最近30天),每天的访问情况
 */
@RequiresPermissions("adminRequestLogFangWen")
@RequestMapping("dayLineForCurrentMonth${url.suffix}")
@ResponseBody
public RequestLogDayLineVO dayLineForCurrentMonth(HttpServletRequest request) throws LogException{
	RequestLogDayLineVO vo = new RequestLogDayLineVO();
	
	//当前10位时间戳
	int currentTime = DateUtil.timeForUnix10();
	String query = "Mozilla | timeslice 24h | count as c";
	
	//当月访问量统计
	ArrayList<QueriedLog> jinriQlList = Log.aliyunLogUtil.queryList(query, "", DateUtil.getDateZeroTime(currentTime - 2592000), currentTime, 0, 100, true);
	
	JSONArray jsonArrayDate = new JSONArray();	//天数
	JSONArray jsonArrayFangWen = new JSONArray();	//某天访问量,pv
	for (int i = 0; i < jinriQlList.size(); i++) {
		LogItem li = jinriQlList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		try {
			jsonArrayDate.add(DateUtil.dateFormat(json.getInt("logtime"), "MM-dd"));
		} catch (NotReturnValueException e) {
			e.printStackTrace();
		}
		jsonArrayFangWen.add(json.getInt("c"));
	}
	vo.setJsonArrayFangWen(jsonArrayFangWen);
	vo.setJsonArrayDate(jsonArrayDate);
	
	AliyunLog.addActionLog(0, "总管理后台,获取最近30天的访问数据统计记录");
	
	return vo;
}
 
Example #2
Source File: LogAdminController_.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 折线图,当月(最近30天),每天的访问情况
 */
@RequiresPermissions("adminLogCartogram")
@RequestMapping("dayLineForCurrentMonth${url.suffix}")
@ResponseBody
public LogLineGraphVO dayLineForCurrentMonth(HttpServletRequest request) throws LogException{
	LogLineGraphVO vo = new LogLineGraphVO();
	
	//当前10位时间戳
	int currentTime = DateUtil.timeForUnix10();
	String query = "Mozilla | timeslice 24h | count as c";
	
	//当月访问量统计
	ArrayList<QueriedLog> jinriQlList = ActionLogCache.aliyunLogUtil.queryList(query, "", DateUtil.getDateZeroTime(currentTime - 2592000), currentTime, 0, 100, true);
	
	JSONArray jsonArrayDate = new JSONArray();	//天数
	JSONArray jsonArrayFangWen = new JSONArray();	//某天访问量,pv
	for (int i = 0; i < jinriQlList.size(); i++) {
		LogItem li = jinriQlList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		try {
			jsonArrayDate.add(DateUtil.dateFormat(json.getInt("logtime"), "MM-dd"));
		} catch (NotReturnValueException e) {
			e.printStackTrace();
		}
		jsonArrayFangWen.add(json.getInt("c"));
	}
	vo.setDataArray(jsonArrayFangWen);
	vo.setNameArray(jsonArrayDate);
	
	return vo;
}
 
Example #3
Source File: AliyunLogUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) throws LogException, InterruptedException, NotReturnValueException {
    AliyunLogUtil aliyunLogUtil = new AliyunLogUtil("cn-hongkong.log.aliyuncs.com", "121212", "121212", "requestlog", "fangwen");
		
    ArrayList<QueriedLog> qlList = aliyunLogUtil.queryList("*", "leiwen.wang.market", DateUtil.timeForUnix10()-10000000, DateUtil.timeForUnix10(), 0, 100, true);
   	for (int i = 0; i < qlList.size(); i++) {
   		System.out.println(i);
   		QueriedLog ll = qlList.get(i);
   		LogItem li = ll.GetLogItem();
   		System.out.println(li.GetLogContents().toString());
   	} 
   	System.out.println("qlList  :  "+qlList.size());
}
 
Example #4
Source File: AliyunLogPageUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 列出日志服务的列表记录
 * <br/>获取当前生成得分页信息可用 {@link #getPage()} 得到
 * @param query 查询条件。若divQuery为true,开启用户自定义检索,这里会先将query的查询条件作为首要查询。总之查询时无论是用户传入什么条件,都会加上此指定的查询条件一并 and 查询。(<a href="https://help.aliyun.com/document_detail/29060.html">查询语法参考</a>)
 * @param topic topic主题,若不指定查询主题,可为空字符串""
 * @param divQuery 是否开启用户自定义检索。若是开启,则用户可以通过<a href="https://help.aliyun.com/document_detail/29060.html">查询语法</a>进行自定义查询。GET或者POST传入queryString=查询条件
 * @param startTime 筛选日志的开始时间,10位时间戳,若为0,则为结束时间以前1000天的时刻
 * @param endTime 筛选日志的结束时间,10位时间戳,若为0,则为当前时间
 * @param everyPageNumber 分页列表每页显示的条数
 * @param request 主要用于获取当前url中的get传递的参数。分页数都是通过get传递的。同样,分页的参数也是自动根据这个计算出来的
 * @return 返回查询的结果。
 * @throws LogException
 */
public ArrayList<QueriedLog> list(String query, String topic, boolean divQuery, int startTime, int endTime, int everyPageNumber, HttpServletRequest request) throws LogException{
	if(endTime == 0){
		endTime = DateUtil.timeForUnix10();
	}
	if(startTime == 0){
		startTime = DateUtil.getDateZeroTime(endTime - 86400000);	
	}
	
	if(divQuery){
		String queryStringRequest = request.getParameter("queryString");	//查询的关键词,可模糊查询
		if(queryStringRequest == null || queryStringRequest.length() == 0){
		}else{
			if(query != null && query.length() > 0){
				query = query + " and "+queryStringRequest;
			}else{
				query = queryStringRequest;
			}
		}
	}
	
	//统计1000天内的符合条件的总数量
	int count = (int) aliyunLogUtil.queryCount(query, "", startTime, endTime);
	
	page = new Page(count, everyPageNumber, request);
	
	//最近三个月访问量统计
	ArrayList<QueriedLog> logList = aliyunLogUtil.queryList(query, "", startTime, endTime, page.getLimitStart(), page.getEveryNumber(), true);
	return logList;
}
 
Example #5
Source File: AliyunLogUtil.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 统计符合条件的日志的记录条数
 * <br/><b>只有阿里云日志控制台打开索引功能,才能使用此接口</b>
 * <br/>最新数据有1分钟延迟时间
 * <br/>使用示例:
 * <pre>
 * 		ArrayList<QueriedLog> qlList = aliyunLogUtil.queryList("", "", DateUtil.timeForUnix10()-10000, DateUtil.timeForUnix10(), 0, 100, true);
 * 		for (int i = 0; i < qlList.size(); i++) {
 * 			QueriedLog ll = qlList.get(i);
 * 			LogItem li = ll.GetLogItem();
 * 			JSONObject json = JSONObject.fromObject(li.ToJsonString());
 * 			System.out.println(DateUtil.dateFormat(json.getLong("logtime"), com.xnx3.DateUtil.FORMAT_DEFAULT)+"__"+li.ToJsonString());
 * 		}
 * </pre>
 * @param query 查询表达式。为空字符串""则查询所有。关于查询表达式的详细语法,请参考 <a href="https://help.aliyun.com/document_detail/29060.html">查询语法 https://help.aliyun.com/document_detail/29060.html</a>
 * @param topic 查询日志主题。为空字符串""则查询所有。
 * @param startTime 查询开始时间点(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数)。10位时间戳,可用 {@link DateUtil#timeForUnix10()} 取得
 * @param endTime 查询结束时间点,10位时间戳,可用 {@link DateUtil#timeForUnix10()} 取得
 * @param offset 请求返回日志的起始点。取值范围为 0 或正整数,默认值为 0。
 * @param line 请求返回的最大日志条数。取值范围为 0~100,默认值为 100。
 * @param reverse 是否按日志时间戳逆序返回日志。
 * 			<ul>
 * 				<li>true : 逆序,时间越大越靠前</li>
 * 				<li>false : 顺序,时间越大越靠后</li>
 * 			</ul>			
 * @return {@link QueriedLog}数组,将每条日志内容都详细列出来。若返回null,则是读取失败
 * @throws LogException 
 */
public ArrayList<QueriedLog> queryList(String query, String topic, int startTime, int endTime, int offset, int line, boolean reverse) throws LogException{
   	GetLogsResponse res4 = null;
   	//对于每个 log offset,一次读取 10 行 log,如果读取失败,最多重复读取 3 次。
   	for (int retry_time = 0; retry_time < 3; retry_time++) {
   		GetLogsRequest req4 = new GetLogsRequest(project, logstore, startTime, endTime, topic, query, offset, line, reverse);
   		res4 = client.GetLogs(req4);
   		if (res4 != null && res4.IsCompleted()) {
   			break;
   		}
   	}
   	if(res4 == null){
   		return null;
   	}
       return res4.GetLogs();
}
 
Example #6
Source File: AliyunLogPageUtil.java    From xnx3 with Apache License 2.0 3 votes vote down vote up
/**
 * 获取当前页面的JSONArray的数据。该数据可以直接在Spring MVC的view中通过c:forEach遍历出后,直接进行listitem.logtime这种形式调出
 * <br/>获取当前生成得分页信息可用 {@link #getPage()} 得到
 * @param query 查询条件。若divQuery为true,开启用户自定义检索,这里会先将query的查询条件作为首要查询。总之查询时无论是用户传入什么条件,都会加上此指定的查询条件一并 and 查询。(<a href="https://help.aliyun.com/document_detail/29060.html">查询语法参考</a>)
 * @param topic topic主题,若不指定查询主题,可为空字符串""
 * @param divQuery 是否开启用户自定义检索。若是开启,则用户可以通过<a href="https://help.aliyun.com/document_detail/29060.html">查询语法</a>进行自定义查询。GET或者POST传入queryString=查询条件
 * @param startTime 筛选日志的开始时间,10位时间戳,若为0,则为结束时间以前1000天的时刻
 * @param endTime 筛选日志的结束时间,10位时间戳,若为0,则为当前时间
 * @param everyPageNumber 分页列表每页显示的条数
 * @param request 主要用于获取当前url中的get传递的参数。分页数都是通过get传递的。同样,分页的参数也是自动根据这个计算出来的
 * @return 返回查询的结果。
 * @throws LogException
 */
public JSONArray listForJSONArray(String query, String topic, boolean divQuery, int startTime, int endTime, int everyPageNumber, HttpServletRequest request) throws LogException{
	//super.list(query, topic, divQuery, startTime, endTime, everyPageNumber, request)
	ArrayList<QueriedLog> logList = list(query, topic, divQuery, startTime, endTime, everyPageNumber, request);
	JSONArray jsonArray = new JSONArray();	//访问量,pv
	for (int i = 0; i < logList.size(); i++) {
		LogItem li = logList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		jsonArray.add(json);
	}
	
	return jsonArray;
}