Chronograf: Difference between revisions

From air
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 60: Line 60:
</pre>
</pre>



==Arret de Chronograf==


==Utilisation en continu==
Exécuter les 2 scripts Node.js suivants dans 2 terminaux.

<pre>
npm install mqtt
npm install influxdb
</pre>


<pre>
node mqtt2influxdb.js
</pre>

<pre>
node mqttpub.js
</pre>



mqtt2influxdb.js
<pre>
// MQTT to InfluxDB bridge
// (c) Didier DONSEZ, 2015-2016

// Tested with InfluxDB v0.9

var mqtt = require('mqtt')
var influx = require('influx');

var mqtt_url = 'mqtt://test.mosquitto.org';
var topic = 'test/influxdb';


var dbhost = 'localhost';
var database = 'xnet';
var username = 'root';
var password = 'root';


var seriesName = 'cluster';
var tags = { "host":"serverA","region":"us_west"};


var dbInflux = influx( {
// single-host configuration
host : dbhost,
port : 8086, // optional, default 8086
protocol : 'http', // optional, default 'http'
username : username,
password : password,
database : database
})

client = mqtt.connect(mqtt_url);

client.on('connect', function () {

console.log("Connected to " + mqtt_url);

client.subscribe(topic).on('message', function (topic, message) {
var date=new Date();
console.log(date.toISOString()+" <-- "+ message);
var values = JSON.parse(message);
values.time = date;
dbInflux.writePoint(seriesName, values, tags, function(err, response) { if(err) throw err; })
});

// TODO add other event handlers here

});

console.log("MQTT to InfluxDB bridge is started");
</pre>

mqttpub.js
<pre>
var mqtt = require('mqtt')

var mqtt_url = 'mqtt://test.mosquitto.org';
var topic = 'test/influxdb';
var publishing_period = 1000; // in ms

client = mqtt.connect(mqtt_url);

//client.subscribe(topic);

var mem = Math.random();
var disk = Math.random();
var cpu;

function publish() {

mem = mem+(Math.random()/10)-0.05;
if(mem<0) { mem=0 };
if(mem>1) { mem=1 };

disk = disk+(Math.random()/20)-0.025;
if(disk<0) { disk=0 };
if(disk>1) { disk=1 };

cpu = Math.random();


var message= {
cpu: cpu,
mem: mem,
disk: disk,
};

client.publish(topic, JSON.stringify(message));
console.log(new Date().toISOString()+" --> "+ JSON.stringify(message));
setTimeout(publish, publishing_period);
}

publish();

console.log("MQTT publishing is started");
</pre>

=Utilisation avancée avec [[Telegraf]]=
TODO

=Arret de Chronograf=
<pre>
<pre>
sudo service chronograf stop
sudo service chronograf stop

Latest revision as of 10:48, 4 February 2016

Définition d'un graphique dans Chronograf
Affichage d'un dashboard dans Chronograf

Interface de visualisation de séries temporelles stockées dans une base de données InfluxDB. Permet de créer des dashboards à partir des graphiques définis.

https://influxdata.com/time-series-platform/chronograf/

Installation

Il faut préalablement installer InfluxDB.


wget https://s3.amazonaws.com/get.influxdb.org/chronograf/chronograf_0.10.0-rc2_amd64.deb
sudo dpkg -i chronograf_0.10.0-rc2_amd64.deb

Si besoin, Configurer Chronograf en éditant le fichier /opt/etc/chronograf.toml

Démarrer Chronograf

sudo service chronograf start
ps wwwax | grep chronograf

Remarque: Chronograf stocke ses informations dans ~/chronograf.db

Utilisation

Naviguer sur https://localhost:10000/

  1. Ajoutant des entrées à la série cluster depuis le shell d’influx
