com.aliyun.openservices.log.exception.LogException Java Examples

The following examples show how to use com.aliyun.openservices.log.exception.LogException. 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: AliyunSLSLogger.java    From utils with Apache License 2.0 6 votes vote down vote up
@Override
public void log(String store, String topic, String source, Object... args) {
    List<LogItem> logs = new ArrayList<LogItem>();

    LogItem item = new LogItem((int) (System.currentTimeMillis() / 1000));
    for (int i = 0; i < args.length; ++i) {
        item.PushBack(String.valueOf(args[i]), String.valueOf(args[++i]));
    }
    logs.add(item);

    PutLogsRequest req = new PutLogsRequest(project, store, topic, source, logs);
    try {
        client.PutLogs(req);
    } catch (LogException ex) {
        //Logger.log(ex);
    }
}
 
Example #2
Source File: LogClientProxy.java    From aliyun-log-flink-connector with Apache License 2.0 6 votes vote down vote up
public void updateCheckpoint(final String project,
                             final String logstore,
                             final String consumerGroup,
                             final int shard,
                             final boolean readOnly,
                             final String checkpoint) throws LogException {
    if (checkpoint == null || checkpoint.isEmpty()) {
        LOG.warn("The checkpoint to update is invalid: {}", checkpoint);
        return;
    }
    try {
        RetryUtil.call((Callable<Void>) () -> {
            client.UpdateCheckPoint(project, logstore, consumerGroup, shard, checkpoint);
            return null;
        }, "Error while updating checkpoint");
    } catch (LogException ex) {
        if ("ConsumerGroupNotExist".equalsIgnoreCase(ex.GetErrorCode())) {
            LOG.warn("Consumer group not exist: {}", consumerGroup);
        } else if ("ShardNotExist".equalsIgnoreCase(ex.GetErrorCode())) {
            LOG.warn("Shard {} not exist, readonly = {}", shard, readOnly);
        } else {
            throw ex;
        }
    }
}
 
Example #3
Source File: AdminRequestLogController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 网站访问记录日志列表
 * @throws LogException 
 */
@RequiresPermissions("adminLogList")
@RequestMapping("fangwenList${url.suffix}")
public String fangwenList(HttpServletRequest request,Model model) throws LogException{
	if(Log.aliyunLogUtil == null){
		return error(model, "您未开启网站访问相关的日志服务!无法查看网站访问日志");
	}
	AliyunLogPageUtil log = new AliyunLogPageUtil(Log.aliyunLogUtil);
	
	//得到当前页面的列表数据
	JSONArray jsonArray = log.list("", "", true, 100, request);
	
	//得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页)
	Page page = log.getPage();
	//设置分页,出现得上几页、下几页跳转按钮的个数
	page.setListNumber(3);
	
	ActionLogCache.insert(request, "查看总管理后台网站访问日志列表", "第"+page.getCurrentPageNumber()+"页");
	
	model.addAttribute("list", jsonArray);
	model.addAttribute("page", page);
	return "/admin/requestLog/fangwenList";
}
 
Example #4
Source File: LogClientProxy.java    From aliyun-log-flink-connector with Apache License 2.0 6 votes vote down vote up
public List<String> listLogstores(String project, Pattern pattern) {
    List<String> logstores = new ArrayList<>();
    try {
        int offset = 0;
        int batchSize = 100;
        while (true) {
            ListLogStoresResponse response = client.ListLogStores(project, offset, batchSize, "");
            filter(response.GetLogStores(), pattern, logstores);
            if (response.GetCount() < batchSize) {
                break;
            }
            offset += batchSize;
        }
    } catch (LogException ex) {
        LOG.warn("Error listing logstores", ex);
    }
    return logstores;
}
 
Example #5
Source File: AgencyUserController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 操作日志
 * @throws LogException 
 */
@RequiresPermissions("agencyActionLogList")
@RequestMapping("actionLogList${url.suffix}")
public String actionLogList(HttpServletRequest request, Model model) throws LogException{
	if(AliyunLog.aliyunLogUtil == null){
		return error(model, "未开启日志服务");
	}
	AliyunLogPageUtil log = new AliyunLogPageUtil(AliyunLog.aliyunLogUtil);
	
	//得到当前页面的列表数据
	JSONArray jsonArray = log.list("userid="+getUserId(), "", false, 15, request);
	
	//得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页)
	Page page = log.getPage();
	
	AliyunLog.addActionLog(0, "获取代理操作记录");
	
	model.addAttribute("list", jsonArray);
	model.addAttribute("page", page);
	return "agency/actionLogList";
}
 
