示例#1
0
        static XMLLogParser()
        {
            var xmlParserContext = Metric.Context("XMLLogParser");

            getElementPathTypeCounter         = xmlParserContext.Counter("GetElementDataFromPath Path Type", Unit.Items, "xml, log, parser, get, attribute, path");
            getElementFilterTypeCounter       = xmlParserContext.Counter("GetElementDataFromPath Filter Type", Unit.Items, "xml, log, parser, get, attribute, filter");
            unknownTopNodeTypeCounter         = xmlParserContext.Counter("Unknown Top Node Type", Unit.Errors, "xml, log, parser, get, attribute, unknown");
            failureToAddAttributeToLogCounter = xmlParserContext.Counter("Failure to Add Attribute to Log", Unit.Errors, "xml, log, parser, process, element, failure, add");
            attributesParsedHistogram         = xmlParserContext.Histogram("Attributes Parsed", Unit.Items, tags: "xml, log, parser, process, element, items");
            processElementCounter             = xmlParserContext.Counter("ProcessElement", Unit.Calls, "xml, log, parser, process, element");
            {
                var subContext = xmlParserContext.Context("Parse");
                processElementTimer      = subContext.Timer("ProcessElement", Unit.Calls, tags: "xml, log, parser, parse, process");
                xmlElementCounter        = subContext.Counter("XML Element", Unit.Items, "xml, log, parser, parse, element");
                xmlCDATACounter          = subContext.Counter("XML CDATA", Unit.Items, "xml, log, parser, parse, text, cdata");
                xmlTextCounter           = subContext.Counter("XML Text", Unit.Items, "xml, log, parser, parse, text");
                unknownXmlElementCounter = subContext.Counter("Unknown XML Types", Unit.Items, "xml, log, parser, parse, unknown");
                parseCounter             = subContext.Counter("Unknown XML Types", Unit.Items, "xml, log, parser, parse, unknown");
                xmlRootUnfinishedCounter = subContext.Counter("XML root Unfinished", Unit.Errors, "xml, log, parser, parse, root, unfinished");
            }
            parseCounter = xmlParserContext.Counter("Parse", Unit.Calls, "xml, log, parser, parse");
            setConfigFailureHandlingCounter = xmlParserContext.Counter("SetConfig", Unit.Calls, "xml, log, parser, config, failure, handle");
            {
                var subContext = xmlParserContext.Context("Context");
                contextApplyConfigCounter        = subContext.Counter("ApplyConfig", Unit.Calls, "xml, log, parser, context, config");
                contextApplyConfigSizeHistogram  = subContext.Histogram("ApplyConfig Size", Unit.Items, tags: "xml, log, parser, context, config, size");
                contextApplyContextConfigCounter = subContext.Counter("ApplyContextConfig", Unit.Calls, "xml, log, parser, context, config");
                contextParseCounter = subContext.Counter("Parse", Unit.Calls, "xml, log, parser, context, parse");
            }
            applyContextConfigCounter = xmlParserContext.Counter("ApplyContextConfig", Unit.Calls, "xml, log, parser, context, config");
        }
