发布新日志

  • LR-下载并保存文件到本地

    2009-01-09 10:03:29

    #include "web_api.h"
    Action()
    {
        int iflen; //文件大小
     long lfbody;  //响应数据内容大小   
     web_set_max_html_param_len("10000");

        //将响应信息存放到fcontent变量
        web_reg_save_param("fcontent","LB=","RB=","SEARCH=BODY",LAST);

     web_url("下载rar",
     "URL=http://www.baidu.com/img/baidu_logo.gif",
     "Resource=0",
     "RecContentType=application/xml",
     "Referer=http://www.baidu.com",
     "Snapshot=t9.inf",
     "Mode=HTML",
     LAST);

        //获取响应大小
        iflen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
     if(iflen > 0)
     {
      //以写方式打开文件
      if((lfbody = fopen("e:\\abc.gif", "wb")) == NULL)
      {
       lr_output_message("文件操作失败!");
       return -1;
      }
      //写入文件内容
      fwrite(lr_eval_string("{fcontent}"), iflen, 1, lfbody);
      //关闭文件
      fclose(lfbody);
     }
     return 0;
    }

  • LR通过snmp监控linux下的mysql

    2009-01-08 09:41:08

    在linux底下安装配置snmp:

    1、使用系统盘安装rpm包(这种方式最好)

    2、在www.net-snmp.org处下载net-snmp安装(安装后有可能找不到snmpd.conf文件)

    tar xzvf net-snmp-5.4.2.1.tar.gz
    cd net-snmp-5.4.2.1
    ./configure
    这里会叫你输入一些信息,其中有一步(好像是第二步)是问要安装什么版本:1、2、3,输入2回车
    其它都直接回车就可以
    make
    make install

    安装后,会生成可执行程序:/usr/local/sbin/snmpd

    使用net-snmp*.tar.gz安装时,如果找不到snmpd.conf文件,可以在其解压目录下COPY一份EXAMPLE.conf/usr/local/etc/snmp下,并改名为snmpd.conf
    修改配置文件中内容:

        #       sec.name  source          community

        com2sec local     192.168.146.50       public   //ip为监控服务器IP

        com2sec mynetwork 192.168.146.0/24      public //允许监控的网络

     

        #                context sec.model sec.level match  read   write  notif

        access MyROGroup ""      any       noauth    exact  all    all    none

        access MyRWGroup ""      any       noauth    exact  all    all    none

        //read write都为all

    LunnerRunner中添加监控:

    1、控制场景-RUN-添加SNMP到监控窗口

    2、在SNMP到监控窗口点击右键添加度量,添加服务器和 mysql PID

    添加PID的路径:mgmt--mib-2--host—hrswrunperf--runperftable-- hrswrunperfEnter -- hrswrunperfcpu(如果是要监控内存那么应该是***Mem)查找需要的PID

    (注:hrswrunperfcpu下的一大串数字,代表的就是各个进程的PID,在linux服务器上可通过ps查看mysql的PID)

  • LR监控Mysql使用的DLL库

    2009-01-06 17:55:08

    注意事项:

    Tools->Options->Directories增加mysql安装目录下的include/lib;

    libmySQL.dll也要COPY到DEBUG目录下,LR使用时,同MonitorTest.dll一起复制到脚本目录下;

     

    VC++代码:

    MonitorTest.cpp

    #include "stdafx.h"
    #include "MonitorTest.h"
    #include "stdlib.h"
    #include "winsock.h"
    #include "mysql.h"

    #include "stdio.h"

    //stdio.h头文件必须要放在stdafx.h头文件后

    MYSQL conn;
    MYSQL_RES *p_res_ptr=NULL;
    MYSQL_ROW sqlrows;


    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
          )
    {
        switch (ul_reason_for_call)
        {
            case DLL_PROCESS_ATTACH:
            case DLL_THREAD_ATTACH:
            case DLL_THREAD_DETACH:
            case DLL_PROCESS_DETACH:
            break;
        }
        return TRUE;
    }

    int init_mysql_connection(char *str_server,char *str_username,char *str_pwd,char *str_db)
    {

        mysql_init(&conn);
        printf("\nSuccess to initate MySQL connection\n");
        if (!mysql_real_connect(&conn,str_server,str_username,str_pwd,str_db,0,NULL,0))
        {
            printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&conn));
            return 1;
        }
        else
        {
            printf("\nLogged on to %s sucessfully\n",str_server);
            return 0;
        }

    }
    int close_mysql_connection()
    {
        mysql_free_result(p_res_ptr);
        printf("\nClose connection");
        mysql_close(&conn);   
        return 0;
    }

    int get_mysql_query_data(char *str_query,char *str_data)
    {
        mysql_real_query(&conn, str_query, (UINT)strlen(str_query));
        MYSQL_RES * res ;
        MYSQL_ROW row;
        res = mysql_use_result( &conn ) ;
        row = mysql_fetch_row( res );
        strcpy(str_data,row[1]);
        mysql_free_result(res);
        return 0;


    }//此函数的参数str_query,查询后的结果必须唯一,主要用来查看show status的变量值

     

    //////////////////////////////////////////////////////////////////////////////////

    MonitorTest.def

    LIBRARY      "MonitorTest"
    DEscrīptION  'MonitorTest Windows Dynamic Link Library'

    EXPORTS
        init_mysql_connection @1
        close_mysql_connection  @2
        get_mysql_query_data @3

     

     

    LR中的脚本:

    #include "web_api.h"

    double atof (const char * string ); //使用atof前需先声明

    Action()
    {
     lr_load_dll("MonitorTest.dll"); 

     int i=0; 
     double f;
     char *str_data;
     str_data=(char *)malloc(20*sizeof(char));
     i= init_mysql_connection("192.168.146.50","root","111111","mysql");
     //lr_output_message("%d",i);
     for(;;)
     {

      i = get_mysql_query_data("show status like 'Uptime';",str_data);
      //lr_output_message("%d",i);
      lr_output_message("%s",lr_eval_string(str_data));
      f = atof(str_data);
      lr_output_message("%.2f",f);
      lr_user_data_point("Uptime",f);
      lr_think_time(5);
     }

     close_mysql_connection();
     return 0;
    }

     

  • LR-webservice测试问题

    2009-01-05 16:19:37

    Action.c(157): 错误: C interpreter run time error: Action.c (157):  Error -- memory violation : Exception ACCESS_VIOLATION received.

     

    解决方法:

    选择run-time 设置中选择“web services”- "客户端**"—“模拟特定的数据包“mssoap”

242/2<12
Open Toolbar