• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
My Blog@github像少年啦飞驰
{关注大规模数据处理(MapReduce)J2EE等技术}
博客园    首页    新随笔    联系   管理    订阅  订阅
网站监控系统

  最近开始做一个网站监控系统,涉及的功能包括:站点监控、服务器性能监控、服务监控等。站点监控的类型包括:HTTP/HTTPS、PING、FTP、DNS、TCP、UDP、SMTP。可用率和响应时间是两个重要的性能指标。

  其实有些实现还是比较简单的,只要模拟连接服务器就可以了。

  先贴一下FTP、SMTP的实现代码(只是简单实现,还有深入的东西要去考虑)

FTP

import sun.net.ftp.*;
public class FtpTool{
/*
 * 可用率
 * 响应时间 
 *
 * 
 * */
	public static boolean connectServer(String host,int port,String username,String password)
	                                                                      throws Exception{
		boolean isSuccess = false;
		try {
			FtpClient ftpclient = new FtpClient();
			ftpclient.openServer(host, port);
			ftpclient.login(username, password);
		    isSuccess = true;	
		} catch (Exception e) {
			throw new Exception("Connect ftp server error:"+e.getMessage());
		}
		
		return isSuccess;
	}
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		long end=0;
		long response=0;
		try {
			boolean isSuccess=FtpTool.connectServer("www.linuxidc.com", 21, "www.linuxidc.com", "www.muu.cc");
			//boolean isSuccess=FtpTool.connectServer("218.4.56.235", 21, "anonymous", "");
			end = System.currentTimeMillis();
			response = end-start;
			System.out.println("Connection successful");
		    System.out.println("响应时间:"+response+"ms");	
		} catch (Exception e) {
			end = System.currentTimeMillis();
			response = end-start;
			System.out.println(e.getMessage());
			System.out.println("响应时间:"+response+"ms");
		}

	}

}

SMTP

import sun.net.smtp.*;
public class SmtpTool {

	public static boolean connectServer(String mailhost,int port)throws Exception{
		boolean isSuccess=false;
		SmtpClient smtpclient;
		try {
			smtpclient = new SmtpClient(mailhost);
			smtpclient.openServer(mailhost, port);
		} catch (Exception e) {
			throw new Exception("Connect server error:"+e.getMessage());
		}
		
		isSuccess=true;
		return isSuccess;
	}
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		long end=0;
		long response=0;
		try {
			SmtpTool.connectServer("smtp.sina.com.cn",25);
			end=System.currentTimeMillis();
			response=end-start;
			System.out.println("Connection successfull");
			System.out.println("响应时间:"+response+"ms");
		} catch (Exception e) {
			end=System.currentTimeMillis();
			response=end-start;
			System.out.println("Connect server error:"+e.getMessage());
			System.out.println("响应时间:"+response+"ms");
		}

	}

}

未完待续 简单记录

参考论文:http://wenku.baidu.com/view/c79b5a2c453610661ed9f4b9.html

  

作者:像少年啦飞驰
出处:http://www.cnblogs.com/flyoung2008/
Blog:http://www.flyoung.me
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
分享到: 更多
posted on 2011-09-05 15:58  像少年啦飞驰  阅读(709)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3