Ejemplo n.º 1
1
 public function __construct($sHost = "localhost", $iPort = 8086, $sUser = '******', $sPassword = '******', $bCheckExistence = true)
 {
     $client = new crodas\InfluxPHP\Client($sHost, $iPort, $sUser, $sPassword);
     if ($bCheckExistence) {
         $aDBs = $client->getDatabases();
         if (isset($aDBs)) {
             foreach ($aDBs as $oDB) {
                 if ($oDB->getName() == 'iws') {
                     print "iws database exists - skipping creation..\n";
                     $this->db = $oDB;
                     return;
                 }
             }
         }
         print "creating missing database for iws ts data..\n";
         $this->db = $client->createDatabase("iws");
         $client->grantPrivilege(crodas\InfluxPHP\Client::PRIV_ALL, "iws", "iws");
     } else {
         $this->db = $client->getDatabase("iws");
     }
 }
Ejemplo n.º 2
0
<?php

require __DIR__ . "/../vendor/autoload.php";
$client = new \crodas\InfluxPHP\Client();
$dbs = $client->getDatabases();
if ($dbs) {
    foreach ((array) $dbs as $db) {
        if (preg_match("/^test_/", $db->getName())) {
            $db->drop();
        }
    }
}
Ejemplo n.º 3
0
<?php

require __DIR__ . '/vendor/autoload.php';
require 'functions.php';
// Use serial number for ID
$addressDataHTML = getPage("http://192.168.100.1/cmAddressData.htm");
$dom = new DOMDocument();
@$dom->loadHTML($addressDataHTML);
$xpath = new DomXPath($dom);
$serialNumber = $xpath->query('//table/tbody/tr/td')->item(1)->nodeValue;
while (true) {
    $signalDataHTML = getPage("http://192.168.100.1/cmSignalData.htm");
    $data = parseSignalData($signalDataHTML);
    $client = new \crodas\InfluxPHP\Client("10.59.52.10", 8086, "root", "root");
    $db = $client->createDatabase("graphite");
    foreach ($data as $measurementSet) {
        $preparedMeasurements = denormalizeSourceData($measurementSet);
        foreach ($preparedMeasurements['fields'] as $preparedMeasurement) {
            $name = $preparedMeasurements['name'];
            $preparedForInflux = denormalizeMeasurement($name, $serialNumber, $preparedMeasurement);
            echo json_encode($preparedForInflux) . "\n";
            $db->insert($name, $preparedForInflux);
        }
    }
    sleep(30);
}