RESTful API for creating a chart

By using RESTful API, it can extract data, and then connect the data with external applications. The user can also visualize the data by using the JavaScript chart library.

RESTFul API Server
You can use RESTful API while the mach webadmin runs.

Data Entry
Create the entry program by using CLI, JDBC, and Python.You can also enter the data by using Collector Guide.

Write a JS Chart
You can describe how to generate the chart by using chart.js (open-source). It can work with other chart libraries as well.
http://www.chartjs.org/

When getting the result values by executing an SQL statement using the GET method and RESTful API, generate the chart after adjusting data to the chart library. Refer to the sample code below. To create a query based on each time period, refer to format string from Built-In Functions.

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<head>
<title>chart</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1/Chart.min.js"></script>
<script type="text/javascript">
var data = {
labels : [],
datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : []
}
]
};
</script>
</head>
<body>
<h2> apache access log per 30 min</h2>
<br/>
<div class="chartWrap" style="position:relative;margin:10px auto;width:96%;height:500px;">
<canvas id="ifChart"></canvas>
</div>

<script>
var sql = "select TO_CHAR(time, 'YYYY-MM-DD HH24:MI30') as x, count(host) as y from apache_access_log group by x order by 1 asc duration 1 day";

$.ajax({
type:'get',
async:true,
url: 'http://192.168.0.10:8080/machbase',
data: 'q='+encodeURIComponent(sql),
beforeSend: function() {
},
success: function(resp) {
$.each($.parseJSON('['+resp+']'), function(n,v) {
data.labels[n] = v.x;
data.datasets[0].data[n] = v.y;
});

var canvas = document.getElementById("ifChart");
canvas.width = $('.chartWrap').width();
canvas.height = $('.chartWrap').height();
var ctx = canvas.getContext("2d");

new Chart(ctx).Bar(data);
},
error: function(request,status,err) {
alert(request.status+':'+request.responseText+'\n'+status + '\n' + err);
},
complete: function() {
}
});
</script>
</body>
</html>

It needs the results from GROUP BY clause with a specified time range due to the characteristics of time series data. Machbase provides the query syntax to get fast query results as follows.

It provides date formats such as "MI30" to easily get the results on a half hourly basis.
select to_char(time, 'YYYY-MM-DD HH24:MI30') as x, count(*) as y from apache_access_log group by x order by 1 asc duration 1 day.
However, when there are more data, the performance time for the query execution will be increased. Therefore, it requires much faster query syntax. To get the results every 30 minute, write queries as follows.

select to_char(date_trunc('minute', time, 30),'YYYY-MM-DD HH24:MI') as x, count(*) as y from apache_access_log group by x order by 1 asc duration 1 day;

results matching ""

    No results matching ""