示例#2
0
        public ServiceProxyProvider(string serviceName, IEventPublisher <ClientCallEvent> eventPublisher,
                                    ICertificateLocator certificateLocator,
                                    ILog log,
                                    Func <string, ReachabilityCheck, IMultiEnvironmentServiceDiscovery> serviceDiscoveryFactory,
                                    Func <DiscoveryConfig> getConfig,
                                    JsonExceptionSerializer exceptionSerializer)
        {
            EventPublisher     = eventPublisher;
            CertificateLocator = certificateLocator;

            Log = log;

            ServiceName         = serviceName;
            GetDiscoveryConfig  = getConfig;
            ExceptionSerializer = exceptionSerializer;

            var metricsContext = Metric.Context(METRICS_CONTEXT_NAME).Context(ServiceName);

            _serializationTime   = metricsContext.Timer("Serialization", Unit.Calls);
            _deserializationTime = metricsContext.Timer("Deserialization", Unit.Calls);
            _roundtripTime       = metricsContext.Timer("Roundtrip", Unit.Calls);

            _successCounter              = metricsContext.Counter("Success", Unit.Calls);
            _failureCounter              = metricsContext.Counter("Failed", Unit.Calls);
            _hostFailureCounter          = metricsContext.Counter("HostFailure", Unit.Calls);
            _applicationExceptionCounter = metricsContext.Counter("ApplicationException", Unit.Calls);

            ServiceDiscovery = serviceDiscoveryFactory(serviceName, ValidateReachability);
        }
        public NetChannel(INetNode node, ITransportChannel transportChannel, IMessageSerializer serializer, ICoreEvents logger, INetNodeConfig config, IBufferPool bufferPool)
        {
            _onOperationSubject          = new Subject <OperationContext>();
            _onDisconnectedSubject       = new Subject <INetChannel>();
            PendingOperationsByRequestId = new ConcurrentDictionary <Guid, PendingOperation>();

            TransportChannel = transportChannel;
            var metricContext = Metric.Context(node.InstanceName);

            _receivedMessagesMeter = metricContext.Meter("ReceivedMessagesMeter", Unit.Requests);
            _sentMessagesMeter     = metricContext.Meter("SentMessagesMeter", Unit.Requests);
            _requestsMeter         = metricContext.Meter("SentRequestsMeter", Unit.Requests);
            _requestsFailedMeter   = metricContext.Meter("SentRequestsFailedMeter", Unit.Requests);
            _requestDurationTimer  = metricContext.Timer("SentRequestsDurationTimer", Unit.Requests, durationUnit: TimeUnit.Milliseconds);


            Node        = node;
            Logger      = logger;
            _config     = config;
            _bufferPool = bufferPool;

            MessageSerializer = serializer;
            IsConnected       = true;
            transportChannel.Bind(ProcessIncomingRequest, Dispose);
        }
        public HttpServiceListener(
            IActivator activator,
            IWorker worker,
            IServiceEndPointDefinition serviceEndPointDefinition,
            ICertificateLocator certificateLocator,
            ILog log,
            IEnumerable <ICustomEndpoint> customEndpoints,
            IEnvironment environment,
            JsonExceptionSerializer exceptionSerializer,
            ServiceSchema serviceSchema,
            Func <LoadShedding> loadSheddingConfig,
            IServerRequestPublisher serverRequestPublisher,
            CurrentApplicationInfo appInfo)
        {
            ServiceSchema           = serviceSchema;
            _serverRequestPublisher = serverRequestPublisher;

            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            CustomEndpoints     = customEndpoints.ToArray();
            Environment         = environment;
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;
            AppInfo             = appInfo;

            if (ServiceEndPointDefinition.HttpsPort != null && ServiceEndPointDefinition.ClientCertificateVerification != ClientCertificateVerificationMode.Disable)
            {
                ServerRootCertHash = certificateLocator.GetCertificate("Service").GetHashOfRootCertificate();
            }

            Listener = new HttpListener {
                IgnoreWriteExceptions = true
            };
            if (ServiceEndPointDefinition.HttpsPort != null)
            {
                Listener.Prefixes.Add($"https://+:{ServiceEndPointDefinition.HttpsPort}/");
            }
            if (ServiceEndPointDefinition.HttpPort != null)
            {
                Listener.Prefixes.Add($"http://+:{ServiceEndPointDefinition.HttpPort}/");
            }
            if (!Listener.Prefixes.Any())
            {
                Log.Warn(_ => _("HttpServiceListener is not listening on any ports, no HTTP or HTTPS ports in ServiceEndPointDefinition"));
            }

            var context = Metric.Context("Service").Context(AppInfo.Name);

            _serializationTime          = context.Timer("Serialization", Unit.Calls);
            _deserializationTime        = context.Timer("Deserialization", Unit.Calls);
            _roundtripTime              = context.Timer("Roundtrip", Unit.Calls);
            _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls);
            _successCounter             = context.Counter("Success", Unit.Calls);
            _failureCounter             = context.Counter("Failed", Unit.Calls);
            _activeRequestsCounter      = context.Timer("ActiveRequests", Unit.Requests);
            _endpointContext            = context.Context("Endpoints");
        }
示例#5
0
 static void InitializeSignalFx(string contextName)
 {
     Metric.Config.WithReporting(Report => Report.WithSignalFxFromAppConfig());
     context = (TaggedMetricsContext)Metric.Context(contextName, (ctxName) => { return(new TaggedMetricsContext(ctxName)); });
     // Create a counter that has the dimension "api:login"
     myCounter = context.Counter("myCounter", Unit.Calls, tags: new MetricTags("api", "login"));
     // Create a timer
     myTimer = context.Timer("myTimer", Unit.Calls);
 }