Example #6
Source File: LogClientProxy.java    From aliyun-log-flink-connector with Apache License 2.0 6 votes vote down vote up
public String fetchCheckpoint(final String project,
                              final String logstore,
                              final String consumerGroup,
                              final int shard) throws LogException {
    return RetryUtil.call(() -> {
        try {
            ConsumerGroupCheckPointResponse response = client.GetCheckPoint(project, logstore, consumerGroup, shard);
            List<ConsumerGroupShardCheckPoint> checkpoints = response.getCheckPoints();
            if (checkpoints == null || checkpoints.isEmpty()) {
                LOG.info("No checkpoint found for shard {}, consumer group {}", shard, consumerGroup);
                return null;
            }
            ConsumerGroupShardCheckPoint checkpoint = checkpoints.get(0);
            if (checkpoint != null) {
                LOG.info("Got checkpoint {} from consumer group {} for shard {}", checkpoint.getCheckPoint(), consumerGroup, shard);
                return checkpoint.getCheckPoint();
            }
        } catch (LogException ex) {
            if (!ex.GetErrorCode().contains("NotExist")) {
                throw ex;
            }
        }
        return null;
    }, "Error while getting checkpoint");
}
 
Example #7
Source File: AgencyUserController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 资金变动日志
 * @throws LogException 
 */
@RequiresPermissions("agencySiteSizeLogList")
@RequestMapping("siteSizeLogList${url.suffix}")
public String siteSizeLogList(HttpServletRequest request, Model model) throws LogException{
	if(SiteSizeChangeLog.aliyunLogUtil == null){
		return error(model, "未开启日志服务");
	}
	//当前10位时间戳
	String query = "userid="+getUserId();
	AliyunLogPageUtil log = new AliyunLogPageUtil(SiteSizeChangeLog.aliyunLogUtil);
	
	//得到当前页面的列表数据
	JSONArray jsonArray = log.list(query, "", true, 15, request);
	
	//得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页)
	Page page = log.getPage();
	//设置分页,出现得上几页、下几页跳转按钮的个数
	page.setListNumber(2);
	
	model.addAttribute("list", jsonArray);
	model.addAttribute("page", page);
	
	return "agency/siteSizeLogList";
}
 
Example #8
Source File: SlsSourceFunction.java    From alibaba-flink-connectors with Apache License 2.0 6 votes vote down vote up
private void init() {
	/**
	 * conuserGroup一旦创建后会保存在服务端。
	 * 首先创建consumerGroup,如果之前已经创建过则比较conuserGroup的信息是否一致,
	 */
	if (null != consumerGroup) {
		try {
			ConsumerGroup group = new ConsumerGroup(consumerGroup, 60, true);
			slsClientProvider.getClient().CreateConsumerGroup(project, logStore, group);
		} catch (LogException e) {
			//如果服务端不存在则抛异常
			if (e.GetErrorCode().compareToIgnoreCase("ConsumerGroupAlreadyExist") != 0) {
				ErrorUtils.throwException(
						"error occour when create consumer group, errorCode: " + e.GetErrorCode() +
						", errorMessage: " + e.GetErrorMessage());
			}
		}
	}
}
 
