prometheus_metricsPrometheus

Mock Jutsu HOW-TO | EN

The prometheus_metrics function within the mock-jutsu library is a specialized tool designed to generate high-fidelity Prometheus text exposition data. This function is essential for developers who need to simulate observability telemetry without the overhead of deploying and configuring live exporters or sidecars. By producing authentic mock data that strictly adheres to the Prometheus text-based format, the utility enables the seamless testing of monitoring pipelines, scraping intervals, and data visualization layers. The output includes a sophisticated mix of process-level CPU and memory statistics, Go runtime metrics, and detailed HTTP request telemetry, ensuring a comprehensive representation of a modern cloud-native application.

Technically, the prometheus_metrics function follows the standard Prometheus exposition format, including necessary HELP and TYPE metadata for each metric. It generates complex HTTP counters categorized by method, path, and status code, alongside histograms that utilize monotonic buckets where the +Inf bucket correctly matches the total observation count. This attention to detail ensures that the test data is functionally indistinguishable from real-world metrics, allowing for the validation of complex PromQL queries and alerting rules. Whether integrated via the Python SDK using jutsu.generate('prometheus_metrics') or invoked through the mock-jutsu CLI, the resulting data maintains the structural integrity required by Prometheus-compatible scrapers.

The primary benefit of using mock-jutsu for metric generation is the ability to conduct rigorous integration testing and performance benchmarking. SREs and DevOps engineers can use the JMeter function syntax, ${__mockjutsu(prometheus_metrics,)}, to inject dynamic telemetry into load testing scripts, simulating how monitoring systems behave under high-stress conditions. This approach is invaluable for verifying Grafana dashboard configurations and ensuring that alert thresholds are properly tuned before moving to production. By providing realistic, repeatable test data, this function reduces infrastructure costs and accelerates the development lifecycle, allowing teams to build more resilient observability stacks with confidence.

CLI Usage
mockjutsu generate prometheus_metricsmockjutsu bulk prometheus_metrics --count 10mockjutsu export prometheus_metrics --count 10 --format jsonmockjutsu export prometheus_metrics --count 10 --format csvmockjutsu export prometheus_metrics --count 10 --format sql
Python API
from mockjutsu import jutsujutsu.generate('prometheus_metrics')jutsu.bulk('prometheus_metrics', count=10)jutsu.template(['prometheus_metrics'], count=5)
JMeter
${__mockjutsu_prometheus(prometheus_metrics)}# JMeter Function: __mockjutsu_prometheus# Parameter 1: prometheus_metrics# Parameter 2: (not required for this function)
REST API
GET /generate/prometheus_metrics# → {"type":"prometheus_metrics","result":"...","status":"ok"}GET /bulk/prometheus_metrics?count=10POST /template {"types":["prometheus_metrics"],"count":1}

Example Output

{"exposition": "# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.\n# TYPE process_cpu_seconds_total counter\nprocess_cpu_seconds_total 11715.85\n# HELP process_resident_memory_bytes Resident memory size in bytes.\n# TYPE process_resident_memory_bytes gauge\nprocess_resident_memory_bytes 2755210250\n# HELP process_virtual_memory_bytes Virtual memory size in bytes.\n# TYPE process_virtual_memory_bytes gauge\nprocess_virtual_memory_bytes 2894975875\n# HELP process_open_fds Number of open file descriptors.\n# TYPE process_open_fds gauge\nprocess_open_fds 136\n# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.\n# TYPE process_start_time_seconds gauge\nprocess_start_time_seconds 1780925039.211\n\n# HELP http_requests_total Total number of HTTP requests received.\n# TYPE http_requests_total counter\nhttp_requests_total{method=\"GET\",path=\"/api/v1/users\",status=\"500\"} 45192\nhttp_requests_total{method=\"GET\",path=\"/api/health\",status=\"500\"} 497\nhttp_requests_total{method=\"GET\",path=\"/api/v1/orders\",status=\"200\"} 1763\nhttp_requests_total{method=\"GET\",path=\"/\",status=\"204\"} 6278\nhttp_requests_total{method=\"DELETE\",path=\"/api/v1/users\",status=\"201\"} 18677\nhttp_requests_total{method=\"DELETE\",path=\"/api/health\",status=\"201\"} 98637\nhttp_requests_total{method=\"DELETE\",path=\"/api/v1/orders\",status=\"502\"} 25700\nhttp_requests_total{method=\"DELETE\",path=\"/\",status=\"201\"} 64033\nhttp_requests_total{method=\"POST\",path=\"/api/v1/users\",status=\"400\"} 98080\nhttp_requests_total{method=\"POST\",path=\"/api/health\",status=\"204\"} 39082\nhttp_requests_total{method=\"POST\",path=\"/api/v1/orders\",status=\"500\"} 67572\nhttp_requests_total{method=\"POST\",path=\"/\",status=\"201\"} 72127\nhttp_requests_total{method=\"PUT\",path=\"/api/v1/users\",status=\"502\"} 53696\nhttp_requests_total{method=\"PUT\",path=\"/api/health\",status=\"201\"} 36322\nhttp_requests_total{method=\"PUT\",path=\"/api/v1/orders\",status=\"404\"} 14065\nhttp_requests_total{method=\"PUT\",path=\"/\",status=\"204\"} 4780\n\n# HELP http_request_duration_seconds HTTP request latency in seconds.\n# TYPE http_request_duration_seconds histogram\nhttp_request_duration_seconds_bucket{le=\"0.005\"} 2603\nhttp_request_duration_seconds_bucket{le=\"0.01\"} 3363\nhttp_request_duration_seconds_bucket{le=\"0.025\"} 3655\nhttp_request_duration_seconds_bucket{le=\"0.05\"} 4328\nhttp_request_duration_seconds_bucket{le=\"0.1\"} 8945\nhttp_request_duration_seconds_bucket{le=\"0.25\"} 10663\nhttp_request_duration_seconds_bucket{le=\"0.5\"} 14976\nhttp_request_duration_seconds_bucket{le=\"1\"} 21299\nhttp_request_duration_seconds_bucket{le=\"2.5\"} 23820\nhttp_request_duration_seconds_bucket{le=\"5\"} 24190\nhttp_request_duration_seconds_bucket{le=\"10\"} 26939\nhttp_request_duration_seconds_bucket{le=\"+Inf\"} 26939\nhttp_request_duration_seconds_sum 17565.697\nhttp_request_duration_seconds_count 26939\n", "format": "prometheus", "metric_families": ["process_cpu_seconds_total", "process_resident_memory_bytes", "process_virtual_memory_bytes", "process_open_fds", "process_start_time_seconds", "http_requests_total", "http_request_duration_seconds"], "total_samples": 35}

Validation Rules

Other Languages