Presentation is loading. Please wait.

Presentation is loading. Please wait.

Improve Manageability Improve Manageability Microsoft.NET.

Similar presentations

Presentation on theme: "Improve Manageability Improve Manageability Microsoft.NET."— Presentation transcript:

1 Improve Manageability Improve Manageability Microsoft.NET

2 .NET 2004/03/24 2.NET Microsoft MCSD/MCSE/MCDBA Rational OOAD Lotus Notes principle CLP/CLI J2EE

3 .NET 2004/03/24 3.NET.NET

4 .NET 2004/03/24 4 Introduction Configuration Management Exception Management Enterprise Instrumentation Framework Logging Application block

5 .NET 2004/03/24 5 Application Architecture UI Components UI Process Components Data Access Components Business Workflows Business Components Users Business Entities Service Agents Service Interfaces Data Sources Services Operational Management Security Communication

6 .NET 2004/03/24 6 Benefits of Improving Manageability Development phase Pinpoint bugs, performance issues Deployment phase Configurable, Flexible Operation phase Know what is going on in applications and able to manage them. Provide sufficient information to track down what is going wrong.

7 .NET 2004/03/24 7 Application Management Challenges For the Support Organization Application faults or issues are often detected first by users Support staff need structured application information Most tracing solutions are not intended for production deployment scenarios Distributed applications magnify these challenges Events fired from an application across multiple servers are hard to correlate

8 .NET 2004/03/24 8 Application Management Challenges For the Development Organization No unified instrumentation API Developers are forced to use different eventing, tracing, or logging solutions Or, more often, avoid instrumentation entirely Firing an event must be as simple and low- profile as possible Developers are often forced to determine event routing within code

9 Configuration Management Application Block - CMAB

10 .NET 2004/03/24 10 App/Web.config Problems Simple data Configuration.AppSettings[ConnString] Not secure Read only File storage only, not Flexible...

11 .NET 2004/03/24 11 Purpose of Configuration Management Application Block (CMAB) Purpose: Standardize interface to Read/Write application configuration data Supports complex data structures Pluggable Storage provider Pluggable Signing & Encryption provider Cache configuration data

12 .NET 2004/03/24 12 Conceptual Design Your Application Your Application Application XML Configuration - XML File - SQL Server - Registry - Custom Configuration Manager Configuration Storage Provider Data Protection Provider Data Protection Provider - DPAPI - BCL - Custom Caching Service Configuration Section Handlers Data Protection Provider Data Protection Provider Data Protection Provider Data Protection Provider Storage Service Provider Pluggable Handler, Storage/protection provider

13 .NET 2004/03/24 13 CMAB Usage //Read Default section, i.e. first section, HashTable data format configData = ConfigurationManager.Read(sectionName); foreach( string key in configData.Keys ) list.Items.Add( new ListPair( key, configData[ key ] ) ); // Write ConfigurationManager.Write( sectionName, configData ); … freaky chakra …

14 .NET 2004/03/24 14 Handler and Provider In the app.config / web.config Define Configuration Section Handler Define Configuration Storage Provider Define Data Protection Provider Define Cache parameters

15 .NET 2004/03/24 15 CMAB configuration freaky chakra

16 .NET 2004/03/24 16 Configuration Setting Schema

17 .NET 2004/03/24 17.NET Support for Configuration Management …

18 .NET 2004/03/24 18 Implementation of ConfigurationManager //Configuration manager Read() & Write() public static object Read( string sectionName ) { cacheSettings = CacheFactory.Create( sectionName ); configReader = StorageReaderFactory.Create( sectionName ); configSectionNode = configReader.Read(); sectionHandler = ConfigSectionHandlerFactory.Create( sectionName ); config = sectionHandler.Create( null, null, configSectionNode ); cacheSettings[ cacheSettings.SectionName ] = config; } public static void Write(string sectionName, object configValue) { storageReader = StorageReaderFactory.Create( sectionName ); storageWriter = (IConfigurationStorageWriter)storageReader; sectionHandler = ConfigSectionHandlerFactory.Create( sectionName ); sectionHandlerWriter = (IConfigurationSectionHandlerWriter)sectionHandler; xmlNode = sectionHandler.Serialize( configValue ); storageWriter.Write( xmlNode ); }

