Hello folks,
I am trying to send my k6 metrics to prometheus for that i have done the following thing.
i have installed prometheus and it is up and running at port 9090.
after that i am using command “k6 run -o experimental-prometheus-rw sampleScript.js”
I am getting following error : ERRO[0003] Failed to send the time series data to the endpoint error=“got status code: 404 instead expected a 2xx successful status code” output=“Prometheus remote write”
Do i have to make any configuration in prometheus , or m i missing somethings , please help!!
Which will return remote write receiver needs to be enabled with --enable-feature=remote-write-receiver. Note that the flag has been deprecated and is now --web.enable-remote-write-receiver.
If this is the case, running curl -v -X POST http://localhost:9090/api/v1/write, in verbose, you would also see that your Prometheus is returning a HTTP/1.1 404 Not Found. Same as the errors you see got status code: 404.
Does this page in the docs help: Prometheus remote write? To enable the remote write flag in Prometheus you have to follow the Prometheus docs. Or are you stuck at another step?
Where do we enable the remote write flag. I have hosted prometheus server locally on localhost:9090 and i am trying to send a custom k6 metrics to the server.
import { Counter } from 'k6/metrics';
import http from 'k6/http';
const myCounter = new Counter('my_counter');
export default function () {
myCounter.add(1);
myCounter.add(2, { tag1: 'myValue', tag2: 'myValue2' });
}
export function handleSummary(data) {
console.log('Preparing the end-of-test summary...');
const metricsPayload = `
# TYPE my_counter counter
# HELP my_counter My Counter
my_counter{label1="value1", label2="value2"} ${data.metrics.my_counter.values.count}
`;
const url = 'http://localhost:9090/api/v1/writex';
const params = {
headers: { 'Content-Type': 'text/plain' },
body: metricsPayload,
};
const response = http.post(url, params);
if (response.status === 200) {
console.log('Metrics sent successfully');
} else {
console.error('Failed to send metrics:', response.body);
}
}
Is there any issue with the above code?
on running the k6 script im getting the error - ERRO[0000] Failed to send metrics: remote write receiver needs to be enabled with --web.enable-remote-write-receiver source=console
Apologies for the late reply. This is in the realm of Prometheus configuration, so you would have to see how to add this to your Prometheus configuration. Not on the k6 side.
If you don’t manage the Prometheus instance, ask for help in following the Prometheus docs for your concrete installation: Feature flags | Prometheus