private static void WriteThreadPoolMetrics(JsonTextWriter writer, HystrixThreadPoolMetrics threadPoolMetrics)
        {
            IHystrixThreadPoolKey key = threadPoolMetrics.ThreadPoolKey;

            writer.WriteStartObject();

            writer.WriteStringField("type", "HystrixThreadPool");
            writer.WriteStringField("name", key.Name);
            writer.WriteLongField("currentTime", Time.CurrentTimeMillisJava);

            writer.WriteIntegerField("currentActiveCount", threadPoolMetrics.CurrentActiveCount);
            writer.WriteIntegerField("currentCompletedTaskCount", threadPoolMetrics.CurrentCompletedTaskCount);
            writer.WriteIntegerField("currentCorePoolSize", threadPoolMetrics.CurrentCorePoolSize);
            writer.WriteIntegerField("currentLargestPoolSize", threadPoolMetrics.CurrentLargestPoolSize);
            writer.WriteIntegerField("currentMaximumPoolSize", threadPoolMetrics.CurrentMaximumPoolSize);
            writer.WriteIntegerField("currentPoolSize", threadPoolMetrics.CurrentPoolSize);
            writer.WriteIntegerField("currentQueueSize", threadPoolMetrics.CurrentQueueSize);
            writer.WriteIntegerField("currentTaskCount", threadPoolMetrics.CurrentTaskCount);
            writer.WriteLongField("rollingCountThreadsExecuted", threadPoolMetrics.GetRollingCount(ThreadPoolEventType.EXECUTED));

            writer.WriteLongField("rollingMaxActiveThreads", threadPoolMetrics.RollingMaxActiveThreads);
            writer.WriteLongField("rollingCountCommandRejections", threadPoolMetrics.GetRollingCount(ThreadPoolEventType.REJECTED));

            writer.WriteIntegerField("propertyValue_queueSizeRejectionThreshold", threadPoolMetrics.Properties.QueueSizeRejectionThreshold);
            writer.WriteIntegerField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", threadPoolMetrics.Properties.MetricsRollingStatisticalWindowInMilliseconds);

            writer.WriteLongField("reportingHosts", 1); // this will get summed across all instances in a cluster

            writer.WriteEndObject();
        }
Beispiel #2
0
 private static void WriteThreadPoolUtilizationJson(JsonTextWriter json, IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolUtilization utilization)
 {
     json.WriteObjectFieldStart(threadPoolKey.Name);
     json.WriteIntegerField("activeCount", utilization.CurrentActiveCount);
     json.WriteIntegerField("queueSize", utilization.CurrentQueueSize);
     json.WriteIntegerField("corePoolSize", utilization.CurrentCorePoolSize);
     json.WriteIntegerField("poolSize", utilization.CurrentPoolSize);
     json.WriteEndObject();
 }
        private static void ConvertExecutionToJson(JsonTextWriter json, ExecutionSignature executionSignature, List <int> latencies)
        {
            json.WriteStartObject();
            json.WriteStringField("name", executionSignature.CommandName);
            json.WriteArrayFieldStart("events");
            ExecutionResult.EventCounts eventCounts = executionSignature.Eventcounts;
            foreach (HystrixEventType eventType in HystrixEventTypeHelper.Values)
            {
                if (!eventType.Equals(HystrixEventType.COLLAPSED))
                {
                    if (eventCounts.Contains(eventType))
                    {
                        int eventCount = eventCounts.GetCount(eventType);
                        if (eventCount > 1)
                        {
                            json.WriteStartObject();
                            json.WriteStringField("name", eventType.ToString());
                            json.WriteIntegerField("count", eventCount);
                            json.WriteEndObject();
                        }
                        else
                        {
                            json.WriteValue(eventType.ToString());
                        }
                    }
                }
            }

            json.WriteEndArray();
            json.WriteArrayFieldStart("latencies");
            foreach (int latency in latencies)
            {
                json.WriteValue(latency);
            }

            json.WriteEndArray();
            if (executionSignature.CachedCount > 0)
            {
                json.WriteIntegerField("cached", executionSignature.CachedCount);
            }

            if (executionSignature.Eventcounts.Contains(HystrixEventType.COLLAPSED))
            {
                json.WriteObjectFieldStart("collapsed");
                json.WriteStringField("name", executionSignature.CollapserKey.Name);
                json.WriteIntegerField("count", executionSignature.CollapserBatchSize);
                json.WriteEndObject();
            }

            json.WriteEndObject();
        }
