Пример #1
0
void test_processes_monitor(void)
{
    double cf_this[100] = { 0.0 };
    MonProcessesGatherData(cf_this);
    MonProcessesGatherData(cf_this);
    MonProcessesGatherData(cf_this);

    int usr, rusr, ousr;
    usr = rusr = ousr = 0;

    bool res = GetSysUsers(&usr, &rusr, &ousr);
    if (!res)
    {
        Log(LOG_LEVEL_NOTICE, "TEST SKIPPED!");
        return;
    }

    usr  = 3*usr;
    rusr = 3*rusr;
    ousr = 3*ousr;

    Log(LOG_LEVEL_NOTICE, "Counted %d/3 different users on the process table,"
        " while CFEngine counted %f/3", usr, cf_this[ob_users]);
    Log(LOG_LEVEL_NOTICE, "This is a non-deterministic test,"
        " the two numbers should be *about* the same since the 'ps'"
        " commands run very close to each other");

    int upper = (int) ((double) usr*1.10);
    int lower = (int) ((double) usr*0.90);
    assert_in_range((long long) cf_this[ob_users], lower, upper);
}
Пример #2
0
void test_processes_monitor(void)
{
# ifdef __sun
  return; //redmine 6316
# endif
    double cf_this[100] = { 0.0 };
    MonProcessesGatherData(cf_this);
    MonProcessesGatherData(cf_this);
    MonProcessesGatherData(cf_this);
    int usr, rusr, ousr;

    usr = rusr = ousr = 0;
    bool res = GetSysUsers(&usr, &rusr, &ousr);
    if (res == false )
    {
        assert_true(1);
        return;
    }

    usr  = 3*usr;
    rusr = 3*rusr;
    ousr = 3*ousr;
    int upper = (int)((double)usr*1.10);
    int lower = (int)((double)usr*0.90);
    assert_in_range((long long)cf_this[ob_users], lower, upper);
}
Пример #3
0
static void GetQ(const Policy *policy, const ReportContext *report_context)
{
    CfDebug("========================= GET Q ==============================\n");

    MonEntropyClassesReset();

    ZeroArrivals();

    MonProcessesGatherData(CF_THIS);
#ifndef __MINGW32__
    MonCPUGatherData(CF_THIS);
    MonLoadGatherData(CF_THIS);
    MonDiskGatherData(CF_THIS);
    MonNetworkGatherData(CF_THIS);
    MonNetworkSnifferGatherData(CF_THIS);
    MonTempGatherData(CF_THIS);
#endif /* !__MINGW32__ */
    MonOtherGatherData(CF_THIS);
    GatherPromisedMeasures(policy, report_context);
}
Пример #4
0
static void GetQ(void)
{
    CfDebug("========================= GET Q ==============================\n");

    MonEntropyClassesReset();

    ZeroArrivals();

    MonProcessesGatherData(CF_THIS);
#ifndef MINGW
    MonCPUGatherData(CF_THIS);
    MonLoadGatherData(CF_THIS);
    MonDiskGatherData(CF_THIS);
    MonNetworkGatherData(CF_THIS);
    MonNetworkSnifferGatherData(CF_THIS);
    MonTempGatherData(CF_THIS);
#endif /* NOT MINGW */
    MonOtherGatherData(CF_THIS);
    GatherPromisedMeasures();
}
Пример #5
0
void MonitorStartServer(EvalContext *ctx, const Policy *policy)
{
    char timekey[CF_SMALLBUF];
    Averages averages;

    Policy *monitor_cfengine_policy = PolicyNew();
    Promise *pp = NULL;
    {
        Bundle *bp = PolicyAppendBundle(monitor_cfengine_policy, NamespaceDefault(), "monitor_cfengine_bundle", "agent", NULL, NULL);
        PromiseType *tp = BundleAppendPromiseType(bp, "monitor_cfengine");

        pp = PromiseTypeAppendPromise(tp, "the monitor daemon", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, NULL);
    }
    assert(pp);

    CfLock thislock;

#ifdef __MINGW32__

    if (!NO_FORK)
    {
        Log(LOG_LEVEL_VERBOSE, "Windows does not support starting processes in the background - starting in foreground");
    }

#else /* !__MINGW32__ */

    if ((!NO_FORK) && (fork() != 0))
    {
        Log(LOG_LEVEL_INFO, "cf-monitord: starting");
        _exit(0);
    }

    if (!NO_FORK)
    {
        ActAsDaemon(0);
    }

#endif /* !__MINGW32__ */

    TransactionContext tc = {
        .ifelapsed = 0,
        .expireafter = 0,
    };

    thislock = AcquireLock(ctx, pp->promiser, VUQNAME, CFSTARTTIME, tc, pp, false);

    if (thislock.lock == NULL)
    {
        PolicyDestroy(monitor_cfengine_policy);
        return;
    }

    WritePID("cf-monitord.pid");

    MonNetworkSnifferOpen();

    while (!IsPendingTermination())
    {
        GetQ(ctx, policy);
        snprintf(timekey, sizeof(timekey), "%s", GenTimeKey(time(NULL)));
        averages = EvalAvQ(ctx, timekey);
        LeapDetection();
        ArmClasses(averages, timekey);

        ZeroArrivals();

        MonNetworkSnifferSniff(ITER, CF_THIS);

        ITER++;
    }

    PolicyDestroy(monitor_cfengine_policy);
}

/*********************************************************************/

static void GetQ(EvalContext *ctx, const Policy *policy)
{
    MonEntropyClassesReset();

    ZeroArrivals();

    MonProcessesGatherData(CF_THIS);
#ifndef __MINGW32__
    MonCPUGatherData(CF_THIS);
    MonLoadGatherData(CF_THIS);
    MonDiskGatherData(CF_THIS);
    MonNetworkGatherData(CF_THIS);
    MonNetworkSnifferGatherData();
    MonTempGatherData(CF_THIS);
#endif /* !__MINGW32__ */
    MonOtherGatherData(CF_THIS);
    GatherPromisedMeasures(ctx, policy);
}