示例#1
0
    public void toJson(JsonGenerator gen) throws IOException {
      gen.writeStartObject();

      gen.writeBooleanField("old", oldRecordExists);
      gen.writeBooleanField("new", newRecordExists);
      gen.writeBooleanField("includeSubscriptions", includeSubscriptions);

      if (newRecordType != null) {
        gen.writeBinaryField("newRecordType", newRecordType.getBytes());
      }

      if (oldRecordType != null) {
        gen.writeBinaryField("oldRecordType", oldRecordType.getBytes());
      }

      if (fieldChanges != null) {
        gen.writeArrayFieldStart("fields");

        for (FieldChange fieldChange : fieldChanges) {
          fieldChange.toJson(gen);
        }

        gen.writeEndArray();
      }

      if (indexSubscriptionIds != null) {
        gen.writeArrayFieldStart("subscriptions");
        for (String subscriptionId : indexSubscriptionIds) {
          gen.writeString(subscriptionId);
        }
        gen.writeEndArray();
      }

      gen.writeEndObject();
    }
  private static void writeTrace(
      final Trace trace, final int traceId, final JsonGenerator generator) throws IOException {
    generator.writeStartObject();
    generator.writeNumberField(JsonTraceCodec.TRACE_ID, traceId);
    generator.writeStringField(JsonTraceCodec.TRACE_NAME, trace.getName());
    generator.writeStringField(JsonTraceCodec.TRACE_RESULT_TYPE, trace.getResultType().toString());
    generator.writeBooleanField(JsonTraceCodec.TRACE_HIDDEN, trace.getHidden());
    generator.writeBooleanField(JsonTraceCodec.TRACE_SYSTEM_HIDDEN, trace.getSystemHidden());

    if (trace.getValue() != null) {
      generator.writeStringField(JsonTraceCodec.TRACE_VALUE, trace.getValue());
    }

    if (trace.getStartNanos() != null) {
      generator.writeNumberField(JsonTraceCodec.TRACE_START_NANOS, trace.getStartNanos());
    }

    if (trace.getEndNanos() != null) {
      generator.writeNumberField(JsonTraceCodec.TRACE_END_NANOS, trace.getEndNanos());
    }

    if (trace.getAttributes() != null && trace.getAttributes().size() > 0) {
      generator.writeArrayFieldStart(JsonTraceCodec.TRACE_ATTRIBUTES);
      for (Map.Entry<String, String> attribute : trace.getAttributes().entrySet()) {
        generator.writeStartObject();
        generator.writeStringField(JsonTraceCodec.TRACE_ATTRIBUTE_KEY, attribute.getKey());
        generator.writeStringField(JsonTraceCodec.TRACE_ATTRIBUTE_VALUE, attribute.getValue());
        generator.writeEndObject();
      }
      generator.writeEndArray();
    }

    generator.writeEndObject();
  }
示例#3
0
  public void toJson(JsonGenerator gen) throws IOException {

    gen.writeStartObject();

    if (type != null) {
      gen.writeStringField("type", type.getName());
    }

    if (tableName != null) {
      gen.writeStringField("tableName", tableName);
    }

    if (versionUpdated != -1) {
      gen.writeNumberField("versionUpdated", versionUpdated);
    }

    if (versionCreated != -1) {
      gen.writeNumberField("versionCreated", versionCreated);
    }

    if (recordTypeChanged) {
      gen.writeBooleanField("recordTypeChanged", true);
    }

    if (updatedFields != null && updatedFields.size() > 0) {
      gen.writeArrayFieldStart("updatedFields");
      for (SchemaId updatedField : updatedFields) {
        gen.writeBinary(updatedField.getBytes());
      }
      gen.writeEndArray();
    }

    if (vtagsToIndex != null && vtagsToIndex.size() > 0) {
      gen.writeArrayFieldStart("vtagsToIndex");
      for (SchemaId vtag : vtagsToIndex) {
        gen.writeBinary(vtag.getBytes());
      }
      gen.writeEndArray();
    }

    if (attributes != null && attributes.size() > 0) {
      gen.writeObjectFieldStart("attributes");
      for (String key : attributes.keySet()) {
        gen.writeStringField(key, attributes.get(key));
      }
      gen.writeEndObject();
    }

    if (indexRecordFilterData != null) {
      gen.writeFieldName("indexFilterData");
      indexRecordFilterData.toJson(gen);
    }

    gen.writeEndObject();
    gen.flush();
  }
 @Override
 public void serialize(JsonGenerator jg, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jg.writeStartObject();
   jg.writeStringField(COL_TYPE, getType());
   jg.writeStringField(COL_INFO, getInfo());
   if (isPrimary()) jg.writeBooleanField(COL_PRIMARY, true);
   if (isBinding()) jg.writeBooleanField(COL_BINDING, true);
   if (StringUtils.isNotEmpty(getLabel())) jg.writeStringField(COL_LABEL, getLabel());
   jg.writeEndObject();
 }
