mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
Adding Point class to handle Points
This commit is contained in:
@@ -92,6 +92,17 @@ class Database
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes points into INfluxdb
|
||||
* @param Point[] $points
|
||||
*/
|
||||
public function writePoints(array $points)
|
||||
{
|
||||
foreach ($points as $point) {
|
||||
$point->a();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RetentionPolicy $retentionPolicy
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Leaseweb\InfluxDB;
|
||||
|
||||
|
||||
class Point
|
||||
{
|
||||
private $measurement;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tags;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $fields;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $timestamp;
|
||||
|
||||
/**
|
||||
* @param $measurement
|
||||
* @param array $tags
|
||||
* @param array $fields
|
||||
* @param string $timestamp
|
||||
*/
|
||||
public function __construct($measurement, array $tags, array $fields, $timestamp = '')
|
||||
{
|
||||
$this->measurement = $measurement;
|
||||
$this->tags = $tags;
|
||||
$this->fields = $fields;
|
||||
$this->timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see: https://influxdb.com/docs/v0.9/concepts/reading_and_writing_data.html
|
||||
*
|
||||
* Should return this format
|
||||
* 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "";
|
||||
/*return sprintf(
|
||||
'%s,%s %s %s',
|
||||
$this->measurement,
|
||||
implode()
|
||||
);*/
|
||||
}
|
||||
|
||||
public function a(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Leaseweb\InfluxDB\Test;
|
||||
|
||||
use Leaseweb\InfluxDB\Client;
|
||||
use Leaseweb\InfluxDB\Database;
|
||||
use Leaseweb\InfluxDB\Point;
|
||||
|
||||
class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -30,13 +31,31 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->db = new Database('influx_test_db', $this->mockClient);
|
||||
|
||||
$this->dataToInsert = file_get_contents(dirname(__FILE__) . '/input.example.json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:
|
||||
*/
|
||||
public function testWrite()
|
||||
{
|
||||
$point1 = new Point(
|
||||
'cpu_load_short',
|
||||
array('host' =>'server01', 'region'=>'us-west'),
|
||||
array('value' => 0.64),
|
||||
'myTime'
|
||||
);
|
||||
|
||||
$point2 = new Point(
|
||||
'cpu_load_short',
|
||||
array('host' =>'server01', 'region'=>'us-west'),
|
||||
array('value' => 0.84),
|
||||
'myTime'
|
||||
);
|
||||
|
||||
$this->db->writePoints(array($point1, $point2));
|
||||
|
||||
$this->assertTrue(
|
||||
'mockClient'
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: dmartinez
|
||||
* Date: 18-6-15
|
||||
* Time: 17:39
|
||||
*/
|
||||
|
||||
namespace Leaseweb\InfluxDB\Test;
|
||||
|
||||
|
||||
use Leaseweb\InfluxDB\Point;
|
||||
|
||||
class PointTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testPointStringRepresentation()
|
||||
{
|
||||
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 mytime';
|
||||
|
||||
$point = new Point(
|
||||
'cpu_load_short',
|
||||
array('host' =>'server01', 'region'=>'us-west'),
|
||||
array('value' => 0.64),
|
||||
'myTime'
|
||||
);
|
||||
|
||||
|
||||
$this->assertEquals($expected, (string) $point);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user