Settings: Difference between revisions

Jump to navigation Jump to search
1,642 bytes removed ,  23 April 2020
Line 311: Line 311:
=== Statistics Export ===
=== Statistics Export ===


The Statistics Export allows querying the API of the Allegro Network Multimeter and transmit JSON results to a remote server via HTTP POST requests. The API path can be determined by using a debug console of the browser on any of the modules of the Allegro Network Multimeter.
See [[Statistics Export via POST]] for details about exporting the measurement data via HTTP POST requests.
 
Example:
 
* Interval: '''60'''
* Internal URL Path: '''/API/stats/interfaces'''
* External POST target: '''http://10.0.0.1:3000/interface-stats-for-mm-1234'''
 
This will generate a '''POST /interface-stats-for-mm-1234''' request to '''10.0.0.1''' every minute and send the interface statistics of the multimeter.
 
==== Sample Node.js server ====
 
The following script is a basic '''Node.js''' server (with minimal error handling) which reads all POST requests and stores them to a file:
 
const http = require('http');
const fs = require('fs');
const listenAddress = '0.0.0.0';
const port = 3000;
let fileCount = 1;
const server = http.createServer((req, res) => {
  if (req.method != 'POST') {
        res.statusCode = 405;
        res.end();
        return;
  }
  let id = fileCount++;
  let outputFilename = `${req.url.substring(1).replace(/\//g, '_')}_${id}.json`;
  console.log(`${id}: ${req.method} ${req.url} => ${outputFilename}`);
  let data = [];
  req.on('data', chunk => data.push(chunk));
  req.on('end', () => {
        fs.writeFile(outputFilename, data, (err) => {
            if (err != null) {
                  console.log(err);
                  res.statusCode = 500;
            } else {
                  res.statusCode = 200;
            }
            res.end();
        });
  });
});
server.listen(port, listenAddress, () => {
  console.log(`Server running at http://${listenAddress}:${port}/`);
});


=== SSH port forwarding ===
=== SSH port forwarding ===
547

edits

Navigation menu