Here is a sample that demonstrates how to create a performance collection rule using the SDK. The only caviat is that this rule will not work for agentless monitoring. A powershell version will follow soon.

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.EnterpriseManagement;

using Microsoft.EnterpriseManagement.Configuration;

 

namespace RuleCreationSample

{

    class Program

    {

        static void Main(string[] args)

        {

            ManagementGroup mg;

            ManagementPack mp;

            ManagementPackRule rule;

 

            mg = new ManagementGroup("localhost");

            mp = mg.GetManagementPacks("Test")[0];

            rule = new ManagementPackRule(mp, "SamplePerformanceCollectionRule");

 

            CreateDataSourceModule(rule, mg);

            CreateWriteActionModules(rule, mg);

 

            rule.Target = mg.GetMonitoringClasses("Microsoft.Windows.Server.2003.OperatingSystem")[0];

            rule.Category = ManagementPackCategoryType.PerformanceCollection;

            rule.DisplayName = "Sample Performance Counter collection rule";

            rule.Description = "This rule was created by a sample that demonstrates how to create a performance collection rule using the SDK";

 

            mp.AcceptChanges();

        }

 

        //---------------------------------------------------------------------

        private static void CreateWriteActionModules(

            ManagementPackRule rule,

            ManagementGroup mg

            )

        {

            ManagementPackModuleType dbWriteActionModuleType;

            ManagementPackModuleType dwWriteActionModuleType;

            ManagementPackWriteActionModule dbWriteActionModule;

            ManagementPackWriteActionModule dwWriteActionModule;

 

            dbWriteActionModuleType = mg.GetMonitoringModuleTypes("Microsoft.SystemCenter.CollectPerformanceData")[0];

            dwWriteActionModuleType = mg.GetMonitoringModuleTypes("Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData")[0];

 

            dbWriteActionModule = new ManagementPackWriteActionModule(rule, "WriteToDB");

            dwWriteActionModule = new ManagementPackWriteActionModule(rule, "WriteToDW");

 

            dbWriteActionModule.TypeID = (ManagementPackWriteActionModuleType)dbWriteActionModuleType;

            dwWriteActionModule.TypeID = (ManagementPackWriteActionModuleType)dwWriteActionModuleType;

 

            rule.WriteActionCollection.Add(dbWriteActionModule);

            rule.WriteActionCollection.Add(dwWriteActionModule);

        }

 

        //---------------------------------------------------------------------

        private static void CreateDataSourceModule(

            ManagementPackRule rule,

            ManagementGroup mg

            )

        {

            ManagementPackModuleType dsModuleType;

            ManagementPackDataSourceModule dsModule;

 

            dsModuleType = mg.GetMonitoringModuleTypes("System.Performance.DataProvider")[0];

 

            dsModule = new ManagementPackDataSourceModule(rule, "DS");

            dsModule.TypeID = (ManagementPackDataSourceModuleType)dsModuleType;

 

            dsModule.Configuration = CreateConfig("% Processor Time", "_Total", "Processor", 10);

 

            rule.DataSourceCollection.Add(dsModule);

        }

 

        //---------------------------------------------------------------------

        static string CreateConfig(

            string counterName,

            string instanceName,

            string objectName,

            int frequencyInSeconds

            )

        {

            StringBuilder builder = new StringBuilder();

 

            builder.Append("<ComputerName></ComputerName>");

            builder.AppendFormat("<CounterName>{0}</CounterName>", counterName);

            builder.AppendFormat("<ObjectName>{0}</ObjectName>", objectName);

            builder.AppendFormat("<InstanceName>{0}</InstanceName>", instanceName);

            builder.Append("<AllInstances>false</AllInstances>");

            builder.AppendFormat("<Frequency>{0}</Frequency>", frequencyInSeconds);

 

            return (builder.ToString());

        }

    }

}