Running a Data Collector Set
To run a data collector set, you can perform one of the following actions:
- Call the IDataCollectorSet::Start method.
- Schedule the data collector set to run.
- Specify that an alert trigger a data collector set to run.
Before you can run a new data collector set, you must first call the IDataCollectorSet::Commit method.
The following example shows how to schedule a data collector set to run. You can specify one or more schedules on which to run the data collector set. This example builds on the example in Creating a Data Collector Set.
HRESULT ScheduleDCS(IDataCollectorSet* pdcs)
{
HRESULT hr = S_OK;
IScheduleCollection* pSchedules = NULL;
ISchedule* pSchedule = NULL;
SYSTEMTIME st;
double date;
VARIANT var;
VariantInit(&var);
V_VT(&var) = VT_DATE;
// Get the collection of schedules from the data collector set.
hr = pdcs->get_Schedules(&pSchedules);
if (FAILED(hr))
{
wprintf(L"get_Schedules failed, 0x%x\n", hr);
goto cleanup;
}
// Get an instance of the Schedule object.
hr = pSchedules->CreateSchedule(&pSchedule);
if (FAILED(hr))
{
wprintf(L"CreateSchedule failed, 0x%x\n", hr);
goto cleanup;
}
// Specify one or more days on which the set runs.
// This example runs only one time.
hr = pSchedule->put_Days(plaRunOnce);
if (FAILED(hr))
{
wprintf(L"put_Days failed, 0x%x\n", hr);
goto cleanup;
}
// Specify the date on which the schedule begins.
ZeroMemory(&st, sizeof(SYSTEMTIME));
st.wDay = 27;
st.wMonth = 5;
st.wYear = 2009;
SystemTimeToVariantTime(&st, &date);
V_DATE(&var) = date;
hr = pSchedule->put_StartDate(var);
if (FAILED(hr))
{
wprintf(L"put_StartDate failed, 0x%x\n", hr);
goto cleanup;
}
// You do not have to specify an end date because the
// job is schedule to run only once.
// Specify the time of day that the set runs.
ZeroMemory(&st, sizeof(SYSTEMTIME));
st.wHour = 10;
st.wMinute = 30;
SystemTimeToVariantTime(&st, &date);
V_DATE(&var) = date;
hr = pSchedule->put_StartTime(var);
if (FAILED(hr))
{
wprintf(L"put_StartTime failed, 0x%x\n", hr);
goto cleanup;
}
VariantClear(&var);
// Add the schedule to the schedule collection.
hr = pSchedules->Add(pSchedule);
if (FAILED(hr))
{
wprintf(L"pSchedules->Add failed, 0x%x\n", hr);
goto cleanup;
}
cleanup:
if (pSchedule)
pSchedule->Release();
if (pSchedules)
pSchedules->Release();
return hr;
}