All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.newrelic.telemetry.micrometer.json.SummaryToJson Maven / Gradle / Ivy

The newest version!
/*
 * ---------------------------------------------------------------------------------------------
 *  Copyright (c) 2019 New Relic Corporation. All rights reserved.
 *  Licensed under the Apache 2.0 License. See LICENSE in the project root directory for license information.
 * --------------------------------------------------------------------------------------------
 */

package com.newrelic.telemetry.micrometer.json;

import static com.newrelic.telemetry.micrometer.json.JsonUtil.number;
import static com.newrelic.telemetry.micrometer.json.JsonUtil.object;
import static com.newrelic.telemetry.micrometer.json.JsonUtil.string;

import com.newrelic.telemetry.metrics.Summary;
import java.util.function.Function;

public class SummaryToJson implements Function {

  @Override
  public String apply(Summary summary) {
    StringBuilder buff = new StringBuilder();
    object(
        buff,
        () -> {
          string(buff, "name", summary.getName());
          string(buff, "type", "summary");
          object(
              buff,
              "value",
              () -> {
                number(buff, "count", summary.getCount());
                number(buff, "sum", summary.getSum());
                number(buff, "min", summary.getMin());
                number(buff, "max", summary.getMax(), false);
              });
          number(buff, "timestamp", summary.getStartTimeMs());
          number(buff, "interval.ms", summary.getEndTimeMs() - summary.getStartTimeMs(), false);
          AttributesWriter.writeAttributes(buff, summary.getAttributes());
        },
        false);
    return buff.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy