Hello everyone, I just registered on the Grafana website because I’m interested in testing it for future projects. At the moment, I’m using the free plan just to run some tests. My intention is to send measurements from an Arduino Nano ESP32. As a data source, I’m trying to use Prometheus, but it seems that the measurements (currently just random values) are not being sent
#include <WiFi.h>
#include <HTTPClient.h>
// Configurazioni WiFi
#define WIFI_SSID "xxx"
#define WIFI_PASSWORD "xxxx"
// Configurazioni Prometheus Pushgateway
#define PUSHGATEWAY_URL xxxxxx"
#define API_KEY "xxxxxx"
void setup() {
// Inizializza la comunicazione seriale
Serial.begin(9600);
while (!Serial);
// Connessione WiFi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connessione al WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" Connesso!");
}
void loop() {
// Genera 5 valori casuali tra 0 e 10
int valore1 = random(0, 11);
int valore2 = random(0, 11);
int valore3 = random(0, 11);
int valore4 = random(0, 11);
int valore5 = random(0, 11);
// Crea il payload per Prometheus
String payload = "";
payload += "# TYPE valore1 gauge\n";
payload += "valore1 " + String(valore1) + "\n";
payload += "# TYPE valore2 gauge\n";
payload += "valore2 " + String(valore2) + "\n";
payload += "# TYPE valore3 gauge\n";
payload += "valore3 " + String(valore3) + "\n";
payload += "# TYPE valore4 gauge\n";
payload += "valore4 " + String(valore4) + "\n";
payload += "# TYPE valore5 gauge\n";
payload += "valore5 " + String(valore5) + "\n";
// Invia i dati al Pushgateway
if (sendToPrometheus(payload)) {
Serial.println("Dati inviati con successo!");
} else {
Serial.println("Errore nell'invio dei dati.");
}
// Attendi 5 secondi prima di inviare nuovi dati
delay(5000);
}
bool sendToPrometheus(String payload) {
WiFiClient client;
HTTPClient http;
// Configura la richiesta HTTP
http.begin(client, PUSHGATEWAY_URL);
http.addHeader("Content-Type", "text/plain");
http.addHeader("Authorization", "Bearer " + String(API_KEY));
// Invia la richiesta POST
int httpResponseCode = http.POST(payload);
// Stampa la risposta del server (per debug)
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Risposta del server: " + response);
} else {
Serial.print("Errore HTTP: ");
Serial.println(httpResponseCode);
}
// Chiudi la connessione
http.end();
// Verifica la risposta
return (httpResponseCode == 202);
}
I don’t quite understand what parameters to enter in the Arduino code. It always returns 'Error in sending data. HTTP Error: -1"
I ask for your forgiveness, but I’m just getting started
Thank you all, have a great day