The prometheus_metrics function within the mock-jutsu library serves as a sophisticated generator for simulating real-world observability telemetry. By producing high-fidelity mock data that adheres strictly to the Prometheus text exposition format, developers can simulate complex infrastructure and application states without the need to deploy actual exporters. This function is particularly useful for engineers who need to validate monitoring pipelines, as it generates comprehensive output including process CPU usage, memory consumption, and detailed Go runtime metrics, ensuring that your test data reflects the nuances of a production environment.
When invoking prometheus_metrics, the library follows standard prometheus-compatible formatting conventions for various metric types. It includes essential labels and values for HTTP request counters, categorised by method, path, and status code. Furthermore, the function correctly handles histogram metrics, ensuring that monotonic buckets are logically consistent and that the +Inf bucket aligns perfectly with the total count. This meticulous adherence to industry standards allows mock-jutsu to integrate seamlessly with existing scrapers, Grafana dashboards, and Alertmanager configurations during the development and staging lifecycles.
For performance testers and DevOps engineers, the ability to generate these metrics via the CLI, Python API, or even a JMeter plugin provides immense flexibility. Common testing scenarios include stress-testing a Prometheus server’s ingestion rate or verifying that specific PromQL queries trigger the correct alerts under simulated failure conditions. By leveraging the prometheus_metrics function, teams can avoid the overhead of spinning up multiple microservices just to populate a dashboard. Instead, they can generate dynamic, structured mock data that mimics various load profiles and failure states, significantly accelerating the feedback loop for observability-driven development.
Ultimately, mock-jutsu empowers developers to treat observability as a first-class citizen in their automated testing suites. Whether you are automating integration tests or performing manual UI validation for a new monitoring tool, the prometheus_metrics function provides reliable, repeatable, and customisable output. By removing the dependency on live system metrics, it ensures that your CI/CD pipelines remain hermetic and predictable, allowing you to focus on building robust monitoring solutions with confidence and precision.
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 sqlfrom mockjutsu import jutsujutsu.generate('prometheus_metrics')jutsu.bulk('prometheus_metrics', count=10)jutsu.template(['prometheus_metrics'], count=5)${__mockjutsu_prometheus(prometheus_metrics)}# JMeter Function: __mockjutsu_prometheus# Parameter 1: prometheus_metrics# Parameter 2: (not required for this function)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 19256.52\n# HELP process_resident_memory_bytes Resident memory size in bytes.\n# TYPE process_resident_memory_bytes gauge\nprocess_resident_memory_bytes 1535480489\n# HELP process_virtual_memory_bytes Virtual memory size in bytes.\n# TYPE process_virtual_memory_bytes gauge\nprocess_virtual_memory_bytes 1994868348\n# HELP process_open_fds Number of open file descriptors.\n# TYPE process_open_fds gauge\nprocess_open_fds 394\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 1780208423.528\n\n# HELP http_requests_total Total number of HTTP requests received.\n# TYPE http_requests_total counter\nhttp_requests_total{method=\"PUT\",path=\"/api/v1/auth/token\",status=\"204\"} 27277\nhttp_requests_total{method=\"PUT\",path=\"/api/v1/users\",status=\"200\"} 20411\nhttp_requests_total{method=\"PUT\",path=\"/api/health\",status=\"200\"} 96071\nhttp_requests_total{method=\"PUT\",path=\"/api/v1/data\",status=\"204\"} 89034\nhttp_requests_total{method=\"DELETE\",path=\"/api/v1/auth/token\",status=\"500\"} 71439\nhttp_requests_total{method=\"DELETE\",path=\"/api/v1/users\",status=\"400\"} 3678\nhttp_requests_total{method=\"DELETE\",path=\"/api/health\",status=\"204\"} 57961\nhttp_requests_total{method=\"DELETE\",path=\"/api/v1/data\",status=\"200\"} 95831\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\"} 1155\nhttp_request_duration_seconds_bucket{le=\"0.01\"} 1179\nhttp_request_duration_seconds_bucket{le=\"0.025\"} 1742\nhttp_request_duration_seconds_bucket{le=\"0.05\"} 1878\nhttp_request_duration_seconds_bucket{le=\"0.1\"} 2051\nhttp_request_duration_seconds_bucket{le=\"0.25\"} 2428\nhttp_request_duration_seconds_bucket{le=\"0.5\"} 2857\nhttp_request_duration_seconds_bucket{le=\"1\"} 4669\nhttp_request_duration_seconds_bucket{le=\"2.5\"} 4968\nhttp_request_duration_seconds_bucket{le=\"5\"} 5075\nhttp_request_duration_seconds_bucket{le=\"10\"} 5359\nhttp_request_duration_seconds_bucket{le=\"+Inf\"} 5359\nhttp_request_duration_seconds_sum 584.774\nhttp_request_duration_seconds_count 5359\n\n# HELP go_goroutines Number of goroutines that currently exist.\n# TYPE go_goroutines gauge\ngo_goroutines 73\n# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.\n# TYPE go_memstats_alloc_bytes gauge\ngo_memstats_alloc_bytes 209941093\n# HELP go_gc_duration_seconds A summary of GC invocation durations.\n# TYPE go_gc_duration_seconds summary\ngo_gc_duration_seconds{quantile=\"0\"} 1.260884e-05\ngo_gc_duration_seconds{quantile=\"0.25\"} 3.863051e-04\ngo_gc_duration_seconds{quantile=\"0.5\"} 6.068565e-04\ngo_gc_duration_seconds{quantile=\"0.75\"} 7.583413e-04\ngo_gc_duration_seconds{quantile=\"1\"} 9.186898e-04\ngo_gc_duration_seconds_sum 0.3269\ngo_gc_duration_seconds_count 1857\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", "go_goroutines", "go_memstats_alloc_bytes", "go_gc_duration_seconds"], "total_samples": 36}Validation Rules
- Generated following real format specifications
- All values are fully synthetic
- For development, testing, and demonstration only