CREATE DATABASE mycluster
SHOW DATABASES
USE mycluster
SHOW SERVERS
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.67,disk=0.20
INSERT cluster,host=serverB,region=us_west cpu=0.50,mem=0.99,disk=0.30
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.60,disk=0.20
INSERT cluster,host=serverB,region=us_west cpu=0.53,mem=0.97,disk=0.29
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.70,disk=0.21
INSERT cluster,host=serverB,region=us_west cpu=0.50,mem=0.80,disk=0.22
SELECT * FROM cluster
SELECT * FROM cluster WHERE host='serverA'
  1. Ajouter un graphique avec la requête SELECT * FROM cluster WHERE host='serverA'
  2. Ajouter un graphique avec la requête SELECT cpu FROM cluster WHERE host='serverA'
  3. Ajouter un graphique avec la requête SELECT cpu FROM cluster WHERE host='serverB'
  4. Ajouter un dashboard
  5. Ajouter les graphiques existants au dashboard
  6. Tester l’affichage dynamique des graphiques en ajoutant des entrées à la série cluster depuis le shell d’influx
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.30,disk=0.10
INSERT cluster,host=serverB,region=us_west cpu=0.50,mem=0.95,disk=0.50
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.60,disk=0.20
INSERT cluster,host=serverB,region=us_west cpu=0.53,mem=0.97,disk=0.19
INSERT cluster,host=serverA,region=us_west cpu=0.64,mem=0.60,disk=0.21
INSERT cluster,host=serverB,region=us_west cpu=0.40,mem=0.80,disk=0.4



Utilisation en continu

Exécuter les 2 scripts Node.js suivants dans 2 terminaux.

npm install mqtt
npm install influxdb


node mqtt2influxdb.js
node mqttpub.js


mqtt2influxdb.js

// MQTT to InfluxDB bridge
// (c) Didier DONSEZ, 2015-2016

// Tested with InfluxDB v0.9

var mqtt = require('mqtt')
var influx = require('influx');

var mqtt_url = 'mqtt://test.mosquitto.org';
var topic  = 'test/influxdb';


var dbhost = 'localhost';
var database = 'xnet';
var username = 'root';
var password = 'root';


var seriesName = 'cluster';
var tags = { "host":"serverA","region":"us_west"};


var dbInflux = influx( {
  // single-host configuration
  host : dbhost,
  port : 8086, // optional, default 8086
  protocol : 'http', // optional, default 'http'
  username : username,
  password : password,
  database : database
})

client = mqtt.connect(mqtt_url);

client.on('connect', function () {

  console.log("Connected to " + mqtt_url);

  client.subscribe(topic).on('message', function (topic, message) {
  	var date=new Date();
    console.log(date.toISOString()+" <-- "+ message);
    var values = JSON.parse(message);
    values.time = date;
	dbInflux.writePoint(seriesName, values, tags, function(err, response) { if(err) throw err; })
  });

  // TODO add other event handlers here

});

console.log("MQTT to InfluxDB bridge is started");

mqttpub.js

var mqtt = require('mqtt')

var mqtt_url = 'mqtt://test.mosquitto.org';
var topic  = 'test/influxdb';
var publishing_period  = 1000; // in ms

client = mqtt.connect(mqtt_url);

//client.subscribe(topic);

var mem = Math.random();
var disk = Math.random();
var cpu;

function publish() {

	mem = mem+(Math.random()/10)-0.05;
	if(mem<0) { mem=0 };
	if(mem>1) { mem=1 };

	disk = disk+(Math.random()/20)-0.025;
	if(disk<0) { disk=0 };
	if(disk>1) { disk=1 };

    cpu = Math.random();


    var message= {
    		cpu: cpu,
    		mem: mem,
    		disk: disk,
    	};

    client.publish(topic, JSON.stringify(message));
    console.log(new Date().toISOString()+" --> "+ JSON.stringify(message));
    setTimeout(publish, publishing_period);
}

publish();

console.log("MQTT publishing is started");

Utilisation avancée avec Telegraf

TODO

Arret de Chronograf

sudo service chronograf stop