node.jsgrafanainfluxdb-2influxqlflux-influxdb

Sum of last value InfluxDB


I am trying to make a graph for the availability of machines.

For example, I want to know that at 4pm, 10 machines were used, and at 7pm, nothing was used.

To do so, I started sending points to InfluxDB, like this:

fetchMachines(token).then((machines) => {
    
    let writeClient = client.getWriteApi(org, bucket, 'ns');

    for (let machine of machines) {
        let point = new Point('machines_a_laver')
            .tag('machine_id', machine.number.toString() + ' ' + machine.room)
            .stringField('status', machine.state);
        
        writeClient.writePoint(point);
    }

    writeClient.flush().then(() => {
        console.log('FINISHED')
    });

});

Status can be ACTIVATED or DEACTIVATED.

How can I write a query that:

Thank you.


Solution