Example #9
Source File: KefuLog.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
public void run() {
	if(Global.aliyunLogUtil == null){
		return;
	}
	System.out.println("KefuLog 已开启自动提交线程,每间隔一分钟会自动提交一次");
	while(true){
		try {
			Thread.sleep(60000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		
		try {
			//如果其中有值,则自动提交
			if(Global.aliyunLogUtil.logGroupCache.size() > 0){
				Global.aliyunLogUtil.cacheCommit();
			}
		} catch (LogException e) {
			System.out.println("日志用多线程自动提交出现问题");
			e.printStackTrace();
		}
	}
}
 
Example #10
Source File: KefuLog.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
public static void insert(Message msg){
	if(Global.aliyunLogUtil == null){
		return;
	}
	LogItem item = Global.aliyunLogUtil.newLogItem();
	
	//发送方
	item.PushBack("sendId", msg.getSendId()+"");
	item.PushBack("sendUserName", msg.getSendUserName());
	//接收方
	item.PushBack("receiveId", msg.getReceiveId()+"");
	item.PushBack("receiveUserName", msg.getReceiveUserName());
	//发送的消息内容
	item.PushBack("content", msg.getContent());
	//接收方的socket标示
	item.PushBack("receiveSocketId", msg.getSocketId()+"");
	item.PushBack("receiveSocketUuid", msg.getSocketUuid());
	
	try {
		Global.aliyunLogUtil.cacheLog(item);
	} catch (LogException e) {
		e.printStackTrace();
	}
}
 
Example #11
Source File: SendProducerBatchTask.java    From aliyun-log-java-producer with Apache License 2.0 6 votes vote down vote up
private boolean isRetriableException(Exception e) {
  if (e instanceof LogException) {
    LogException logException = (LogException) e;
    return (logException.GetErrorCode().equals(RetriableErrors.REQUEST_ERROR)
        || logException.GetErrorCode().equals(RetriableErrors.UNAUTHORIZED)
        || logException.GetErrorCode().equals(RetriableErrors.WRITE_QUOTA_EXCEED)
        || logException.GetErrorCode().equals(RetriableErrors.SHARD_WRITE_QUOTA_EXCEED)
        || logException.GetErrorCode().equals(RetriableErrors.EXCEED_QUOTA)
        || logException.GetErrorCode().equals(RetriableErrors.INTERNAL_SERVER_ERROR)
        || logException.GetErrorCode().equals(RetriableErrors.SERVER_BUSY)
        || logException.GetErrorCode().equals(RetriableErrors.BAD_RESPONSE)
        || logException.GetErrorCode().equals(RetriableErrors.PROJECT_NOT_EXISTS)
        || logException.GetErrorCode().equals(RetriableErrors.LOGSTORE_NOT_EXISTS));
  }
  return false;
}
 
Example #12
Source File: ImController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
@RequestMapping("previewByToken${url.suffix}")
public String previewByToken(HttpServletRequest request,Model model,
		@RequestParam(value = "token", required = false , defaultValue="") String token){
	//进行安全过滤
	token = token.replaceAll("\\s*", "");
	token = filter(token);
	if(token.length() != 64){
		return error(model, "授权码错误");
	}else{
		int currentTime = DateUtil.timeForUnix10();
		int startTime = currentTime - 86400*30;	//30天内有效
		try {
			AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil);
			JSONArray jsonArray = log.listForJSONArray("receiveSocketUuid="+token, "", false, startTime, currentTime, 100, request);
			model.addAttribute("list", jsonArray);
		} catch (LogException e) {
			e.printStackTrace();
		}
	}
	
	return "im/perviewByToken";
}
 
Example #13
Source File: ImController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 历史聊天人列表,会话列表,每一项都是一个人
 */
@RequestMapping("hostoryChatList${url.suffix}")
public String hostoryChatList(HttpServletRequest request,Model model){
	if(Global.aliyunLogUtil == null){
		return error(model, "您未开启IM客服访问相关的日志服务!");
	}
	User user = getUser();
	int currentTime = DateUtil.timeForUnix10();
	int startTime = currentTime - 86400*30;	//30天内有效
	try {
		AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil);
		JSONArray jsonArray = log.listForJSONArray("receiveId = "+user.getId()+" | select max(sendId) , map_agg('array',sendUserName) as sendUserName,max(sendId) as sendIds, count(*) as count, max(__time__) as time group by sendId order by time desc limit 100", "", false, startTime, currentTime, 100, request);
		model.addAttribute("list", jsonArray);
	} catch (LogException e) {
		e.printStackTrace();
	}
	
	return "im/hostoryChatList";
}
 
Example #14
Source File: LogProducerTest.java    From aliyun-log-producer-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendToMultiProjects() {
    producer.setProjectConfig(buildProjectConfig1());
    producer.setProjectConfig(buildProjectConfig2());

    TestCallback testCallback1 = mock(TestCallback.class);
    TestCallback testCallback2 = mock(TestCallback.class);
    producer.send(System.getenv("project1"), "store_1s", "topic1", MOCK_IP, getLogItems(),
            testCallback1);
    producer.send(System.getenv("project2"), "store_1s", "topic2", MOCK_IP, getLogItems(),
            testCallback2);
    producer.flush();
    producer.close();

    verify(testCallback1, times(1)).onCompletion(ArgumentMatchers.any(PutLogsResponse.class),
            (LogException) isNull());
    verify(testCallback2, times(1)).onCompletion(ArgumentMatchers.any(PutLogsResponse.class),
            (LogException) isNull());
}
 
