k6 prometheus output extension

Overview

xk6-prometheus

A k6 extension implements Prometheus HTTP exporter as k6 output extension.

Using xk6-prometheus output extension you can collect metrics from long running k6 process with Prometheus. All custom k6 metrics (Counter,Gauge,Rate,Trend) and build-in metrics will be accessible as appropiate Prometheus metrics on a given HTTP port in Prometheus importable text format.

Built for k6 using xk6.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
$ go install github.com/k6io/xk6/cmd/[email protected]
  1. Build the binary:
$ xk6 build --with github.com/szkiba/[email protected]

You should use at least v0.31.0 version because xk6-prometheus extension registers itself as output extension. This feature introduced in the v0.31.0 version of k6.

Usage

With defaults

Without parameters the Prometheus HTTP exporter will accessible on port 5656.

$ ./k6 run -d 1m --out prometheus script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: script.js
     output: prometheus (:5656)

  scenarios: (100.00%) 1 scenario, 1 max VUs, 1m30s max duration (incl. graceful stop):
           * default: 1 looping VUs for 1m0s (gracefulStop: 30s)


running (1m01.0s), 0/1 VUs, 54 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  1m0s

     data_received..................: 611 kB 10 kB/s
     data_sent......................: 4.1 kB 67 B/s
     http_req_blocked...............: avg=3.37ms   min=2.86µs   med=3.82µs   max=181.96ms p(90)=11.15µs  p(95)=13.52µs 
     http_req_connecting............: avg=2.19ms   min=0s       med=0s       max=118.34ms p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=125.14ms min=118.99ms med=120.68ms max=237.66ms p(90)=121.45ms p(95)=124.07ms
       { expected_response:true }...: avg=125.14ms min=118.99ms med=120.68ms max=237.66ms p(90)=121.45ms p(95)=124.07ms
     http_req_failed................: 0.00%  ✓ 0   ✗ 54 
     http_req_receiving.............: avg=5.1ms    min=85.32µs  med=792.2µs  max=118.29ms p(90)=860.41µs p(95)=903.71µs
     http_req_sending...............: avg=20.68µs  min=12.53µs  med=16.69µs  max=75.97µs  p(90)=29.39µs  p(95)=37.87µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=120.01ms min=118.17ms med=119.78ms max=127.48ms p(90)=120.6ms  p(95)=120.71ms
     http_reqs......................: 54     0.885451/s
     iteration_duration.............: avg=1.12s    min=1.11s    med=1.12s    max=1.3s     p(90)=1.12s    p(95)=1.16s   
     iterations.....................: 54     0.885451/s
     vus............................: 1      min=1 max=1
     vus_max........................: 1      min=1 max=1

Parameters

The output extension accept parameters in a standard query string format:

k6 run --out 'prometheus=param1=value1&param2=value2&param3=value3'

