Using Task Scheduler to automate the collection of CDF traces

Using Task Scheduler to automate the collection of CDF traces

book

Article ID: CTX221609

calendar_today

Updated On:

Description

It gets difficult at times when we need to capture CDF traces for a specific period of time. We have different tools like CDF Control, Scout and CDF Monitor, however it requires manual intervention to start and stop the traces and yet there are chances that the traces might get over-written if you use CDF Monitor or blow up your storage space by using CDF Control/Scout to collect multiple sequential logs. And it also becomes difficult if we need to capture traces at wee hours.

To avoid situations like this, we can use Task Scheduler to start and stop CDF monitor using batch files. In my use case, I am configuring task scheduler to capture CDF traces for a reboot schedule starting at 2:00 AM this Sunday which will run for a couple of hours and then stop with the help of CDF Monitor.


Instructions

 
1. Download CDFMonitor tool from  http://support.citrix.com/article/ctx129537
 
2. First, uninstall the CDF Monitor service from the Delivery Controllers (if it was installed previously). To do this, open command prompt and browse to the location which contains the CDFmonitor.exe file. Run the following command:
            CDFmonitor.exe /uninstallservice
 
3. To validate that the service is uninstalled completely, open services.msc console and check for CDF Monitor service. If you do not find any, then the service is uninstalled completely. Also delete the following folder (if present) - C:\Windows\CDFMonitor from all the Delivery Controllers.  
 
4. Now configure the config file of CDF Monitor as per the below settings:
 
a. Change the value to ‘15’ for ‘logfilemaxcount’
 
User-added image

 b. Change the value to ‘100’ for ‘logfilemaxsize’  
 
User-added image

c. Change the value to <add key="logtoetl" value="True" />  

d. Change the value to <add key="tracefile" value="cdftrace.etl" />
 
5. Once we have the config file saved, you will need to create two .bat files for starting and stopping the CDF Monitor service. In my sample script, I have placed the CDFMonitor.exe and CDFMonitor.exe.config files in the C: directory. I have attached the batch files in this article for your reference.
 
a. To start the service:
                         cd C:\
                         cdfmonitor.exe /installservice
 
b. To stop the service:
                         cd C:\
                         cdfmonitor.exe /stopservice
 
 
6. Now, we will use “Task Scheduler” to create a task for starting and stopping the service at a specific time. As an example, we set the start time to 1:45 AM and stop time to 6:00 AM. So below are the steps to configure “Task Scheduler”.
 
a. On one of the Delivery Controllers, open Task Scheduler.
 
b. Create a new folder and name it as CDF Monitor:
 
 
User-added image
 
 
c. Right-click on the folder that you created and select the option “Create Task”.
 
User-added image
 
d. Name it as CDFstart and configure the Security Options accordingly. Make sure you check the option “Run with highest privileges” and “Run whether user is logged on or not”
 
User-added image
 
         
e. Browse to the “Triggers” tab and click on “New”. A window will pop-up to configure the trigger. You can configure the options depending on the use case.
 
User-added image
 
 
Make sure that you have the “Expire” date and time set as well.
 
 
f. Now browse to the “Actions” tab and create a new Action. A new window will pop up where you will need to select the Action type. Set it to “Start a program” and in the Settings, browse to the CDFstart.bat file and click on Open.
 
 
User-added image
 
g. In the conditions tab, select the values mentioned in the below screenshot.
 
User-added image
 
 
h. Also configure the Settings tab as in the below screenshot:
 
User-added image
 
i. Once all the properties are configured, click on OK to save it.
 
j. Repeat the steps from “c” through “i” to create and configure the task to stop CDF Monitor. Here, the only changes will be in the name of the task, Trigger start and stop time, batch file in the Actions tab. Below are the screenshots for each of these sections:
 
User-added image
 
 
User-added image
 
 
 
User-added image
 
 
k. The values in “Conditions” and “Settings” will be the same as CDFstart task.
 
7. Once you have both the tasks, configured, the summary will look something like the below screenshot:
 
User-added image
 
 
8. For testing, you can probably set the values for the triggers accordingly and check if the .etl files are getting created in the C:\Windows\CDFMonitor folder. Alternatively, after the Start trigger, you can find CDF Monitor service in a “Running” state and after the second trigger, the CDF Monitor service will be in a stopped state in the Services console. Once you validate that the task scheduler is configured properly, uninstall the CDF Monitor service by following Step 1. We need to have it uninstalled because the command that we are using in the script is to install the service. This will not start the service if CDF Monitor is already installed.
 
9. Once the tasks are created on a DDC, you will find an option to export each task. Export both the tasks, create a new Folder in the Task Scheduler of all the other DDC/VDA where you want to configure CDF tracing and import it to that folder.
 
User-added image
 
 
To import:
 
User-added image
 
 
10. Once they are configured correctly with the above settings, CDF Monitor will start collecting the traces at 1:45 AM and will stop the collection on 5:00 AM 03/12/2017.

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.