[Feature] InfluxDB integration
General
- [x] My feature does not exist in the latest version of MySpeed.
- [x] I have checked that my feature has not been suggested by anyone else.
Your Idea
I suggest adding an integration for pushing results to InfluxDB. This would resolve issues such as #1029 by offloading the storage to an external database. This would also provide users a better experience when analyzing data, since tools such as Grafan have built in support for InfluxDB.
Isn't it possible to use Prometheus to scrape and load it into influxdb via prometheus source?
But you can also use prometheus<-grafana directly.
Vote for it!
Promethues isnt Influx. Thats no way if it is wanted to become a InfluxDB Support.
Done this, add "influxdb.js" into /opt/myspeed/server/integrations
Insert this:
const os = require('os');
const INFLUX_URL = 'http://yourserverhere:8086'; // YOUR INFLUX DB SERVER
const INFLUX_ORG = 'YOURORGANISTATION'; // YOUR ORGANISTATION
const INFLUX_BUCKET = 'YOURBUCKET'; // YOUR BUCKET
const INFLUX_TOKEN = 'YOURTOKENHERE'; // YOUR TOKEN HERE
const measurement = 'speedtests'; // YOUR MEASUREMENT
const fetch = global.fetch;
module.exports = (registerEvent) => {
registerEvent('testFinished', async (integration, data, triggerActivity) => {
const tags = `host=${os.hostname()}`;
const fields = [
`download=${data.download}`,
`upload=${data.upload}`,
`ping=${data.ping}`,
`jitter=${data.jitter || 0}`,
`packetLoss=${data.packetLoss || 0}`
].join(',');
const timestamp = Math.floor(new Date(data.timestamp || Date.now()).getTime() / 1000);
const line = `${measurement},${tags} ${fields} ${timestamp}`;
const url = `${INFLUX_URL}/api/v2/write?org=${INFLUX_ORG}&bucket=${INFLUX_BUCKET}&precision=s`;
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Token ${INFLUX_TOKEN}`,
'Content-Type': 'text/plain'
},
body: line
});
if (!response.ok) {
console.error('[MySpeed][InfluxDB] Write Error:', await response.text());
}
} catch (err) {
console.error('[MySpeed][InfluxDB] Fetch Exception:', err);
}
triggerActivity();
});
// --- Jetzt: EIN ECHTES, REQUIRED FELD ---
return {
icon: "fa-solid fa-database",
fields: [
{
name: "aktiv",
type: "boolean",
label: "Integration aktivieren",
required: true,
default: true
}
]
};
}
reboot Container/VM/Docker or whatever
goto Webui -> Integrations search your influx Integration Hit "add" CHANGE THE NAME OF THE INSTACE Hit Safe Button.
Done.
P.S. for Devs: Your Code is very wired.. i spent 3 Hours to get a working Integration.
@Lucifor1976 you should open a PR with this change