Note apostrophe (') characters around the --out parameter! You should use it for escape & characters from shell (or use backslash before & characters).

The following paremeters are recognized:

parameter description
namespace Prometheus namespace for exported metrics (default: "", empty)
subsystem Prometheus subsystem for exported metrics (default: "", empty)
host Hostname or IP address for HTTP endpoint (default: "", empty, listen on all interfaces)
port TCP port for HTTP endoint (default: 5656)

It is recommended to use k6 as either namespace or subsystem to prefix exported metrics names with k6_ string.

Sample HTTP response

Here is the relevant part of the metrics HTTP response:

# HELP k6_data_received The amount of received data
# TYPE k6_data_received counter
k6_data_received 600077
# HELP k6_data_sent The amount of data sent
# TYPE k6_data_sent counter
k6_data_sent 4028
# HELP k6_http_req_blocked Time spent blocked  before initiating the request
# TYPE k6_http_req_blocked summary
k6_http_req_blocked{quantile="0.5"} 0.003785
k6_http_req_blocked{quantile="0.9"} 0.011186
k6_http_req_blocked{quantile="0.95"} 0.014801
k6_http_req_blocked{quantile="1"} 181.961168
k6_http_req_blocked_sum 182.2282190000001
k6_http_req_blocked_count 54
# HELP k6_http_req_blocked_current Time spent blocked  before initiating the request (current)
# TYPE k6_http_req_blocked_current gauge
k6_http_req_blocked_current 0.004652
# HELP k6_http_req_connecting Time spent establishing TCP connection
# TYPE k6_http_req_connecting summary
k6_http_req_connecting{quantile="0.5"} 0
k6_http_req_connecting{quantile="0.9"} 0
k6_http_req_connecting{quantile="0.95"} 0
k6_http_req_connecting{quantile="1"} 118.345391
k6_http_req_connecting_sum 118.345391
k6_http_req_connecting_count 54
# HELP k6_http_req_connecting_current Time spent establishing TCP connection (current)
# TYPE k6_http_req_connecting_current gauge
k6_http_req_connecting_current 0
# HELP k6_http_req_duration Total time for the request
# TYPE k6_http_req_duration summary
k6_http_req_duration{quantile="0.5"} 120.68482
k6_http_req_duration{quantile="0.9"} 121.461453
k6_http_req_duration{quantile="0.95"} 128.291489
k6_http_req_duration{quantile="1"} 237.666802
k6_http_req_duration_sum 6757.691293999998
k6_http_req_duration_count 54
# HELP k6_http_req_duration_current Total time for the request (current)
# TYPE k6_http_req_duration_current gauge
k6_http_req_duration_current 120.751952
# HELP k6_http_req_failed The rate of failed requests
# TYPE k6_http_req_failed histogram
k6_http_req_failed_bucket{le="0"} 54
k6_http_req_failed_bucket{le="+Inf"} 54
k6_http_req_failed_sum 0
k6_http_req_failed_count 54
# HELP k6_http_req_receiving Time spent receiving response data
# TYPE k6_http_req_receiving summary
k6_http_req_receiving{quantile="0.5"} 0.79092
k6_http_req_receiving{quantile="0.9"} 0.862976
k6_http_req_receiving{quantile="0.95"} 0.973895
k6_http_req_receiving{quantile="1"} 118.292546
k6_http_req_receiving_sum 275.923961
k6_http_req_receiving_count 54
# HELP k6_http_req_receiving_current Time spent receiving response data (current)
# TYPE k6_http_req_receiving_current gauge
k6_http_req_receiving_current 0.706994
# HELP k6_http_req_sending Time spent sending data
# TYPE k6_http_req_sending summary
k6_http_req_sending{quantile="0.5"} 0.016638
k6_http_req_sending{quantile="0.9"} 0.030783
k6_http_req_sending{quantile="0.95"} 0.041126
k6_http_req_sending{quantile="1"} 0.07597
k6_http_req_sending_sum 1.11689
k6_http_req_sending_count 54
# HELP k6_http_req_sending_current Time spent sending data (current)
# TYPE k6_http_req_sending_current gauge
k6_http_req_sending_current 0.018325
# HELP k6_http_req_tls_handshaking Time spent handshaking TLS session
# TYPE k6_http_req_tls_handshaking summary
k6_http_req_tls_handshaking{quantile="0.5"} 0
k6_http_req_tls_handshaking{quantile="0.9"} 0
k6_http_req_tls_handshaking{quantile="0.95"} 0
k6_http_req_tls_handshaking{quantile="1"} 0
k6_http_req_tls_handshaking_sum 0
k6_http_req_tls_handshaking_count 54
# HELP k6_http_req_tls_handshaking_current Time spent handshaking TLS session (current)
# TYPE k6_http_req_tls_handshaking_current gauge
k6_http_req_tls_handshaking_current 0
# HELP k6_http_req_waiting Time spent waiting for response
# TYPE k6_http_req_waiting summary
k6_http_req_waiting{quantile="0.5"} 119.771619
k6_http_req_waiting{quantile="0.9"} 120.604942
k6_http_req_waiting{quantile="0.95"} 120.858167
k6_http_req_waiting{quantile="1"} 127.48803
k6_http_req_waiting_sum 6480.650443
k6_http_req_waiting_count 54
# HELP k6_http_req_waiting_current Time spent waiting for response (current)
# TYPE k6_http_req_waiting_current gauge
k6_http_req_waiting_current 120.026633
# HELP k6_http_reqs How many HTTP requests has k6 generated, in total
# TYPE k6_http_reqs counter
k6_http_reqs 54
# HELP k6_iteration_duration The time it took to complete one full iteration
# TYPE k6_iteration_duration summary
k6_iteration_duration{quantile="0.5"} 1121.458258
k6_iteration_duration{quantile="0.9"} 1122.620529
k6_iteration_duration{quantile="0.95"} 1237.23951
k6_iteration_duration{quantile="1"} 1304.729788
k6_iteration_duration_sum 59861.31288699999
k6_iteration_duration_count 53
# HELP k6_iteration_duration_current The time it took to complete one full iteration (current)
# TYPE k6_iteration_duration_current gauge
k6_iteration_duration_current 1121.360347
# HELP k6_iterations The aggregate number of times the VUs in the test have executed
# TYPE k6_iterations counter
k6_iterations 53
# HELP k6_vus Current number of active virtual users
# TYPE k6_vus gauge
k6_vus 1
# HELP k6_vus_max Max possible number of virtual users
# TYPE k6_vus_max gauge
k6_vus_max 1
You might also like...
This is a K6 extension to be able to test using NATS protocol
This is a K6 extension to be able to test using NATS protocol

xk6-nats This is a k6 extension using the xk6 system, that allows to use NATS protocol. ❗ This is a proof of concept, isn't supported by the k6 team,

k6 extension to load test Apache Kafka with support for Avro messages and SASL Authentication

xk6-kafka This project is a k6 extension that can be used to load test Kafka, using a producer. Per each connection to Kafka, many messages can be sen

k6 extension supporting avro textual and binary representations

xk6-avro This extension wraps the goavro library into a k6 extension. You can build the extension using: xk6 build --with github.com/xvzf/xk6-avro Exa

GitHub CLI extension for reviewing Dependabot PRs.

gh-dependabot A GitHub CLI extension to quickly review and approve Dependabot PRs. Installation This extension is developed and tested against a minim

Aws-secretsmanager-caching-extension - Cache server for AWS Secrets Manager
Aws-secretsmanager-caching-extension - Cache server for AWS Secrets Manager

AWS Lambda Extension / Sidecar Container Cache Server The cache server is writte

A gh-cli extension for managing environments.

gh-environments A gh-cli extension for managing environments. Installation and Upgrades gh extension install chelnak/gh-environments gh extension upgr

Pg algorand - A Postgres DB extension with Algorand's utility functions

AlgoRand Postgres extension by AlgoNode About pg_algorand A set of utility funct

In this repository, the development of the gardener extension, which deploys the flux controllers automatically to shoot clusters, takes place.

Gardener Extension for Flux Project Gardener implements the automated management and operation of Kubernetes clusters as a service. Its main principle

A GitHub CLI extension that provides summary pull request metrics.

gh-metrics A gh extension that provides summary pull request metrics. Usage Metric definitions Influences Usage To install the extension use: $ gh ext

Comments
  • Error parsing the go.mod

    Error parsing the go.mod

    When following install instructions:

    hans.knecht:k6-runner/ (master✗) $ go install github.com/k6io/xk6/cmd/[email protected]                                                                                                                                                                                                 
    
    go: downloading github.com/k6io/xk6 v0.4.2
    go: downloading github.com/Masterminds/semver/v3 v3.1.0
    
    hans.knecht:k6-runner/ (master✗) $ xk6 build --with github.com/szkiba/[email protected]                                                                                                                                                                                      
    
    2021/08/23 13:16:29 [INFO] Temporary folder: /Users/hans.knecht/Documents/Repositories/universe/infra/k6-runner/buildenv_2021-08-23-1316.046709920
    2021/08/23 13:16:29 [INFO] Writing main module: /Users/hans.knecht/Documents/Repositories/universe/infra/k6-runner/buildenv_2021-08-23-1316.046709920/main.go
    2021/08/23 13:16:29 [INFO] Initializing Go module
    2021/08/23 13:16:29 [INFO] exec (timeout=10s): /usr/local/Cellar/go/1.16.5/libexec/bin/go mod init k6 
    go: creating new go.mod: module k6
    go: to add module requirements and sums:
            go mod tidy
    2021/08/23 13:16:29 [INFO] Pinning versions
    2021/08/23 13:16:29 [INFO] exec (timeout=0s): /usr/local/Cellar/go/1.16.5/libexec/bin/go mod edit -require go.k6.io/[email protected] 
    2021/08/23 13:16:29 [INFO] exec (timeout=0s): /usr/local/Cellar/go/1.16.5/libexec/bin/go mod edit -require github.com/szkiba/[email protected] 
    go: errors parsing go.mod:
    /Users/hans.knecht/Documents/Repositories/universe/infra/k6-runner/buildenv_2021-08-23-1316.046709920/go.mod:5: require go.k6.io/k6: version "latest" invalid: must be of the form v1.2.3
    2021/08/23 13:16:29 [INFO] Cleaning up temporary folder: /Users/hans.knecht/Documents/Repositories/universe/infra/k6-runner/buildenv_2021-08-23-1316.046709920
    2021/08/23 13:16:29 [FATAL] exit status 1
    

    This can be replicated with a minimalist dockerfile:

    # Build the k6 binary with the extension
    FROM golang:1.16.4-buster as builder
    
    RUN go install github.com/k6io/xk6/cmd/[email protected]
    RUN xk6 build --output /k6 --with github.com/szkiba/[email protected]
    

    I've also tried increasing the golang version to 1.16.7 (latest stable in that minor version). without and change.

    opened by KnechtionsCoding 0
  • Can we add scenarios and name labels to the output

    Can we add scenarios and name labels to the output

    Looking for additional labels to be added.

    Example:

    k6_http_req_duration{quantile="0.9",method="GET", scenario="test-1", status="200", name="addToCart"}
    
    opened by kmcrawford 0
  • updated to k6 v0.39.0

    updated to k6 v0.39.0

    To support latest k6 version (v0.39.0), package go.k6.io/k6/stats has been renamed to go.k6.io/k6/metrics.

    I also updated logrus and prometheus client dependencies to latest versions

    opened by phsym 1
  • collecting the metrics

    collecting the metrics

    hi,

    is it possiable to change the code so the image can push the metrics into the pushgetaway of the prometheus instead of the waiting to the prometheus to collect the metrics. the reason of this change is when you use this image with the k6-operator, the prometheus isn't fast enough to collect the metrics, meaning, when the job is completed, the prometheus woudn't be able to collect to metrics.

    opened by ranyhb 0
Owner
Iván Szkiba
I'm a software architect with hands on programming knowledge.
Iván Szkiba
Export Prometheus metrics from journald events using Prometheus Go client library

journald parser and Prometheus exporter Export Prometheus metrics from journald events using Prometheus Go client library. For demonstration purposes,

Mike Sgarbossa 0 Jan 3, 2022
kubequery is a Osquery extension that provides SQL based analytics for Kubernetes clusters

kubequery powered by Osquery kubequery is a Osquery extension that provides SQL based analytics for Kubernetes clusters kubequery will be packaged as

Uptycs Inc 83 Oct 25, 2022
Client extension for interacting with Kubernetes clusters from your k6 tests.

⚠️ This is a proof of concept As this is a proof of concept, it won't be supported by the k6 team. It may also break in the future as xk6 evolves. USE

k6 23 Nov 21, 2022
⚙️ A k6 extension for Tarantool

xk6-tarantool This is a k6 extension using the xk6 system. ❗ This is a proof of concept, isn't supported by the k6 team, and may break in the future.

Sergey Kononenko 7 Jan 20, 2022
Kubernetes OS Server - Kubernetes Extension API server exposing OS configuration like sysctl via Kubernetes API

KOSS is a Extension API Server which exposes OS properties and functionality using Kubernetes API, so it can be accessed using e.g. kubectl. At the moment this is highly experimental and only managing sysctl is supported. To make things actually usable, you must run KOSS binary as root on the machine you will be managing.

Mateusz Gozdek 3 May 19, 2021
General Pod Autoscaler(GPA) is a extension for K8s HPA, which can be used not only for serving, also for game.

Introduction General Pod Autoscaler(GPA) is a extension for K8s HPA, which can be used not only for serving, also for game. Features Compatible with a

Open Cloud-native Game-application Initiative 15 Aug 19, 2022
A plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension.

opa-lambda-extension-plugin A custom plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension. To learn more about how Lambda Ex

GoDaddy 24 Oct 11, 2022
PolarDB-X Operator is a Kubernetes extension that aims to create and manage PolarDB-X cluster on Kubernetes.

GalaxyKube -- PolarDB-X Operator PolarDB-X Operator is a Kubernetes extension that aims to create and manage PolarDB-X cluster on Kubernetes. It follo

null 63 Nov 3, 2022
k6 extension for InfluxDB v2

xk6-output-influxdb k6 extension for InfluxDB v2, it adds the support for the latest v2 version and the compatibility API for v1.8+. Why is this outpu

Grafana Labs 21 Nov 7, 2022
K6 extension that adds support for browser automation and end-to-end web testing using playwright-go

k6 extension that adds support for browser automation and end-to-end web testing using playwright-go

We Open Source Performance 13 Oct 14, 2022