Beispiel #4
0
        private static void WriteLocalService(JsonTextWriter writer, IServiceInstance localService)
        {
            writer.WriteObjectFieldStart("origin");
            writer.WriteStringField("host", localService?.Host);
            if (localService == null)
            {
                writer.WriteIntegerField("port", -1);
            }
            else
            {
                writer.WriteIntegerField("port", localService.Port);
            }

            writer.WriteStringField("serviceId", localService?.ServiceId);
            writer.WriteStringField("id", contextId);
            writer.WriteEndObject();
        }
 private static void WriteThreadPoolConfigJson(JsonTextWriter json, IHystrixThreadPoolKey threadPoolKey, HystrixThreadPoolConfiguration threadPoolConfig)
 {
     json.WriteObjectFieldStart(threadPoolKey.Name);
     json.WriteIntegerField("coreSize", threadPoolConfig.CoreSize);
     json.WriteIntegerField("maximumSize", threadPoolConfig.MaximumSize);
     json.WriteIntegerField("maxQueueSize", threadPoolConfig.MaxQueueSize);
     json.WriteIntegerField("queueRejectionThreshold", threadPoolConfig.QueueRejectionThreshold);
     json.WriteIntegerField("keepAliveTimeInMinutes", threadPoolConfig.KeepAliveTimeInMinutes);
     json.WriteBooleanField("allowMaximumSizeToDivergeFromCoreSize", threadPoolConfig.AllowMaximumSizeToDivergeFromCoreSize);
     json.WriteIntegerField("counterBucketSizeInMilliseconds", threadPoolConfig.RollingCounterBucketSizeInMilliseconds);
     json.WriteIntegerField("counterBucketCount", threadPoolConfig.RollingCounterNumberOfBuckets);
     json.WriteEndObject();
 }
 private static void WriteCollapserConfigJson(JsonTextWriter json, IHystrixCollapserKey collapserKey, HystrixCollapserConfiguration collapserConfig)
 {
     json.WriteObjectFieldStart(collapserKey.Name);
     json.WriteIntegerField("maxRequestsInBatch", collapserConfig.MaxRequestsInBatch);
     json.WriteIntegerField("timerDelayInMilliseconds", collapserConfig.TimerDelayInMilliseconds);
     json.WriteBooleanField("requestCacheEnabled", collapserConfig.IsRequestCacheEnabled);
     json.WriteObjectFieldStart("metrics");
     HystrixCollapserConfiguration.CollapserMetricsConfig metricsConfig = collapserConfig.CollapserMetricsConfiguration;
     json.WriteIntegerField("percentileBucketSizeInMilliseconds", metricsConfig.RollingPercentileBucketSizeInMilliseconds);
     json.WriteIntegerField("percentileBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteBooleanField("percentileEnabled", metricsConfig.IsRollingPercentileEnabled);
     json.WriteIntegerField("counterBucketSizeInMilliseconds", metricsConfig.RollingCounterBucketSizeInMilliseconds);
     json.WriteIntegerField("counterBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteEndObject();
     json.WriteEndObject();
 }
        private static void WriteCommandMetrics(JsonTextWriter writer, HystrixCommandMetrics commandMetrics)
        {
            IHystrixCommandKey     key            = commandMetrics.CommandKey;
            IHystrixCircuitBreaker circuitBreaker = HystrixCircuitBreakerFactory.GetInstance(key);

            writer.WriteStartObject();
            writer.WriteStringField("type", "HystrixCommand");
            writer.WriteStringField("name", key.Name);
            writer.WriteStringField("group", commandMetrics.CommandGroup.Name);
            writer.WriteLongField("currentTime", Time.CurrentTimeMillisJava);

            // circuit breaker
            if (circuitBreaker == null)
            {
                // circuit breaker is disabled and thus never open
                writer.WriteBooleanField("isCircuitBreakerOpen", false);
            }
            else
            {
                writer.WriteBooleanField("isCircuitBreakerOpen", circuitBreaker.IsOpen);
            }

            HealthCounts healthCounts = commandMetrics.Healthcounts;

            writer.WriteIntegerField("errorPercentage", healthCounts.ErrorPercentage);
            writer.WriteLongField("errorCount", healthCounts.ErrorCount);
            writer.WriteLongField("requestCount", healthCounts.TotalRequests);

            // rolling counters
            writer.WriteLongField("rollingCountBadRequests", commandMetrics.GetRollingCount(HystrixEventType.BAD_REQUEST));
            writer.WriteLongField("rollingCountCollapsedRequests", commandMetrics.GetRollingCount(HystrixEventType.COLLAPSED));
            writer.WriteLongField("rollingCountEmit", commandMetrics.GetRollingCount(HystrixEventType.EMIT));
            writer.WriteLongField("rollingCountExceptionsThrown", commandMetrics.GetRollingCount(HystrixEventType.EXCEPTION_THROWN));
            writer.WriteLongField("rollingCountFailure", commandMetrics.GetRollingCount(HystrixEventType.FAILURE));
            writer.WriteLongField("rollingCountFallbackEmit", commandMetrics.GetRollingCount(HystrixEventType.FALLBACK_EMIT));
            writer.WriteLongField("rollingCountFallbackFailure", commandMetrics.GetRollingCount(HystrixEventType.FALLBACK_FAILURE));
            writer.WriteLongField("rollingCountFallbackMissing", commandMetrics.GetRollingCount(HystrixEventType.FALLBACK_MISSING));
            writer.WriteLongField("rollingCountFallbackRejection", commandMetrics.GetRollingCount(HystrixEventType.FALLBACK_REJECTION));
            writer.WriteLongField("rollingCountFallbackSuccess", commandMetrics.GetRollingCount(HystrixEventType.FALLBACK_SUCCESS));
            writer.WriteLongField("rollingCountResponsesFromCache", commandMetrics.GetRollingCount(HystrixEventType.RESPONSE_FROM_CACHE));
            writer.WriteLongField("rollingCountSemaphoreRejected", commandMetrics.GetRollingCount(HystrixEventType.SEMAPHORE_REJECTED));
            writer.WriteLongField("rollingCountShortCircuited", commandMetrics.GetRollingCount(HystrixEventType.SHORT_CIRCUITED));
            writer.WriteLongField("rollingCountSuccess", commandMetrics.GetRollingCount(HystrixEventType.SUCCESS));
            writer.WriteLongField("rollingCountThreadPoolRejected", commandMetrics.GetRollingCount(HystrixEventType.THREAD_POOL_REJECTED));
            writer.WriteLongField("rollingCountTimeout", commandMetrics.GetRollingCount(HystrixEventType.TIMEOUT));

            writer.WriteIntegerField("currentConcurrentExecutionCount", commandMetrics.CurrentConcurrentExecutionCount);
            writer.WriteLongField("rollingMaxConcurrentExecutionCount", commandMetrics.RollingMaxConcurrentExecutions);

            // latency percentiles
            writer.WriteIntegerField("latencyExecute_mean", commandMetrics.ExecutionTimeMean);
            writer.WriteObjectFieldStart("latencyExecute");
            writer.WriteIntegerField("0", commandMetrics.GetExecutionTimePercentile(0));
            writer.WriteIntegerField("25", commandMetrics.GetExecutionTimePercentile(25));
            writer.WriteIntegerField("50", commandMetrics.GetExecutionTimePercentile(50));
            writer.WriteIntegerField("75", commandMetrics.GetExecutionTimePercentile(75));
            writer.WriteIntegerField("90", commandMetrics.GetExecutionTimePercentile(90));
            writer.WriteIntegerField("95", commandMetrics.GetExecutionTimePercentile(95));
            writer.WriteIntegerField("99", commandMetrics.GetExecutionTimePercentile(99));
            writer.WriteIntegerField("99.5", commandMetrics.GetExecutionTimePercentile(99.5));
            writer.WriteIntegerField("100", commandMetrics.GetExecutionTimePercentile(100));
            writer.WriteEndObject();
            writer.WriteIntegerField("latencyTotal_mean", commandMetrics.TotalTimeMean);
            writer.WriteObjectFieldStart("latencyTotal");
            writer.WriteIntegerField("0", commandMetrics.GetTotalTimePercentile(0));
            writer.WriteIntegerField("25", commandMetrics.GetTotalTimePercentile(25));
            writer.WriteIntegerField("50", commandMetrics.GetTotalTimePercentile(50));
            writer.WriteIntegerField("75", commandMetrics.GetTotalTimePercentile(75));
            writer.WriteIntegerField("90", commandMetrics.GetTotalTimePercentile(90));
            writer.WriteIntegerField("95", commandMetrics.GetTotalTimePercentile(95));
            writer.WriteIntegerField("99", commandMetrics.GetTotalTimePercentile(99));
            writer.WriteIntegerField("99.5", commandMetrics.GetTotalTimePercentile(99.5));
            writer.WriteIntegerField("100", commandMetrics.GetTotalTimePercentile(100));
            writer.WriteEndObject();

            // property values for reporting what is actually seen by the command rather than what was set somewhere
            IHystrixCommandOptions commandProperties = commandMetrics.Properties;

            writer.WriteIntegerField("propertyValue_circuitBreakerRequestVolumeThreshold", commandProperties.CircuitBreakerRequestVolumeThreshold);
            writer.WriteIntegerField("propertyValue_circuitBreakerSleepWindowInMilliseconds", commandProperties.CircuitBreakerSleepWindowInMilliseconds);
            writer.WriteIntegerField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.CircuitBreakerErrorThresholdPercentage);
            writer.WriteBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.CircuitBreakerForceOpen);
            writer.WriteBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.CircuitBreakerForceClosed);
            writer.WriteBooleanField("propertyValue_circuitBreakerEnabled", commandProperties.CircuitBreakerEnabled);

            writer.WriteStringField("propertyValue_executionIsolationStrategy", commandProperties.ExecutionIsolationStrategy.ToString());
            writer.WriteIntegerField("propertyValue_executionIsolationThreadTimeoutInMilliseconds", commandProperties.ExecutionTimeoutInMilliseconds);
            writer.WriteIntegerField("propertyValue_executionTimeoutInMilliseconds", commandProperties.ExecutionTimeoutInMilliseconds);
            writer.WriteBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout", false);
            writer.WriteStringField("propertyValue_executionIsolationThreadPoolKeyOverride", commandProperties.ExecutionIsolationThreadPoolKeyOverride);
            writer.WriteIntegerField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests", commandProperties.ExecutionIsolationSemaphoreMaxConcurrentRequests);
            writer.WriteIntegerField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests", commandProperties.FallbackIsolationSemaphoreMaxConcurrentRequests);
            writer.WriteIntegerField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", commandProperties.MetricsRollingStatisticalWindowInMilliseconds);
            writer.WriteBooleanField("propertyValue_requestCacheEnabled", commandProperties.RequestCacheEnabled);
            writer.WriteBooleanField("propertyValue_requestLogEnabled", commandProperties.RequestLogEnabled);
            writer.WriteIntegerField("reportingHosts", 1); // this will get summed across all instances in a cluster
            writer.WriteStringField("threadPool", commandMetrics.ThreadPoolKey.Name);
            writer.WriteEndObject();
        }
        private static void WriteCollapserMetrics(JsonTextWriter writer, HystrixCollapserMetrics collapserMetrics)
        {
            IHystrixCollapserKey key = collapserMetrics.CollapserKey;

            writer.WriteStartObject();

            writer.WriteStringField("type", "HystrixCollapser");
            writer.WriteStringField("name", key.Name);
            writer.WriteLongField("currentTime", Time.CurrentTimeMillisJava);

            writer.WriteLongField("rollingCountRequestsBatched", collapserMetrics.GetRollingCount(CollapserEventType.ADDED_TO_BATCH));

            writer.WriteLongField("rollingCountBatches", collapserMetrics.GetRollingCount(CollapserEventType.BATCH_EXECUTED));

            writer.WriteLongField("rollingCountResponsesFromCache", collapserMetrics.GetRollingCount(CollapserEventType.RESPONSE_FROM_CACHE));

            // batch size percentiles
            writer.WriteIntegerField("batchSize_mean", collapserMetrics.BatchSizeMean);
            writer.WriteObjectFieldStart("batchSize");
            writer.WriteIntegerField("25", collapserMetrics.GetBatchSizePercentile(25));
            writer.WriteIntegerField("50", collapserMetrics.GetBatchSizePercentile(50));
            writer.WriteIntegerField("75", collapserMetrics.GetBatchSizePercentile(75));
            writer.WriteIntegerField("90", collapserMetrics.GetBatchSizePercentile(90));
            writer.WriteIntegerField("95", collapserMetrics.GetBatchSizePercentile(95));
            writer.WriteIntegerField("99", collapserMetrics.GetBatchSizePercentile(99));
            writer.WriteIntegerField("99.5", collapserMetrics.GetBatchSizePercentile(99.5));
            writer.WriteIntegerField("100", collapserMetrics.GetBatchSizePercentile(100));
            writer.WriteEndObject();

            writer.WriteBooleanField("propertyValue_requestCacheEnabled", collapserMetrics.Properties.RequestCacheEnabled);
            writer.WriteIntegerField("propertyValue_maxRequestsInBatch", collapserMetrics.Properties.MaxRequestsInBatch);
            writer.WriteIntegerField("propertyValue_timerDelayInMilliseconds", collapserMetrics.Properties.TimerDelayInMilliseconds);

            writer.WriteIntegerField("reportingHosts", 1); // this will get summed across all instances in a cluster

            writer.WriteEndObject();
        }
 private static void WriteCommandConfigJson(JsonTextWriter json, IHystrixCommandKey key, HystrixCommandConfiguration commandConfig)
 {
     json.WriteObjectFieldStart(key.Name);
     json.WriteStringField("threadPoolKey", commandConfig.ThreadPoolKey.Name);
     json.WriteStringField("groupKey", commandConfig.GroupKey.Name);
     json.WriteObjectFieldStart("execution");
     HystrixCommandConfiguration.HystrixCommandExecutionConfig executionConfig = commandConfig.ExecutionConfig;
     json.WriteStringField("isolationStrategy", executionConfig.IsolationStrategy.ToString());
     json.WriteStringField("threadPoolKeyOverride", executionConfig.ThreadPoolKeyOverride);
     json.WriteBooleanField("requestCacheEnabled", executionConfig.IsRequestCacheEnabled);
     json.WriteBooleanField("requestLogEnabled", executionConfig.IsRequestLogEnabled);
     json.WriteBooleanField("timeoutEnabled", executionConfig.IsTimeoutEnabled);
     json.WriteBooleanField("fallbackEnabled", executionConfig.IsFallbackEnabled);
     json.WriteIntegerField("timeoutInMilliseconds", executionConfig.TimeoutInMilliseconds);
     json.WriteIntegerField("semaphoreSize", executionConfig.SemaphoreMaxConcurrentRequests);
     json.WriteIntegerField("fallbackSemaphoreSize", executionConfig.FallbackMaxConcurrentRequest);
     json.WriteBooleanField("threadInterruptOnTimeout", executionConfig.IsThreadInterruptOnTimeout);
     json.WriteEndObject();
     json.WriteObjectFieldStart("metrics");
     HystrixCommandConfiguration.HystrixCommandMetricsConfig metricsConfig = commandConfig.MetricsConfig;
     json.WriteIntegerField("healthBucketSizeInMs", metricsConfig.HealthIntervalInMilliseconds);
     json.WriteIntegerField("percentileBucketSizeInMilliseconds", metricsConfig.RollingPercentileBucketSizeInMilliseconds);
     json.WriteIntegerField("percentileBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteBooleanField("percentileEnabled", metricsConfig.IsRollingPercentileEnabled);
     json.WriteIntegerField("counterBucketSizeInMilliseconds", metricsConfig.RollingCounterBucketSizeInMilliseconds);
     json.WriteIntegerField("counterBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteEndObject();
     json.WriteObjectFieldStart("circuitBreaker");
     HystrixCommandConfiguration.HystrixCommandCircuitBreakerConfig circuitBreakerConfig = commandConfig.CircuitBreakerConfig;
     json.WriteBooleanField("enabled", circuitBreakerConfig.IsEnabled);
     json.WriteBooleanField("isForcedOpen", circuitBreakerConfig.IsForceOpen);
     json.WriteBooleanField("isForcedClosed", circuitBreakerConfig.IsForceOpen);
     json.WriteIntegerField("requestVolumeThreshold", circuitBreakerConfig.RequestVolumeThreshold);
     json.WriteIntegerField("errorPercentageThreshold", circuitBreakerConfig.ErrorThresholdPercentage);
     json.WriteIntegerField("sleepInMilliseconds", circuitBreakerConfig.SleepWindowInMilliseconds);
     json.WriteEndObject();
     json.WriteEndObject();
 }
Beispiel #10
0
 private static void WriteCommandUtilizationJson(JsonTextWriter json, IHystrixCommandKey key, HystrixCommandUtilization utilization)
 {
     json.WriteObjectFieldStart(key.Name);
     json.WriteIntegerField("activeCount", utilization.ConcurrentCommandCount);
     json.WriteEndObject();
 }