{"size": 933, "ext": "js", "max_stars_repo_path": "src/grafana_live.js", "max_stars_repo_name": "firekccz3/grafanao", "max_stars_repo_stars_event_min_datetime": "2017-02-22T11:48:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-06T18:45:38.000Z", "max_issues_repo_path": "src/grafana_live.js", "max_issues_repo_name": "firekccz3/grafanao", "max_issues_repo_issues_event_min_datetime": "2017-09-10T21:26:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-15T21:32:52.000Z", "max_forks_repo_path": "src/grafana_live.js", "max_forks_repo_name": "firekccz3/grafanao", "max_forks_repo_forks_event_min_datetime": "2016-07-13T03:46:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-11T11:10:08.000Z"}
{"max_stars_count": 10, "max_issues_count": 10, "max_forks_count": 7, "avg_line_length": 21.2045454545, "max_line_length": 67, "alphanum_fraction": 0.5455519829}
var _ = require('lodash');

function live() {
  var restify = require('restify');
  var client = restify.createJsonClient({url: 'http://localhost'});
  client.basicAuth('admin', 'admin');
  var data = {};

  console.log('Starting Grafana Live Fake Data Feeder');

  function randomWalk(name, tags, start, variation) {
    if (!data[name]) {
      data[name] = start;
    }

    data[name] += (Math.random() * variation) - (variation / 2);

    client.post('/grafana/api/streams/push', {
      "stream": "fake." + name,
      "series": [
        {
          "name": name,
          "delta": true,
          "datapoints": [[new Date().getTime(), data[name]]],
        }
      ]
    }, function(err, res) {
      if (err) {
        console.log("writing grafana live error: " + err);
      }
    });
  }

  setInterval(function() {
    randomWalk('payments');
    randomWalk('logins');
  }, 2000);

}

module.exports = {
  live: live
};