示例#5
0
 protected void writeExtendedInfo(JsonGenerator jg, String key, Serializable value)
     throws IOException {
   Class<?> clazz = value.getClass();
   if (Long.class.isAssignableFrom(clazz)) {
     jg.writeNumberField(key, (Long) value);
   } else if (Integer.class.isAssignableFrom(clazz)) {
     jg.writeNumberField(key, (Integer) value);
   } else if (Double.class.isAssignableFrom(clazz)) {
     jg.writeNumberField(key, (Double) value);
   } else if (Date.class.isAssignableFrom(clazz)) {
     jg.writeStringField(key, ISODateTimeFormat.dateTime().print(new DateTime(value)));
   } else if (String.class.isAssignableFrom(clazz)) {
     jg.writeStringField(key, (String) value);
   } else if (Boolean.class.isAssignableFrom(clazz)) {
     jg.writeBooleanField(key, (Boolean) value);
   } else {
     jg.writeStringField(key, value.toString());
   }
 }
 public void writeJson(JsonGenerator g) throws JsonGenerationException, IOException {
   g.writeStartObject();
   g.writeBooleanField(SUCCESS, success);
   g.writeStringField(MESSAGE, message);
   g.writeArrayFieldStart(DATA);
   if (null != list && !list.isEmpty()) {
     for (T model : list) {
       // write model data
       g.writeStartObject();
       g.writeStringField("key", model.getKey());
       g.writeStringField("label", model.getLabel());
       g.writeEndObject();
     }
   }
   g.writeEndArray();
   // write model data end
   g.writeEndObject();
   g.flush();
   g.close();
 }
示例#7
0
 public void testWritePrimitiveWithBoolean() throws Exception {
   generator.writeBooleanField("foo", false);
   replayMocks();
   nullSafeWritePrimitiveField(generator, "foo", false);
   verifyMocks();
 }