19 .NET 2004/03/24 19 Implementation of ConfigurationSectionHandler public object Create(object parent,object configContext,XmlNode section) { foreach(XmlNode configChildNode in section.ChildNodes) { if (configChildNode.Name == "configSection" ) ProcessConfigSection( configChildNode, out sectionSettings, configSettings ); } void ProcessConfigSection( XmlNode configChildNode,...) { foreach(XmlNode sectionChildNode in configChildNode.ChildNodes) { switch ( sectionChildNode.Name ) { case "configCache" : ProcessConfigCacheSection( sectionChildNode, … ); break; case "configProvider" : ProcessConfigProviderSection( sectionChildNode, … ); break; case "protectionProvider" : ProcessProtectionProvider( sectionChildNode, … ); break; }

20 .NET 2004/03/24 20 Implementation of XmlHashtableSectionHandler object Create(object parent, object configContext, XmlNode section) { if( section.ChildNodes.Count == 0 ) return new Hashtable(); XmlSerializableHashtable xmlHt = (XmlSerializableHashtable)_xmlSerializer.Deserialize( new XmlNodeReader( section ) ); return xmlHt.InnerHashtable; } XmlNode Serialize(object value) { StringWriter sw = new StringWriter( ); _xmlSerializer.Serialize( sw, new XmlSerializableHashtable( (Hashtable)value ) ); XmlDocument doc = new XmlDocument(); doc.LoadXml( sw.ToString() ); return doc.DocumentElement; }

21 .NET 2004/03/24 21 Implementation of XmlFileStorage public XmlNode Read() { XmlDocument xmlDoc = new XmlDocument(); LoadXmlFile(...); XmlNode sectionNode = + SectionName); if( _isSigned || _isEncrypted ) { XmlNode encryptedNode = sectionNode.SelectSingleNode( "encryptedData" ); XmlNode signatureNode = sectionNode.SelectSingleNode( "signature" ); byte[] hash =_dataProtection.ComputeHash( Encoding.UTF8.GetBytes( sectionData ) ); //Compare the hashes encryptedBytes = Convert.FromBase64String( sectionData ); decryptedBytes = _dataProtection.Decrypt( encryptedBytes ); sectionData = Encoding.UTF8.GetString( decryptedBytes );... } return section data; }

22 .NET 2004/03/24 22 CMAB Summary Standard Read/Write interface to access application configuration data Supports complex data structures Pluggable Storage provider for flexibility Pluggable Signing & Encryption provider for security Cache configuration data for efficiency

23 Exception Management Application Block - EMAB

24 .NET 2004/03/24 24 Exception Management Application Block (EMAB) Purpose: Make it simple and powerful to report that an exception has occurred (1 line of code) Make it extensible and flexible to log errors however you want Problems solved: Often exception code is unique and repeated in every application Changing how your exceptions are logged meant changing your code Difficult to pass context information up the stack

25 .NET 2004/03/24 25 Solution Concept YourApplication Publisher (event log) Exception Manager Exception Publisher(database) Publisher (text file) Publisher( )

26 .NET 2004/03/24 26 EMAB Usage Publishing an exception: Pluggable Publishers of exception info Event Log as default. try {…} catch (Exception ex) { ExceptionManager.Publish(ex); }

27 .NET 2004/03/24 27 EMAB Configuration-1 * Means all exceptions, + means the exception and its descendants

28 .NET 2004/03/24 28 EMAB Configuration-2

29 .NET 2004/03/24 29 Logical Design

30 .NET 2004/03/24 30 BaseApplicationException The exception block provides a base application exception class from which all your exceptions inherit. Has contextual information like MachineName, Thread, Login, DateTime, AppDomain Has additional information collection for inserting custom pieces of data class HeartAttackException : BaseApplicationException {... }

31 .NET 2004/03/24 31 Encounter An Exception Throw an customized exception Your custom exceptions now have additional information passed up the stack. publish your exception if you are at the top of the stack HeartAttackException ex; ex = new HeartAttackException(); ex.AdditionalInformation.Add("BloodPressure", "120/300"); ex.AdditionalInformation.Add("Pulse", 85); ex.AdditionalInformation.Add("WhiteCount", 1000); throw ex;

32 .NET 2004/03/24 32 Publish an Exception private void btnLogon_Click(…) { try { if ( DoLogon(txtUserName.Text, txtPassword.Text) == true ) MessageBox.Show("Your Logon Was Successful"); else MessageBox.Show("Logon failed); } catch( LogonException lex){ // publish Exception using ExceptionManager ExceptionManager.Publish( lex ); MessageBox.Show(lex.Message); } private bool DoLogon(string userName, string password) { try{ using (FileStream fs = new FileStream( "Accounts.dat",…)) { return CheckUserDetails(fs, userName, password); } catch (FileNotFoundException ex ) { throw new LogonException( "Internal Failure. User file not found", ex ); }

33 .NET 2004/03/24 33 Tips for exception blocks Throw an customized exception Remember to publish your exception if you are at the top of the stack Do not re-throw it. If you choose to ignore the above tip, at least add exception handling into the Thread_UnhandledException event (winforms) Application_Error event (webforms) To display an exception to the user, you still need a MessageBox call. ExceptionManager.Publish just records it.

34 .NET 2004/03/24 34 Implementation of BaseApplicationException [Serializable] public class BaseApplicationException : ApplicationException { public BaseApplicationException() : base() { InitializeEnvironmentInformation(); } public BaseApplicationException(string message) : base(message) { InitializeEnvironmentInformation(); } public BaseApplicationException(string message,Exception inner) : base(message, inner) { InitializeEnvironmentInformation(); } private void InitializeEnvironmentInformation() { machineName = Environment.MachineName; threadIdentity = Thread.CurrentPrincipal.Identity.Name; windowsIdentity = WindowsIdentity.GetCurrent().Name;... }

35 .NET 2004/03/24 35 Implementation of ExceptionManager void Publish(Exception exception, NameValueCollection additionalInfo) { ConfigurationSettings.GetConfig(...); PublishToDefaultPublisher(exception, additionalInfo); // or foreach(PublisherSettings Publisher in config.Publishers) PublishToCustomPublisher(exception, additionalInfo, Publisher); } void PublishToCustomPublisher(...) { if (publisher.ExceptionFormat == PublisherFormat.Xml) { IExceptionXmlPublisher XMLPublisher = (IExceptionXmlPublisher)Activate(publisher.AssemblyName, publisher.TypeName); XMLPublisher.Publish(SerializeToXml(exception, additionalInfo),publisher.OtherAttributes); } else { IExceptionPublisher Publisher = (IExceptionPublisher)Activate(publisher.AssemblyName, publisher.TypeName); Publisher.Publish(exception, additionalInfo, publisher.OtherAttributes); }

36 .NET 2004/03/24 36 Implementation of DefaultPublisher Get publisher s source Get custom exception info Get BaseApplicationException info Get stack trace Write to target source

37 .NET 2004/03/24 37 Summary Register custom event sources by running installutil on your DLL Understand exception management best practices Build a dump to text file publisher for development

38 Enterprise Instrumentation Framework EIF

39 .NET 2004/03/24 39 EIF Goals Monitor and Troubleshoot applications built on the.NET Framework Integrate and unify disparate tracing, eventing, and logging technologies Support Distributed Environment Integrate with existing management tools and products

40 .NET 2004/03/24 40 EIF Core Features Unified Instrumentation API Unified model for tracing, eventing, and logging Leverages WMI Infrastructure (System.Management.Instrumentation) Structured WMI Event Schema Manageability contract between developers, quality assurance, and support staff Configurable At-Source Event Filtering Fire via WMI, Event Log, Windows Event Trace Minimal cost for leaving instrumentation in production build High-speed Diagnostic Tracing Enables problem management for production applications Enables tracing user requests along application business processes or services

41 .NET 2004/03/24 41.NET Application Instrumentation API Event Filtering Event Filtering WMI Event Trace Event Log Trace Log Event Log WMI Subscriber Configuration Event Schema Application Object Event Source Trace Reader Single Application Server Event Sink

42 .NET 2004/03/24 42 Distributed Servers Distributed.NET Application Application Server Event Source Event Routing WMI Event Trace Event Log Trace Log Event Log WMI Subscriber Trace Reader Event Source Event Routing WMI Event Trace Event Log Trace Log Event Log WMI Subscribers Trace Reader Management Server Management Suite Mgmt Event Repository SQL Trace Event Repository Event Sink

43 .NET 2004/03/24 43 EIF Usage Assemblies Microsoft.EnterpriseInstrumentation Microsoft.EnterpriseInstrumentation.Schema System.Configuration.Install Event sources Implicit event source (application) TraceMessageEvent.Raise(something happened"); Explicit event source

44 .NET 2004/03/24 44 Raise Event by Implicit Event Source using Microsoft.EnterpriseInstrumentation; using Microsoft.EnterpriseInstrumentation.Schema; class MyComponent { // some method public void DoWork() { // Raise an event TraceMessageEvent.Raise(something happened"); }

45 .NET 2004/03/24 45 EIF Explicit Event Source // using statements... class MyComponent { private static EventSource myEventSource = new EventSource(MyEventSource"); public void DoWork() { TraceMessageEvent.Raise(myEventSource, Important message-1"); // or TraceMessageEvent e = new TraceMessageEvent(); e.Message = Important message-2"; myEventSource.Raise(e); }

46 .NET 2004/03/24 46 EIF Configuration Files Default name EnterpriseInstrumentation.config Default locations *.exein the same directory as executable Web applicationsroot of Web Name and location configurable Define in web.config or app.config Use appSettings section

47 .NET 2004/03/24 47 EIF Configuration Definition and control of: Event source Event sink WMI, event log, and Windows event tracing Event categories, describing a set of related events Event filters, which map event sources to specific event categories and event sinks FilterBinding Event Category Event Sinks Event Filter Event Source Events

48 .NET 2004/03/24 48 EIF Event Schemas Events in the standard event schema Administrative events Audit events Error events Trace events Custom event schemas Add additional events and change events

49 .NET 2004/03/24 49 Custom Event Include event schema definitions Define custom event which is derived from standard event Build & install & Register it using System; using Microsoft.EnterpriseInstrumentation.Schema; namespace MyCompany.EnterpriseInstrumentation.Schema { public class CustomEvent : BaseEvent { public CustomEvent() {} public string CustomProperty1 = "Default property value"; }

50 .NET 2004/03/24 50 EIF Custom Event Sinks Writing a custom event sink Derive from EventSink abstract base class Implement the constructor Implement the Dispose method and virtual EventSink::Write() method Use parameters in constructor to set up the event sink Documents have example for MsmqEventSink

51 .NET 2004/03/24 51 Enables tracing user requests through a distributed application Trace business services of the application Can flow across a distributed.NET application Tracing is only activated only specific execution path Events get tagged with request context Even if no tracing session is enabled EIF Request Tracing

52 .NET 2004/03/24 52 Request-based Correlation Of Events Request Event Source public class MyRequestTrace { public static RequestEventSource requestEventSource = new RequestEventSource(My Request Authorization"); public void DoWork(){ RequestTrace myRequest = new RequestTrace(requestEventSource); try { TraceMessageEvent.Raise(My message); } finally { firstRequest.Dispose(); }

53 .NET 2004/03/24 53 Using EIF Request Tracing public class MyRequestTrace { public static RequestEventSource requestEventSource = new RequestEventSource(My Request Authorization"); public void DoWork() { // Request trace starts when the rti is created. using (RequestTrace rti = new RequestTrace(requestEventSource)) { // do something … TraceMessageEvent.Raise(My message); }

54 .NET 2004/03/24 54 Summary Enterprise Instrumentation Framework Significantly improves enterprise customers ability to monitor and troubleshoot.NET applications Integrates and unifies disparate tracing, eventing, and logging technologies Integrates with existing management tools and products via WMI and the Windows Event Log Provides a starting point for distributed trace- log aggregation and analysis

55 Logging Application Block LAB

56 .NET 2004/03/24 56 LAB Overview Provides extensions to the Enterprise Instrumentation Framework (EIF) addressing common usage scenarios for logging Enable control of what and how much information is logged Enable logged information to be consumed by different monitoring/analysis applications with little or no customization Provide useful and rich information in the logged data Support for logging in distributed applications Enable scenarios like metering and workflow tracing for web services

57 .NET 2004/03/24 57 LAB Extensions to EIF Configurable log levels Enhanced information in the published events Event information available in a easily consumable XML format Asynchronous logging (store and forward using MSMQ) Centralized logging (SQL database as the log store) Formatting of event information (XSLT transformation) Request tracing (Workflow tracing) for Web services Metering for Web services EIF publisher for Exception Management Block

58 .NET 2004/03/24 58 LAB Solution concept Event Schema Application EIF Instrumentation API Trace Log Event Log WMI Event Sinks Trace Log Event Log WMI EIF Config WSE Filters SQL MSMQ User Developed PnP Developed Ships out of the Box PnP Modified

59 .NET 2004/03/24 59 Design of Formatting of Event Information ClientApplication Client App Config EIF API EIFConfig FormatterFactory CustomFormatter2 CustomFormatter1 XSLTFormatter Logging Block Event Sink LogStore

60 .NET 2004/03/24 60 Request Tracing for Web Services Capability to trace a request from origin through completion even when the request flows across machine, domain boundaries when using Web Services. Event correlation information carried as part of the Soap Header.

61 .NET 2004/03/24 61 Design of Request Tracing for WS Request Tracing Input Filter Request Tracing Output Filter EIF Logging Block Event Sinks (SQL, MSMQ, WMI and Event Log) EIF Config XSLT based Formatter Log Store WSE Pipeline My Web Service

62 .NET 2004/03/24 62 Summary Enable control of what and how much information is logged Enable logged information to be consumed by different monitoring/analysis applications with little or no customization Provide useful and rich information in the logged data Support for logging in distributed applications Enable scenarios like metering and workflow tracing for web services

63 .NET 2004/03/24 63 Conclusion Manageability play an important role to minimize TCO. Manageability is helpful to development, deployment, and operation management. Application building blocks are most effective when used with.NET Application Architecture and SOA..NET Architecture Patterns & Practices

64 Questions… Microsoft.NET

Download ppt "Improve Manageability Improve Manageability Microsoft.NET."

Similar presentations

Ads by Google