Our next-gen architecture is built to help you make sense of your ever-growing data Watch a 4-min demo video!

Back to All Integrations

Custom Metrics Custom Metrics

Last Updated: Mar. 23, 2023

Coralogix provides a scalable Prometheus-compatible managed service for time-series data.

Coralogix supports ingesting metrics in multiple ways. Our most common integrations are Prometheus & OpenTelemetry, and we also have metrics integrations such as Cloudwatch metrics and AWS Kinesis firehose.

In this document, we explore our custom metric endpoint, which covers even more use cases such as Serverless computing and quick “cURL”-like calls to send Counters, Gauges, and more to Coralogix.

View this GitHub repo for SDK examples of the custom metrics endpoint for grpcurl, Java, and Go.

Data Model

Coralogix metrics follow the Prometheus data model, and metrics can be one of the following: Counter, Gauge, and Histogram (Read more about Prometheus data model).

The Custom Metric API implementation is based on the stable OpenTelemetry Metric Spec.

Here’s a sample of both a counter and a gauge:

{
  "resource_metrics": {
    "scope_metrics": {
      "metrics": [{
        "name": "grpc_sample_gauge1",
        "gauge": {
          "data_points": [{
            "as_double": 0.8,
            "attributes": [{
              "key": "service.name",
              "value": {
                "string_value": "test-service"
              }
              }],
              "start_time_unix_nano": 1657079957000000000,
              "time_unix_nano": 1657079957000000000
          }]
        }
      },{
        "name": "grpc_sample_counter1",
        "gauge": {
          "data_points": [{
            "as_int": 100,
            "attributes": [{
              "key": "service.name",
              "value": {
                "string_value": "test-service"
              }
              }],
              "start_time_unix_nano": 1657079957000000000,
              "time_unix_nano": 1657079957000000000
          }]
        }
      }]
    }
  }
}

* Currently both timestamps as well as service.name are mandatory.

Sending Data with grpcurl

gRPC is a modern way of calling APIs on top of HTTP/2. Similar to cURL, grpcurl is a command-line tool used to communicate with gRPC services.

Coralogix currently supports gRPC only for its custom metrics endpoint. REST APIs will be added in the future.

Assuming the example in the data model is saved as “sample.json”, the following command will send it to Coralogix:

grpcurl -v -d @ -H 'Authorization: Bearer e0cxxxx-xxxx-xxxx-xxxx-xxxa08b' <custom-metrics-endpoint>:443 opentelemetry.proto.collector.metrics.v1.MetricsService/Export <sample.json

For the authorization key, use your Coralogix private key.

* Please contact Coralogix support to receive the relevant custom metrics endpoint for your team.

Using Java

While there are many OpenTelemetry SDKs in this tutorial we will be using Java.

In order to get started quickly with OpenTelemetry SDK and Coralogix, follow this sample project.

Add to your maven pom.xml the following libraries:

<dependency>
  <groupId>io.opentelemetry</groupId>
  <artifactId>opentelemetry-sdk-metrics</artifactId>
</dependency>
<dependency>
  <groupId>io.opentelemetry</groupId>
  <artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>

Code snippet to generate a counter and a gauge:

SdkMeterProvider meterProvider = 
      SdkMeterProvider.builder()
        .registerMetricReader(
          PeriodicMetricReader.builder(
            OtlpGrpcMetricExporter.builder()
              .setEndpoint("<custom-metrics-endpoint>:443")
              .addHeader("Authorization", "Bearer e0cxxxx-xxxx-xxxx-xxxx-xxxa08b")
          .build())
        .build())
      .build();
                
    Meter meter = meterProvider.meterBuilder("test").build();
    
    LongCounter counter = meter
      .counterBuilder("otlp_test_counter1")
      .setDescription("Processed jobs")
      .build();

    counter.add(
      100l, 
      Attributes.of(AttributeKey.stringKey("service.name"), "my-test-service")
    );
    
    meter
      .gaugeBuilder("otlp_test_gauge1")
      .buildWithCallback(measurement -> {
        measurement.record(0.8, Attributes.of(AttributeKey.stringKey("service.name"), "my-test-service"));
      });

    meterProvider.forceFlush();

* Currently the service.name attribute is mandatory on each metric.

On this page