示例#8
0
  @Override
  public void run() {

    try {
      // command metrics
      for (HystrixCommandMetrics commandMetrics : HystrixCommandMetrics.getInstances()) {
        HystrixCommandKey key = commandMetrics.getCommandKey();
        HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
        StringWriter jsonString = new StringWriter();
        JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);

        // Informational and Status
        json.writeStartObject();
        json.writeStringField(type.value, HystrixCommand.value);
        json.writeStringField(name.value, key.name());
        json.writeStringField(group.value, commandMetrics.getCommandGroup().name());
        json.writeNumberField(currentTime.value, (int) (System.currentTimeMillis() / 1000));

        // circuit breaker
        json.writeBooleanField(isCircuitBreakerOpen.value, circuitBreaker.isOpen());
        HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts();
        json.writeNumberField(errorPercentage.value, healthCounts.getErrorPercentage());
        json.writeNumberField(errorCount.value, healthCounts.getErrorCount());
        json.writeNumberField(requestCount.value, healthCounts.getTotalRequests());

        // rolling counters  Gauge
        json.writeNumberField(
            rollingCountCollapsedRequests.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.COLLAPSED));
        json.writeNumberField(
            rollingCountExceptionsThrown.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.EXCEPTION_THROWN));
        json.writeNumberField(
            rollingCountFailure.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.FAILURE));
        json.writeNumberField(
            rollingCountFallbackFailure.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_FAILURE));
        json.writeNumberField(
            rollingCountFallbackRejection.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_REJECTION));
        json.writeNumberField(
            rollingCountFallbackSuccess.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS));
        json.writeNumberField(
            rollingCountResponsesFromCache.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.RESPONSE_FROM_CACHE));
        json.writeNumberField(
            rollingCountSemaphoreRejected.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED));
        json.writeNumberField(
            rollingCountShortCircuited.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.SHORT_CIRCUITED));
        json.writeNumberField(
            rollingCountSuccess.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS));
        json.writeNumberField(
            rollingCountThreadPoolRejected.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED));
        json.writeNumberField(
            rollingCountTimeout.value,
            commandMetrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT));

        json.writeNumberField(
            currentConcurrentExecutionCount.value,
            commandMetrics.getCurrentConcurrentExecutionCount());

        // latency percentiles
        json.writeNumberField(latencyExecute_mean.value, commandMetrics.getExecutionTimeMean());
        json.writeObjectFieldStart(latencyExecute.value);
        json.writeNumberField("0", commandMetrics.getExecutionTimePercentile(0));
        json.writeNumberField("25", commandMetrics.getExecutionTimePercentile(25));
        json.writeNumberField("50", commandMetrics.getExecutionTimePercentile(50));
        json.writeNumberField("75", commandMetrics.getExecutionTimePercentile(75));
        json.writeNumberField("90", commandMetrics.getExecutionTimePercentile(90));
        json.writeNumberField("95", commandMetrics.getExecutionTimePercentile(95));
        json.writeNumberField("99", commandMetrics.getExecutionTimePercentile(99));
        json.writeNumberField("99.5", commandMetrics.getExecutionTimePercentile(99.5));
        json.writeNumberField("100", commandMetrics.getExecutionTimePercentile(100));
        json.writeEndObject();
        //
        json.writeNumberField(latencyTotal_mean.value, commandMetrics.getTotalTimeMean());
        json.writeObjectFieldStart(latencyTotal.value);
        json.writeNumberField("0", commandMetrics.getTotalTimePercentile(0));
        json.writeNumberField("25", commandMetrics.getTotalTimePercentile(25));
        json.writeNumberField("50", commandMetrics.getTotalTimePercentile(50));
        json.writeNumberField("75", commandMetrics.getTotalTimePercentile(75));
        json.writeNumberField("90", commandMetrics.getTotalTimePercentile(90));
        json.writeNumberField("95", commandMetrics.getTotalTimePercentile(95));
        json.writeNumberField("99", commandMetrics.getTotalTimePercentile(99));
        json.writeNumberField("99.5", commandMetrics.getTotalTimePercentile(99.5));
        json.writeNumberField("100", commandMetrics.getTotalTimePercentile(100));
        json.writeEndObject();

        // property values for reporting what is actually seen by the command rather than what was
        // set somewhere
        HystrixCommandProperties commandProperties = commandMetrics.getProperties();

        json.writeNumberField(
            propertyValue_circuitBreakerRequestVolumeThreshold.value,
            commandProperties.circuitBreakerRequestVolumeThreshold().get());
        json.writeNumberField(
            propertyValue_circuitBreakerSleepWindowInMilliseconds.value,
            commandProperties.circuitBreakerSleepWindowInMilliseconds().get());
        json.writeNumberField(
            propertyValue_circuitBreakerErrorThresholdPercentage.value,
            commandProperties.circuitBreakerErrorThresholdPercentage().get());
        json.writeBooleanField(
            propertyValue_circuitBreakerForceOpen.value,
            commandProperties.circuitBreakerForceOpen().get());
        json.writeBooleanField(
            propertyValue_circuitBreakerForceClosed.value,
            commandProperties.circuitBreakerForceClosed().get());
        json.writeBooleanField(
            propertyValue_circuitBreakerEnabled.value,
            commandProperties.circuitBreakerEnabled().get());

        json.writeStringField(
            propertyValue_executionIsolationStrategy.value,
            commandProperties.executionIsolationStrategy().get().name());
        json.writeNumberField(
            propertyValue_executionIsolationThreadTimeoutInMilliseconds.value,
            commandProperties.executionIsolationThreadTimeoutInMilliseconds().get());
        json.writeBooleanField(
            propertyValue_executionIsolationThreadInterruptOnTimeout.value,
            commandProperties.executionIsolationThreadInterruptOnTimeout().get());
        json.writeStringField(
            propertyValue_executionIsolationThreadPoolKeyOverride.value,
            commandProperties.executionIsolationThreadPoolKeyOverride().get());
        json.writeNumberField(
            propertyValue_executionIsolationSemaphoreMaxConcurrentRequests.value,
            commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get());
        json.writeNumberField(
            propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests.value,
            commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get());

        /*
         * The following are commented out as these rarely change and are verbose for streaming for something people don't change.
         * We could perhaps allow a property or request argument to include these.
         */

        //                    json.put("propertyValue_metricsRollingPercentileEnabled",
        // commandProperties.metricsRollingPercentileEnabled().get());
        //                    json.put("propertyValue_metricsRollingPercentileBucketSize",
        // commandProperties.metricsRollingPercentileBucketSize().get());
        //                    json.put("propertyValue_metricsRollingPercentileWindow",
        // commandProperties.metricsRollingPercentileWindowInMilliseconds().get());
        //                    json.put("propertyValue_metricsRollingPercentileWindowBuckets",
        // commandProperties.metricsRollingPercentileWindowBuckets().get());
        //                    json.put("propertyValue_metricsRollingStatisticalWindowBuckets",
        // commandProperties.metricsRollingStatisticalWindowBuckets().get());
        json.writeNumberField(
            propertyValue_metricsRollingStatisticalWindowInMilliseconds.value,
            commandProperties.metricsRollingStatisticalWindowInMilliseconds().get());
        json.writeBooleanField(
            propertyValue_requestCacheEnabled.value, commandProperties.requestCacheEnabled().get());
        json.writeBooleanField(
            propertyValue_requestLogEnabled.value, commandProperties.requestLogEnabled().get());
        json.writeNumberField(reportingHosts.value, 1);

        json.writeStringField(Key.ip.value, app_ip);

        json.writeEndObject();
        json.close();
        //                System.out.println(ip + ":" + port + "||" +
        // jsonString.getBuffer().toString());
        UDPClient.send(
            socketIp, socketPort, jsonString.getBuffer().toString().getBytes(), new byte[] {});
      }

      // thread pool metrics
      for (HystrixThreadPoolMetrics threadPoolMetrics : HystrixThreadPoolMetrics.getInstances()) {
        HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

        StringWriter jsonString = new StringWriter();
        JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);
        json.writeStartObject();

        json.writeStringField(type.value, HystrixThreadPool.value);
        json.writeStringField(name.value, key.name());
        json.writeNumberField(currentTime.value, System.currentTimeMillis());

        // 101.3 80 154

        json.writeNumberField(
            currentActiveCount.value, threadPoolMetrics.getCurrentActiveCount().intValue());
        json.writeNumberField(
            currentCompletedTaskCount.value,
            threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
        json.writeNumberField(
            currentCorePoolSize.value, threadPoolMetrics.getCurrentCorePoolSize().intValue());
        json.writeNumberField(
            currentLargestPoolSize.value, threadPoolMetrics.getCurrentLargestPoolSize().intValue());
        json.writeNumberField(
            currentMaximumPoolSize.value, threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
        json.writeNumberField(
            currentPoolSize.value, threadPoolMetrics.getCurrentPoolSize().intValue());
        json.writeNumberField(
            currentQueueSize.value, threadPoolMetrics.getCurrentQueueSize().intValue());
        json.writeNumberField(
            currentTaskCount.value, threadPoolMetrics.getCurrentTaskCount().longValue());
        json.writeNumberField(
            rollingCountThreadsExecuted.value, threadPoolMetrics.getRollingCountThreadsExecuted());
        json.writeNumberField(
            rollingMaxActiveThreads.value, threadPoolMetrics.getRollingMaxActiveThreads());

        json.writeNumberField(
            propertyValue_queueSizeRejectionThreshold.value,
            threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
        json.writeNumberField(
            propertyValue_metricsRollingStatisticalWindowInMilliseconds.value,
            threadPoolMetrics
                .getProperties()
                .metricsRollingStatisticalWindowInMilliseconds()
                .get());

        json.writeNumberField(
            reportingHosts.value, 1); // this will get summed across all instances in a cluster
        json.writeStringField(Key.ip.value, app_ip);
        json.writeEndObject();
        json.close();

        String str = jsonString.getBuffer().toString();
        byte[] ret = str.getBytes();
        UDPClient.send(socketIp, socketPort, ret, new byte[] {});
      }
    } catch (Exception e) {
      System.err.println("Failed to output metrics as JSON");
      e.printStackTrace();
    }
  }