示例#6
0
        public NetNode(string name, INetProvider net, ICoreEvents logger, IMessageSerializer messageSerializer, Func <INetNode, ITransportChannel, TNetChannel> channelFactory, INetNodeConfig config,
                       IPEndPoint publicAddress = null)
        {
            _config           = config;
            _publicAddress    = publicAddress;
            _logger           = logger;
            InstanceName      = name;
            Net               = net;
            MessageSerializer = messageSerializer;

            ChannelFactory = channelFactory;

            var metricsContext = Metric.Context(name);

            _netChannelsConnectedMeter    = metricsContext.Meter("NetChannelsConnected", Unit.Custom("Channels"));
            _netChannelsDisconnectedMeter = metricsContext.Meter("NetChannelsDisconnected", Unit.Custom("Channels"));
            _netChannelsCounter           = metricsContext.Counter("NetChannelsCount", Unit.Items);
            _nodeUpdateTimer = metricsContext.Timer("NodeUpdateTime", Unit.None);
        }
        public ServiceProxyProvider(string serviceName, IEventPublisher <ClientCallEvent> eventPublisher,
                                    ILog log,
                                    Func <string, ReachabilityCheck, IMultiEnvironmentServiceDiscovery> serviceDiscoveryFactory,
                                    Func <DiscoveryConfig> getConfig,
                                    JsonExceptionSerializer exceptionSerializer,
                                    CurrentApplicationInfo appInfo,
                                    Func <HttpClientConfiguration, HttpMessageHandler> messageHandlerFactory,
                                    IMicrodotTypePolicySerializationBinder serializationBinder)
        {
            JsonSettings.SerializationBinder = serializationBinder;

            EventPublisher = eventPublisher;

            Log = log;

            ServiceName         = serviceName;
            GetDiscoveryConfig  = getConfig;
            ExceptionSerializer = exceptionSerializer;
            AppInfo             = appInfo;

            var metricsContext = Metric.Context(METRICS_CONTEXT_NAME).Context(ServiceName);

            _serializationTime   = metricsContext.Timer("Serialization", Unit.Calls);
            _deserializationTime = metricsContext.Timer("Deserialization", Unit.Calls);
            _roundtripTime       = metricsContext.Timer("Roundtrip", Unit.Calls);

            _successCounter              = metricsContext.Counter("Success", Unit.Calls);
            _failureCounter              = metricsContext.Counter("Failed", Unit.Calls);
            _hostFailureCounter          = metricsContext.Counter("HostFailure", Unit.Calls);
            _applicationExceptionCounter = metricsContext.Counter("ApplicationException", Unit.Calls);

            _httpMessageHandlerFactory = messageHandlerFactory;

            ServiceDiscovery = serviceDiscoveryFactory(serviceName, ValidateReachability);

            var globalConfig  = GetDiscoveryConfig();
            var serviceConfig = GetConfig();

            _httpsTestInterval = TimeSpan.FromMinutes(serviceConfig.TryHttpsIntervalInMinutes ?? globalConfig.TryHttpsIntervalInMinutes);

            _connectionContext = Metric.Context("Connections");
        }
示例#8
0
 public TimerMetric(string contextName, string name, string unit, params string[] tags)
 {
     timer = Metrics_Net.Metric.Context(contextName).Timer(name, unit, tags: tags);
 }
示例#9
0
            public void Call()
            {
                getTimer = metrics.Timer("getTimer", Unit.Requests);
                putTimer = metrics.Timer("putTimer", Unit.Requests);
                setTimer = metrics.Timer("setTimer", Unit.Requests);

                var endTime = DateTime.Now.AddSeconds(duration);
                while (DateTime.Now.CompareTo(endTime) < 0)
                {
                    var map = client.GetMap<object, object>(baseMapName + random.Next(totalMaps));
                    double chance = random.NextDouble();
                    if ((chance -= putProb) <= 0)
                    {
                        using (putTimer.NewContext())
                        {
                            map.Put(random.Next(totalKeys), value);
                        }
                     }
                    else if ((chance -= getProb) <= 0)
                    {
                        using (getTimer.NewContext())
                        {
                            map.Get(random.Next(totalKeys));
                        }
                    }
                    else
                    {
                        using (setTimer.NewContext())
                        {
                            map.Set(random.Next(totalKeys), value);
                        }
                    }
                }
                Console.WriteLine("Call DONE...");
            }
示例#10
0
        // TODO: Would like to see all the instrumentation stuff behind its own service interface
        private void InstallInstrumentation()
        {
            // Counters, timers, etc
            _resultCounter = Metric.Counter("Results Harvested", Unit.Custom("Results"));
            _serviceRequestTimer = Metric.Timer("eBay Service Requests", Unit.Requests);

            // Register gauges
            Metric.Gauge("Error Count", () => _errorCount, Unit.Errors);
            Metric.Gauge("Uptime", () => (DateTime.Now - StartTime).TotalHours, Unit.Custom("Hours"));
        }
示例#11
0
        static void Main(string[] args)
        {
            Metric.Config
            //.WithAllCounters()
            .WithReporting(config => config
                           .WithConsoleReport(TimeSpan.FromSeconds(30))
                           .WithApplicationInsights(ConfigurationManager.AppSettings["AI_InstrumentationKey"].ToString(),
                                                    Guid.NewGuid().ToString(), TimeSpan.FromSeconds(30))
                           );

            // create some metrics
            Counter counter = Metric.Counter("MyItemCounter", Unit.Items);

            counter.Increment();
            counter.Increment();
            counter.Increment();


            Counter counterSuppressed = Metric.Counter("MySuppressedCounter", Unit.Items, ApplicationInsightsReport.DoNotReport);

            counterSuppressed.Increment();

            Metric.Gauge("MyPercentageGauge", () => DateTime.Now.Second, Unit.Percent);

            Meter meter = Metric.Meter("MyErrorsPerSecMeter", Unit.Errors, TimeUnit.Seconds);

            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();
            meter.Mark();

            Histogram histogram = Metric.Histogram("MyItemsHistogram", Unit.Items);

            histogram.Update(456);
            histogram.Update(123);
            histogram.Update(789);

            HealthChecks.RegisterHealthCheck("Seconds", () =>
            {
                if (DateTime.Now.Second > 55)
                {
                    return(HealthCheckResult.Unhealthy("Seconds > 55"));
                }
                else
                {
                    return(HealthCheckResult.Healthy("Seconds <= 55"));
                }
            });
            HealthChecks.RegisterHealthCheck("AlwaysTrue", () => HealthCheckResult.Healthy("Always True check"));

            var rnd = new Random();

            Metrics.Timer timer = Metric.Timer("MyEventsTimer", Unit.Events);
            for (int i = 0; i < 3; i++)
            {
                using (var context = timer.NewContext("TimerCtx"))
                {
                    Thread.Sleep(132 + rnd.Next(15));
                }
            }

            Console.WriteLine("Press any key to end...");
            Console.ReadKey();
        }
        public HttpServiceListener(
            IActivator activator,
            IWorker worker,
            IServiceEndPointDefinition serviceEndPointDefinition,
            ICertificateLocator certificateLocator,
            ILog log,
            IEnumerable <ICustomEndpoint> customEndpoints,
            IEnvironment environment,
            JsonExceptionSerializer exceptionSerializer,
            ServiceSchema serviceSchema,
            Func <LoadShedding> loadSheddingConfig,
            IServerRequestPublisher serverRequestPublisher,
            CurrentApplicationInfo appInfo,
            Func <MicrodotHostingConfig> microdotHostingConfigFactory,
            IMicrodotTypePolicySerializationBinder serializationBinder)
        {
            ServiceSchema           = serviceSchema;
            _serverRequestPublisher = serverRequestPublisher;

            ServiceEndPointDefinition = serviceEndPointDefinition;
            Worker              = worker;
            Activator           = activator;
            Log                 = log;
            CustomEndpoints     = customEndpoints.ToArray();
            Environment         = environment;
            ExceptionSerializer = exceptionSerializer;
            LoadSheddingConfig  = loadSheddingConfig;
            AppInfo             = appInfo;

            JsonSettings.SerializationBinder = serializationBinder;

            if (ServiceEndPointDefinition.HttpsPort != null && ServiceEndPointDefinition.ClientCertificateVerification != ClientCertificateVerificationMode.Disable)
            {
                var serviceCertificate = certificateLocator.GetCertificate("Service");
                Log.Info(_ => _($"Service certificate loaded: {serviceCertificate.FriendlyName}",
                                unencryptedTags: new
                {
                    Thumbprint = serviceCertificate.Thumbprint.Substring(serviceCertificate.Thumbprint.Length - 5),
                }));
                ServerRootCertHash = serviceCertificate.GetHashOfRootCertificate();
            }

            Listener = new HttpListener {
                IgnoreWriteExceptions = true
            };

            _uriPrefixes = new List <string>();

            if (ServiceEndPointDefinition.HttpsPort != null)
            {
                _uriPrefixes.Add($"https://+:{ServiceEndPointDefinition.HttpsPort}/");
            }
            if (ServiceEndPointDefinition.HttpPort != null)
            {
                _uriPrefixes.Add($"http://+:{ServiceEndPointDefinition.HttpPort}/");
            }
            if (!_uriPrefixes.Any())
            {
                Log.Warn(_ => _("HttpServiceListener is not listening on any ports, no HTTP or HTTPS ports in ServiceEndPointDefinition"));
            }
            else
            {
                foreach (string prefix in _uriPrefixes)
                {
                    Listener.Prefixes.Add(prefix);
                }
            }


            var context = Metric.Context("Service").Context(AppInfo.Name);

            _serializationTime          = context.Timer("Serialization", Unit.Calls);
            _deserializationTime        = context.Timer("Deserialization", Unit.Calls);
            _roundtripTime              = context.Timer("Roundtrip", Unit.Calls);
            _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls);
            _successCounter             = context.Counter("Success", Unit.Calls);
            _failureCounter             = context.Counter("Failed", Unit.Calls);
            _activeRequestsCounter      = context.Timer("ActiveRequests", Unit.Requests);
            _endpointContext            = context.Context("Endpoints");
        }