Click here to Skip to main content
15,884,176 members
Articles / DevOps / Load Testing

Measuring and Monitoring WCF Web Service Performance

Rate me:
Please Sign up or sign in to vote.
5.00/5 (17 votes)
4 Oct 2012GPL310 min read 55.3K   2.2K   47  
Using ServiceMon to obtain performance statistics for web services
using System.Drawing;
using System.Text;
using System.Web;
using Kaleida.ServiceMonitor.Model.Email;

namespace Kaleida.ServiceMonitor.Model.Runtime
{
    public static class MonitorStateExtensions
    {
        public static SeverityLevel ToSeverityLevel(this MonitorState state)
        {
            if (!state.IsMonitoring)
                return SeverityLevel.NotMonitoring;

            if (state.OperationErrorCount == 0)
                return SeverityLevel.Operational;
            if (state.OperationErrorCount <= 1)
                return SeverityLevel.Temperamental;
            if (state.OperationErrorCount <= 10)
                return SeverityLevel.Unstable;
            if (state.OperationErrorCount <= 100)
                return SeverityLevel.Critical;

            return SeverityLevel.Dire;

        }
        
        public static Color ToColour(this SeverityLevel level)
        {
            switch (level)
            {
                case SeverityLevel.Operational:
                    return Color.LightGreen;
                case SeverityLevel.Temperamental:
                    return Color.Yellow;
                case SeverityLevel.Unstable:
                    return Color.Orange;
                case SeverityLevel.Critical:
                    return Color.LightCoral;
                case SeverityLevel.Dire:
                    return Color.Crimson;
                default:
                    return Color.Gray;
            }
        }

        public static string ToSummary(this SeverityLevel severityLevel)
        {
            return string.Format("{0} {1} ({2})", (int)severityLevel, severityLevel, severityLevel.ToColour().Name);
        }
        
        public static IHtmlString ToSummaryHtml(this SeverityLevel severityLevel)
        {
            var colour = severityLevel.ToColour();
            var htmlColour = ColorTranslator.ToHtml(colour);

            var html = new StringBuilder();
            html.AppendFormat("<span style='padding:4px; background-color: {0};'>", htmlColour);
            html.AppendFormat("{0} {1}", (int)severityLevel, severityLevel.ToString().HtmlEncode());
            html.AppendFormat(" ({0})</span>", colour.Name);
            return html.ToString().AsRawHtml();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect BlackJet Software Ltd
United Kingdom United Kingdom
Stuart Wheelwright is the Principal Architect and Software Developer at BlackJet Software Ltd.

He has over 16 years commercial experience producing robust, maintainable, web-based solutions and bespoke systems for Microsoft platforms.

His latest project is Shopping UK, an elegantly simple shopping list for iPhone.

Comments and Discussions