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

      

  • 相关阅读:
    抓包的原理
    在ASP.NET MVC中使用JQ插件datatable
    如何禁用Visual Studio 2013的Browser Link功能
    SVN中tag branch trunk用法详解
    ASP.NET MVC和jQuery DataTable整合
    随便看的
    SQL查询今天、昨天、7天内、30天
    在DataTable数据类型最后增加一列,列名为“Column”,内容都为“AAA”
    validform表单验证插件最终版
    context.Session[“xxx”]详解
  • 原文地址:https://www.cnblogs.com/flyoung2008/p/2167641.html
Copyright © 2011-2022 走看看