Skip to content
leonbarrett edited this page Nov 9, 2010 · 2 revisions

To use this api, make a call to one of the methods.

The call will then return an XML formatted block which you can then echo out inside one of your Controllers.

Example

The example controller below displays a Geck-O-Meter widget containing data from ServerDensity.

<?php

class Serverdensity extends Controller {

	function Serverdensity()
	{
		parent::Controller();
		$this->load->library('server_density_api');	
		$this->load->library('geckoboard_api');	
	}
	
	function serverload($server_id='')
	{	
		date_default_timezone_set('Europe/London'); 
		$start_time = gmdate("Y-m-d\TH:i:s",strtotime('-1 hour')); 
		$end_time = gmdate("Y-m-d\TH:i:s"); 
		
		$load = $this->server_density_api->get_server_load($server_id);
		$range = $this->server_density_api->get_server_load_range($server_id,$start_time,$end_time);
				
		$data = array();
		$data['value'] = $load->metric->value;
		
		$data['min']['value'] = $range->metrics[0]->value;
		$data['min']['label'] = 'Min Load';
		
		$data['max']['value'] = $range->metrics[1]->value;
		$data['max']['label'] = 'Max Load';
		
       	$response = $this->geckoboard_api->return_geckoboard_meter($data);
       	
       	echo($response);
       				
	}
}

The controller method accepts an ID which is then passed to a ServerDensity API to fetch data.

Inside Geckoboard click Add New Widget, choose Custom Charts > Geck-O-Meter.

On the settings panel enter the following information:

URL data feed (the path to your controller and function), in our case http://example.com/serverdensity/serverload/5

API key - leave blank unless you wish to add some sort of tracking/security for your data (this is not included in this library)

Widget type - Custom

Feed format - XML

The rest of the options are then up to you.

Click Save, and your widget should then display the data that you passed in via your controller

Clone this wiki locally