toPrometheusFormat method

String toPrometheusFormat({
  1. String prefix = 'queue',
})

Export metrics in Prometheus format

Implementation

String toPrometheusFormat({String prefix = 'queue'}) {
  final buffer = StringBuffer();

  buffer.writeln('# HELP ${prefix}_total_queued Total number of jobs queued');
  buffer.writeln('# TYPE ${prefix}_total_queued counter');
  buffer.writeln('${prefix}_total_queued $totalQueued');

  buffer.writeln(
    '# HELP ${prefix}_total_completed Total number of jobs completed',
  );
  buffer.writeln('# TYPE ${prefix}_total_completed counter');
  buffer.writeln('${prefix}_total_completed $totalCompleted');

  buffer.writeln('# HELP ${prefix}_total_failed Total number of jobs failed');
  buffer.writeln('# TYPE ${prefix}_total_failed counter');
  buffer.writeln('${prefix}_total_failed $totalFailed');

  buffer.writeln(
    '# HELP ${prefix}_currently_processing Number of jobs currently processing',
  );
  buffer.writeln('# TYPE ${prefix}_currently_processing gauge');
  buffer.writeln('${prefix}_currently_processing $currentlyProcessing');

  buffer.writeln('# HELP ${prefix}_throughput Jobs processed per second');
  buffer.writeln('# TYPE ${prefix}_throughput gauge');
  buffer.writeln('${prefix}_throughput $throughput');

  buffer.writeln(
    '# HELP ${prefix}_processing_time_seconds Job processing time',
  );
  buffer.writeln('# TYPE ${prefix}_processing_time_seconds summary');
  buffer.writeln(
    '${prefix}_processing_time_seconds{quantile="0.5"} ${p50ProcessingTime.inMilliseconds / 1000}',
  );
  buffer.writeln(
    '${prefix}_processing_time_seconds{quantile="0.95"} ${p95ProcessingTime.inMilliseconds / 1000}',
  );
  buffer.writeln(
    '${prefix}_processing_time_seconds{quantile="0.99"} ${p99ProcessingTime.inMilliseconds / 1000}',
  );

  buffer.writeln('# HELP ${prefix}_queue_depth Current queue depth');
  buffer.writeln('# TYPE ${prefix}_queue_depth gauge');
  buffer.writeln('${prefix}_queue_depth $currentQueueDepth');

  buffer.writeln(
    '# HELP ${prefix}_worker_utilization Worker utilization (0-1)',
  );
  buffer.writeln('# TYPE ${prefix}_worker_utilization gauge');
  buffer.writeln('${prefix}_worker_utilization $currentWorkerUtilization');

  return buffer.toString();
}