Example #15
Source File: ImController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 聊天记录,跟某个人之间,一个会话的聊天记录,两个人之间的聊天记录
 * @param id 跟自己会话的那个人的id,对方的id
 */
@RequestMapping("chatRecord${url.suffix}")
public String chatRecord(HttpServletRequest request,Model model,
		@RequestParam(value = "id", required = false , defaultValue="0") long id){
	if(id == 0){
		return error(model, "请输入要查看得对方得id编号");
	}
	User user = getUser();
	int currentTime = DateUtil.timeForUnix10();
	int startTime = currentTime - 86400*30;	//30天内有效
	try {
		AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil);
		JSONArray jsonArray = log.listForJSONArray("(receiveId = "+user.getId()+" and sendId = "+id+" ) or (receiveId = "+id+" and sendId = "+user.getId()+" )", "", false, startTime, currentTime, 100, request);
		JSONArray ja = new JSONArray();	//将其倒序
		for (int i = jsonArray.size()-1; i >-1 ; --i) {
			ja.add(jsonArray.get(i));
		}
		model.addAttribute("list", ja);
	} catch (LogException e) {
		e.printStackTrace();
	}
	
	model.addAttribute("user", user);
	return "im/chatRecord";
}
 
Example #16
Source File: Log.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
public static void requestLog(HttpServletRequest request, RequestInfo requestInfo, SImpleSiteVO simpleSiteVO){
	//未开启日志记录
	if(aliyunLogUtil == null){
		return;
	}
	if(simpleSiteVO.getResult() - SImpleSiteVO.FAILURE == 0){
		//失败的,没有访问正规站点的,可能是ip直接访问的,或者访问的未绑定上的域名过来的。这样的不与记录。
		return;
	}
	
	LogItem logItem = new LogItem(DateUtil.timeForUnix10());
	logItem.PushBack("ip", requestInfo.getIp());
	logItem.PushBack("referer", requestInfo.getReferer());
	logItem.PushBack("userAgent", requestInfo.getUserAgent());
	logItem.PushBack("htmlFile", requestInfo.getHtmlFile());
	logItem.PushBack("siteid", simpleSiteVO.getSimpleSite().getId()+"");
	logItem.PushBack("serverName", requestInfo.getServerName());
	
	try {
		aliyunLogUtil.cacheLog(logItem);
	} catch (LogException e1) {
		e1.printStackTrace();
	}
}
 
Example #17
Source File: LogProducerTrySendTest.java    From aliyun-log-producer-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSend() {
    producer.setProjectConfig(buildProjectConfig());

    TestCallback testCallback = mock(TestCallback.class);
    boolean res = producer.trySend(
            System.getenv("project1"),
            "store_1s",
            "topic1",
            MOCK_IP,
            getLogItems(),
            testCallback
    );
    producer.flush();
    producer.close();
    assertTrue(!res);

    verify(testCallback, times(0)).onCompletion(ArgumentMatchers.any(PutLogsResponse.class),
            (LogException) isNull());
}
 
Example #18
Source File: LogAdminController_.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
	 * 日志列表
	 * @throws LogException 
	 */
	@RequiresPermissions("adminLogList")
	@RequestMapping("list${url.suffix}")
	public String list(HttpServletRequest request,Model model) throws LogException{
		if(ActionLogCache.aliyunLogUtil == null){
			return error(model, "您未开启日志服务!无法查看操作日志");
		}
		
		AliyunLogPageUtil log = new AliyunLogPageUtil(ActionLogCache.aliyunLogUtil);
		
		//得到当前页面的列表数据
		JSONArray jsonArray = log.list("", "", true, Global.getInt("LIST_EVERYPAGE_NUMBER"), request);
		
		//得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页)
		Page page = log.getPage();
		//设置分页,出现得上几页、下几页跳转按钮的个数
		page.setListNumber(2);
		
//		ActionLogCache.insert(request, "查看总管理后台日志列表", "第"+page.getCurrentPageNumber()+"页");
		
		model.addAttribute("list", jsonArray);
		model.addAttribute("page", page);
		return "/iw/admin/log/list";
	}
 
Example #19
Source File: LogProducerDeadlockTest.java    From aliyun-log-producer-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSend() {
    producer.setProjectConfig(buildProjectConfig());

    TestCallback testCallback = mock(TestCallback.class);
    for (int i = 0; i < 1000; ++i) {
        producer.send(System.getenv("project1"), "store_1s", "topic1", MOCK_IP, getLogItems(),
                testCallback);
    }
    producer.flush();
    producer.close();

    verify(testCallback, times(1000)).
            onCompletion(
                    (PutLogsResponse) isNull(),
                    ArgumentMatchers.any(LogException.class)
            );
}
 
Example #20
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 #21
Source File: LogClientProxy.java    From aliyun-log-flink-connector with Apache License 2.0 5 votes vote down vote up
public void createConsumerGroup(final String project, final String logstore, final String consumerGroupName)
        throws Exception {
    RetryUtil.call((Callable<Void>) () -> {
        ConsumerGroup consumerGroup = new ConsumerGroup(consumerGroupName, 100, false);
        try {
            client.CreateConsumerGroup(project, logstore, consumerGroup);
        } catch (LogException ex) {
            if ("ConsumerGroupAlreadyExist".equals(ex.GetErrorCode())) {
                return null;
            }
            throw ex;
        }
        return null;
    }, "Error while creating consumer group");
}
 
Example #22
Source File: SlsRecordReader.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public int getPartitionsNums() {
	try {
		return getShardsList().size();
	} catch (LogException e) {
		throw new RuntimeException(e);
	}
}
 
Example #23
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 #24
Source File: ActionLogCache.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 插入一条日志
 * @param logItem 传入要保存的logItem,若为空,则会创建一个新的。此项主要为扩展使用,可自行增加其他信息记录入日志
 * @param request HttpServletRequest
 * @param goalid 操作的目标的id,若无,可为0,也可为空
 * @param action 动作的名字,如:用户登录、更改密码
 * @param remark 动作的描述,如用户将名字张三改为李四
 */
public static synchronized void insert(LogItem logItem, HttpServletRequest request, int goalid, String action, String remark){
	if(aliyunLogUtil == null){
		//不使用日志服务,终止即可
		return;
	}
	if(logItem == null){
		logItem = aliyunLogUtil.newLogItem();
	}
	
	/*用户相关信息,只有用户登录后,才会记录用户信息*/
	User user = ShiroFunc.getUser();
	if(user != null){
		logItem.PushBack("userid", user.getId()+"");
		logItem.PushBack("username", user.getUsername());
	}
	
	/* 动作相关 */
	logItem.PushBack("goalid", goalid+"");
	logItem.PushBack("action", action);
	logItem.PushBack("remark", remark);
	
	/*浏览器自动获取的一些信息*/
	if(request != null){
		logItem.PushBack("ip", IpUtil.getIpAddress(request));
		logItem.PushBack("param", request.getQueryString());
		logItem.PushBack("url", request.getRequestURL().toString());
		logItem.PushBack("referer", request.getHeader("referer"));
		logItem.PushBack("userAgent", request.getHeader("User-Agent"));
	}
	try {
		aliyunLogUtil.cacheLog(logItem);
	} catch (LogException e) {
		e.printStackTrace();
	}
}
 
Example #25
Source File: IOThread.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
private PutLogsResponse doSendData(BlockedData bd) throws LogException, InterruptedException {
    try {
        Client clt = clientPool.getClient(bd.data.project);
        if (clt == null) {
            throw new LogException("ProjectConfigNotExist",
                    "the config of project " + bd.data.project + " is not exist", "");
        } else {
            int retry = 0;
            int sleepTimeInSecs = 1;
            while (true) {
                try {
                    return sendRequest(clt, bd);
                } catch (LogException e) {
                    if (e.GetErrorCode().equals("RequestError") || e.GetErrorCode().equals("Unauthorized") || e.GetErrorCode().equals("WriteQuotaExceed") || e.GetErrorCode().equals("InternalServerError") || e.GetErrorCode().equals("ServerBusy")) {
                        if (retry > producerConfig.retryTimes) {
                            throw e;
                        }
                        LOGGER.warn("Failed to send request, errorCode=" + e.GetErrorCode() + ", errorMessage=" + e.GetErrorMessage() + ", requestId=" + e.GetRequestId() + ", retry=" + retry);
                        Thread.sleep(sleepTimeInSecs * 1000);
                        if (sleepTimeInSecs < 512) {
                            sleepTimeInSecs = sleepTimeInSecs * 2;
                        }
                        ++retry;
                    } else {
                        throw e;
                    }
                }
            }
        }
    } finally {
        packageManager.releaseBytes(bd.bytes);
    }
}
 
