zoukankan      html  css  js  c++  java
  • 网站监控系统

      最近开始做一个网站监控系统,涉及的功能包括:站点监控、服务器性能监控、服务监控等。站点监控的类型包括: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

      

  • 相关阅读:
    myelipse与idea的javaweb项目创建
    入站规则和出站规则设置
    NAT技术基本原理与应用
    如何将sqlserver数据中的数据导出到服务器
    如何将SqlServer中表结构以及表数据全部导出
    国外服务器--新加坡服务器
    windows server2008 创建新用户 远程桌面连接 和 多用户登录问题
    程序员应该关注的国外IT网站
    IDEA创建普通java和web项目教程
    IIS Express 通过IP访问的方法和坑
  • 原文地址:https://www.cnblogs.com/flyoung2008/p/2167641.html
Copyright © 2011-2022 走看看