public IDictionary <String, Object> DetectSupportedVM() { var detector = SupportedVMDetector.CreateInstance(new SupportedVMDetectorConfiguration() { GuestDataItemKey = "Enhanced_Monitoring_Supported", }); var watcher = System.Diagnostics.Stopwatch.StartNew(); var vms = detector.GetSupportedVM(); Console.WriteLine(String.Format("Elapsed: {0}ms\t Detect supported VM", watcher.ElapsedMilliseconds)); Assert.IsNotNull(vms); Assert.AreNotEqual(0, vms.Count); var vm = vms.FirstOrDefault(); Assert.IsNotNull(vm); Assert.IsNotNull(vm["VirtualMachineName"]); Assert.IsNotNull(vm["VirtualMachineElementName"]); Assert.IsNotNull(vm["VirtualMachinePath"]); Console.WriteLine("Found: " + vm["VirtualMachineElementName"]); return(vm); }
public void TestMetricJSON() { MonitorConfiguration conf = MonitorConfiguration.Load(@"..\..\..\EnhancedMonitoring\Configuration\EnhancedMonitoringProviderConfig.xml"); List <MgmtObject> mgmtObjects = new List <MgmtObject>(); foreach (var mgmtObjConf in conf.MgmtObjects) { mgmtObjects.Add(MgmtObject.CreateInstance(mgmtObjConf)); } Assert.AreNotEqual(0, mgmtObjects.Count); var data = new Dictionary <String, Object>(); var vms = SupportedVMDetector.CreateInstance(conf.SupportedVMDetector).GetSupportedVM(); Assert.AreNotEqual(0, vms.Count); var vm = vms.FirstOrDefault(); var args = new Dictionary <String, Object>(vm); foreach (var mgmtObj in mgmtObjects) { var watch = System.Diagnostics.Stopwatch.StartNew(); try { data.Add(mgmtObj.KeyName, mgmtObj.CollectData(args)); } catch (Exception e) { if (!mgmtObj.SuppressError) { Console.WriteLine(e); Console.WriteLine(e.StackTrace); Assert.Fail(e.Message); } data.Add(mgmtObj.KeyName, null); } Console.WriteLine(String.Format("{0}\t{1}", watch.ElapsedMilliseconds, mgmtObj.KeyName)); } Assert.IsNotNull(data); Assert.AreNotEqual(0, data.Count); var xmlStr = DataFormatHelper.ToXml(data); Console.WriteLine(xmlStr); //var jsonStr = DataFormatHelper.ToJSON(data); //var encodedStr = DataFormatHelper.Base64Encode(jsonStr); //var dataChunks = DataFormatHelper.PackString(jsonStr, 900); //var packedData = DataFormatHelper.ToChunk("", dataChunks); //var encodedDataChunks = DataFormatHelper.PackString(encodedStr, 900); //var encodedPackedData = DataFormatHelper.ToChunk("", encodedDataChunks); //Console.WriteLine(JsonHelper.FormatJson(jsonStr)); //Console.WriteLine(String.Format("Original JSON string length: {0}", jsonStr.Length)); //Console.WriteLine(String.Format("Encoded JSON string length: {0}", encodedStr.Length)); //Console.WriteLine(String.Format("Packed JSON string length: {0}", packedData.Select(d => d.Value.ToString().Length).Sum())); //Console.WriteLine(String.Format("Packed encoded JSON string length: {0}", encodedPackedData.Select(d => d.Value.ToString().Length).Sum())); }