Example #26
Source File: IOThread.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
private void executeCallback(BlockedData bd, PutLogsResponse response, LogException excp, float srcOutFlow) {
    try {
        bd.data.callback(response, excp, srcOutFlow);
    } catch (Exception e) {
        LOGGER.error("Failed to invoke callback.", e);
    }
}
 
Example #27
Source File: IOThread.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
private PutLogsResponse sendRequest(Client clt, BlockedData bd) throws LogException {
    PutLogsRequest request = buildRequest(bd);
    List<TagContent> tags = new ArrayList<TagContent>();
    tags.add(new TagContent("__pack_id__", bd.data.getPackageId()));
    request.SetTags(tags);
    request.setContentType(producerConfig.logsFormat.equals("protobuf") ?
            Consts.CONST_PROTO_BUF
            : Consts.CONST_SLS_JSON);
    PutLogsResponse response = clt.PutLogs(request);
    long tmpBytes = sendLogBytes.get();
    sendLogBytes.set(tmpBytes + bd.bytes);
    return response;
}
 
Example #28
Source File: SiteSizeChangeLog.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 增加动作日志。此方法不可直接调用,需间接
 * @param userid 当前日志属于哪个登录用户的,对应其user.id
 * @param username 当前日志属于哪个登录用户的,对应其user.username
 * @param agencyName 当前登录的代理的 {@link Agency}.name 若是不是代理,那就是管理员了,管理员可传入空字符串
 * @param remark 备注说明
 * @param agencySiteSizeChange 代理变动的“站”余额的多少,消耗为负数,增加为正数  {@link Agency}.siteSize
 * @param changeBefore 变动前,站点的站余额是多少, {@link Agency}.siteSize
 * @param changeAfter 变化之后的站点的站余额是多少。{@link Agency}.siteSize
 * @param goalid 其余额变动,是开通的哪个站点引起的,记录站点的id,或者是哪个人给他增加的,记录给他增加的人的userid
 * @param ip 操做人的ip地址
 * @param topic 主题,分类。减去站币,消费,传入"xiaofei", 增加站币,充值,传入"chongzhi"
 */
private static void addChangeLog(int userid, String username, String agencyName, String remark, int agencySiteSizeChange, int changeBefore, int changeAfter, int goalid, String ip, String topic){
	if(aliyunLogUtil == null){
		return;
	}
	StackTraceElement st = Thread.currentThread().getStackTrace()[3];
	
	LogItem logItem = aliyunLogUtil.newLogItem();
	/*用户相关信息*/
	logItem.PushBack("userid", userid+"");
	logItem.PushBack("username", username);
	/*日志信息*/
	logItem.PushBack("goalid", goalid+"");
	logItem.PushBack("remark", remark);
	/*代理信息,如果是代理操作的话*/
	logItem.PushBack("agencyName", agencyName);
	logItem.PushBack("changeBefore", changeBefore+"");
	logItem.PushBack("changeAfter", changeAfter+"");
	logItem.PushBack("agencySiteSizeChange", agencySiteSizeChange+"");
	/*使用的类的信息,来源位置*/
	logItem.PushBack("class", st.getClassName());
	logItem.PushBack("method", st.getMethodName());
	
	try {
		aliyunLogUtil.save(topic, ip, logItem);
	} catch (LogException e) {
		MailUtil.sendMail(Global.get("SERVICE_MAIL"), "站币消费出错", e.getMessage()+","+logItem.ToJsonString());
		e.printStackTrace();
	}
}
 
Example #29
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 #30
Source File: PackageData.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
public void callback(PutLogsResponse response, LogException e, float srcOutFlow) {
    long curr = System.currentTimeMillis();
    for (ILogCallback cb : callbacks) {
        cb.completeIOEndTimeInMillis = curr;
        cb.sendBytesPerSecond = srcOutFlow;
        cb.onCompletion(response, e);
    }
}