From zero to server monitoring analytics

You'll learn how to create a database and create analytics in a server monitoring dataset using the API and the Data Exploration & Visualization Module.

In this page

Introduction

This tutorial will introduce you on how to use SlicingDice for storing, making queries on server monitoring data and visualize it using the built-in Data Exploration & Visualization Module.
For this tutorial, we'll purpose a dataset where you collect server monitoring data and insert it on SlicingDice. We'll also use API to the queries and insertion processes.


Retrieving your Team API Key

As we'll use the API, you'll need to retrieve your Team API Key in order to create a new database. Go to Control Panel, then open the Database Section. Click on Team API Key button and copy your Team API Key.

You can use any API REST client you prefer to execute your API requests or you can do it using curl as shown in the examples on this tutorial.


Creating a database

To create a database using API, you'll need to send a POST request to the /database API Endpoint, like the following example. You should receive a success message after the execution.

curl -X POST https://api.slicingdice.com/v1/database \
    -H 'Authorization: TEAM_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
    	"database": {
      		"name": "LogsDB",
      		"description": "Database to store server monitoring data",
      		"type": "test",
      		"pricing-model": "pay-per-column",
      		"query-load": "normal",
      		"insertion-load": "normal",
            "cloud_provider": "ovh",
            "cloud_area": "global"
    		}
}'

Retrieving your Database Key

As your database is created, you'll now need to retrieve the Database Key to start modeling and using it. Go to Control Panel, open the Database Section. Find your database name, click on Show Keys and copy the Master Key.


Creating columns

Before inserting data, we need to create some columns. For this tutorial, we'll use the default dimension. We'll also create new columns, based on the table below.

Column Name Data Type
entity-id Unique-ID
datacenter Integer
disk-space Decimal-Event

We'll use a POST request on the /column endpoint to create a new column. You can also use our SDK Clients to create them. The command you should execute will be like this:

$ curl -X POST https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "name": "datacenter",
            "api-name": "datacenter",
            "type": "integer",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "disk-space",
            "api-name": "disk-space",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

columns_data = [
        {
            "name": "datacenter",
            "api-name": "datacenter",
            "type": "integer",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "disk-space",
            "api-name": "disk-space",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
]
print(slicingdice.create_column(columns_data))
import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray columnData = new JSONArray()
        .put(new JSONObject()
            .put("name", "datacenter")
            .put("api-name", "datacenter")
            .put("type", "integer")
            .put("storage", "latest-value")
            .put("dimension", "default"))
        .put(new JSONObject()
            .put("name", "disk-space")
            .put("api-name", "disk-space")
            .put("type", "decimal-event")
            .put("decimal-places", 2)
            .put("dimension", "default"));
        JSONObject result = slicingdice.createColumn(columnData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

column_data = [
        {
            "name" => "datacenter",
            "api-name" => "datacenter",
            "type" => "integer",
            "storage" => "latest-value",
            "dimension" => "default"
        },
        {
            "name" => "disk-space",
            "api-name" => "disk-space",
            "type" => "decimal-event",
            "decimal-places" => 2,
            "dimension" => "default"
        }
]
puts slicingdice.create_column(column_data)
const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const columnData = [
        {
            "name": "datacenter",
            "api-name": "datacenter",
            "type": "integer",
            "storage": "latest-value",
            "dimension": "default"
        }, {
            "name": "disk-space",
            "api-name": "disk-space",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default"
        }
];

slicingdice.createColumn(columnData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$columnData = array(
    array(
        "name" => "datacenter",
        "api-name" => "datacenter",
        "type" => "integer",
        "storage" => "latest-value",
        "dimension" => "default"
    ),
    array(
        "name" => "disk-space",
        api-name" => "disk-space",
        "type" => "decimal-event",
        "decimal-places" => 2,
        "dimension" => "default"
    )
);

print_r($slicingdice->createColumn($columnData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var columnData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"name", "datacenter"},
                    {"api-name", "datacenter"},
                    {"type", "integer"},
                    {"storage", "latest-value"},
                    {"dimension", "default"}
                },
                new Dictionary<string, dynamic>{
                    {"name", "disk-space"},
                    {"api-name", "disk-space"},
                    {"type", "decimal-event"},
                    {"decimal-places", 2},
                    {"dimension", "default"},
                }
            };

            var result = slicingdice.createColumn(columnData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    columnData := []interface{}{
        map[string]interface{}{
            "name": "datacenter",
            "api-name": "datacenter",
            "type": "integer",
            "storage": "latest-value",
            "dimension": "default",
        },
        map[string]interface{}{
            "name": "disk-space",
            "api-name": "disk-space",
            "type": "decimal-event",
            "decimal-places": 2,
            "dimension": "default",
        },
    }

    fmt.Println(slicingdice.createColumn(columnData))
}

If you receive a success message, your columns are created and ready to have data inserted on them.


Inserting data

Now we're going to insert some data. You can use a POST request on the /insert endpoint, the POST /sql endpoint or use our SDK Clients to insert data. The data in the table below will be inserted in the default dimension using the following commands.

entity-id datacenter disk-space
server-01 1
  • 0.73 - 2019-05-01T10:00:00Z
  • 0.69 - 2019-05-01T11:00:00Z
  • 0.62 - 2019-05-01T12:00:00Z
  • 0.59 - 2019-05-01T13:00:00Z
  • server-02 1
  • 0.81 - 2019-05-01T08:00:00Z
  • 0.74 - 2019-05-01T09:00:00Z
  • 0.66 - 2019-05-01T10:00:00Z
  • 0.64 - 2019-05-01T10:30:00Z
  • server-03 2
  • 0.50 - 2019-05-01T14:00:00Z
  • 0.46 - 2019-05-01T15:00:00Z
  • 0.42 - 2019-05-01T16:00:00Z
  • 0.39 - 2019-05-01T17:00:00Z
  • curl -X POST https://api.slicingdice.com/v1/insert \
        -H 'Authorization: API_KEY' \
        -H 'Content-Type: application/json' \
        -d '{
        "server-01": {
            "datacenter": 1,
            "disk-space": [
                {
                    "value": 0.73,
                    "date": "2019-05-01T10:00:00Z"
                },
                {
                    "value": 0.69,
                    "date": "2019-05-01T11:00:00Z"
                },
                {
                    "value": 0.62,
                    "date": "2019-05-01T12:00:00Z"
                },
                {
                    "value": 0.59,
                    "date": "2019-05-01T13:00:00Z"
                }
            ]
        },
        "server-02": {
            "datacenter": 1,
            "disk-space": [
                {
                    "value": 0.81,
                    "date": "2019-05-01T08:00:00Z"
                },
                {
                    "value": 0.74,
                    "date": "2019-05-01T09:00:00Z"
                },
                {
                    "value": 0.66,
                    "date": "2019-05-01T10:00:00Z"
                },
                {
                    "value": 0.64,
                    "date": "2019-05-01T10:30:00Z"
                }
            ]
        },
        "server-03": {
            "datacenter": 2,
            "disk-space": [
                {
                    "value": 0.50,
                    "date": "2019-05-01T14:00:00Z"
                },
                {
                    "value": 0.46,
                    "date": "2019-05-01T15:00:00Z"
                },
                {
                    "value": 0.42,
                    "date": "2019-05-01T16:00:00Z"
                },
                {
                    "value": 0.39,
                    "date": "2019-05-01T17:00:00Z"
                }
            ]
        }
    }'
    curl -X POST https://api.slicingdice.com/v1/sql \
    	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
    	    -H 'Content-Type: application/sql' \
    	    -d 'INSERT INTO default ([entity-id], datacenter, [disk-space.0.value], [disk-space.0.date], [disk-space.1.value], [disk-space.1.date], [disk-space.2.value], [disk-space.2.date], [disk-space.3.value], [disk-space.3.date])
    VALUES ('server-02', 1, 0.81, '{2019-05-01T08:00:00Z"', 0.74, '2019-05-01T09:00:00Z', 0.66, '2019-05-01T10:00:00Z', 0.64, '2019-05-01T10:30:00Z');
    INSERT INTO default ([entity-id], datacenter, [disk-space.0.value], [disk-space.0.date], [disk-space.1.value], [disk-space.1.date], [disk-space.2.value], [disk-space.2.date], [disk-space.3.value], [disk-space.3.date])
    VALUES ('server-01', 1, 0.73, '2019-05-01T10:00:00Z', 0.69, '2019-05-01T11:00:00Z', 0.62, '2019-05-01T12:00:00Z', 0.59, '2019-05-01T13:00:00Z');
    INSERT INTO default ([entity-id], datacenter, [disk-space.0.value], [disk-space.0.date], [disk-space.1.value], [disk-space.1.date], [disk-space.2.value], [disk-space.2.date], [disk-space.3.value], [disk-space.3.date])
    VALUES ('server-03', 2, 0.5, '2019-05-01T14:00:00Z', 0.46, '2019-05-01T15:00:00Z', 0.42, '2019-05-01T16:00:00Z', 0.39, '2019-05-01T17:00:00Z');'
    from pyslicer import SlicingDice
    slicingdice = SlicingDice(master_key='MASTER_API_KEY')
    
    insert_data = {
    
        "server-01": {
            "disk-space": [
                {
                    "date": "2019-05-01T10:00:00Z",
                    "value": 0.73
                },
                {
                    "date": "2019-05-01T11:00:00Z",
                    "value": 0.69
                },
                {
                    "date": "2019-05-01T12:00:00Z",
                    "value": 0.62
                },
                {
                    "date": "2019-05-01T13:00:00Z",
                    "value": 0.59
                }
            ],
            "datacenter": 1
        },
        "server-02": {
            "disk-space": [
                {
                    "date": "2019-05-01T08:00:00Z",
                    "value": 0.81
                },
                {
                    "date": "2019-05-01T09:00:00Z",
                    "value": 0.74
                },
                {
                    "date": "2019-05-01T10:00:00Z",
                    "value": 0.66
                },
                {
                    "date": "2019-05-01T10:30:00Z",
                    "value": 0.64
                }
            ],
            "datacenter": 1
        },
        "server-03": {
            "disk-space": [
                {
                    "date": "2019-05-01T14:00:00Z",
                    "value": 0.5
                },
                {
                    "date": "2019-05-01T15:00:00Z",
                    "value": 0.46
                },
                {
                    "date": "2019-05-01T16:00:00Z",
                    "value": 0.42
                },
                {
                    "date": "2019-05-01T17:00:00Z",
                    "value": 0.39
                }
            ],
            "datacenter": 2
        }
    }
    
    print(slicingdice.insert(insert_data))
    
    
    import com.slicingdice.jslicer.SlicingDice;
    import java.io.IOException;
    import org.json.JSONObject;
    import org.json.JSONArray;
    
    public class Example {
        public static void main(String[] args) throws IOException {
            SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
    
            JSONObject insertData = new JSONObject()
            .put("server-01", new JSONObject()
                .put("disk-space", new JSONArray()
                    .put(new JSONObject()
                        .put("date", "2019-05-01T10:00:00Z")
                        .put("value", 0.73))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T11:00:00Z")
                        .put("value", 0.69))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T12:00:00Z")
                        .put("value", 0.62))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T13:00:00Z")
                        .put("value", 0.59)))
                .put("datacenter", 1))
            .put("server-02", new JSONObject()
                .put("disk-space", new JSONArray()
                    .put(new JSONObject()
                        .put("date", "2019-05-01T08:00:00Z")
                        .put("value", 0.81))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T09:00:00Z")
                        .put("value", 0.74))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T10:00:00Z")
                        .put("value", 0.66))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T10:30:00Z")
                        .put("value", 0.64)))
                .put("datacenter", 1))
            .put("server-03", new JSONObject()
                .put("disk-space", new JSONArray()
                    .put(new JSONObject()
                        .put("date", "2019-05-01T14:00:00Z")
                        .put("value", 0.5))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T15:00:00Z")
                        .put("value", 0.46))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T16:00:00Z")
                        .put("value", 0.42))
                    .put(new JSONObject()
                        .put("date", "2019-05-01T17:00:00Z")
                        .put("value", 0.39)))
                .put("datacenter", 2));
    
            JSONObject result = slicingdice.insert(insertData);
            System.out.println(result.toString());
        }
    }
    
    require 'rbslicer'
    slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
    
    insert_data = {
    
        "server-01" => {
            "disk-space" => [
                {
                    "date" => "2019-05-01T10:00:00Z",
                    "value" => 0.73
                },
                {
                    "date" => "2019-05-01T11:00:00Z",
                    "value" => 0.69
                },
                {
                    "date" => "2019-05-01T12:00:00Z",
                    "value" => 0.62
                },
                {
                    "date" => "2019-05-01T13:00:00Z",
                    "value" => 0.59
                }
            ],
            "datacenter" => 1
        },
        "server-02" => {
            "disk-space" => [
                {
                    "date" => "2019-05-01T08:00:00Z",
                    "value" => 0.81
                },
                {
                    "date" => "2019-05-01T09:00:00Z",
                    "value" => 0.74
                },
                {
                    "date" => "2019-05-01T10:00:00Z",
                    "value" => 0.66
                },
                {
                    "date" => "2019-05-01T10:30:00Z",
                    "value" => 0.64
                }
            ],
            "datacenter" => 1
        },
        "server-03" => {
            "disk-space" => [
                {
                    "date" => "2019-05-01T14:00:00Z",
                    "value" => 0.5
                },
                {
                    "date" => "2019-05-01T15:00:00Z",
                    "value" => 0.46
                },
                {
                    "date" => "2019-05-01T16:00:00Z",
                    "value" => 0.42
                },
                {
                    "date" => "2019-05-01T17:00:00Z",
                    "value" => 0.39
                }
            ],
            "datacenter" => 2
        }
    }
    
    puts slicingdice.insert(insert_data)
    
    const SlicingDice = require('slicerjs');
    
    const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
    
    const insertData = {
    
        "server-01": {
            "disk-space": [
                {
                    "date": "2019-05-01T10:00:00Z",
                    "value": 0.73
                },
                {
                    "date": "2019-05-01T11:00:00Z",
                    "value": 0.69
                },
                {
                    "date": "2019-05-01T12:00:00Z",
                    "value": 0.62
                },
                {
                    "date": "2019-05-01T13:00:00Z",
                    "value": 0.59
                }
            ],
            "datacenter": 1
        },
        "server-02": {
            "disk-space": [
                {
                    "date": "2019-05-01T08:00:00Z",
                    "value": 0.81
                },
                {
                    "date": "2019-05-01T09:00:00Z",
                    "value": 0.74
                },
                {
                    "date": "2019-05-01T10:00:00Z",
                    "value": 0.66
                },
                {
                    "date": "2019-05-01T10:30:00Z",
                    "value": 0.64
                }
            ],
            "datacenter": 1
        },
        "server-03": {
            "disk-space": [
                {
                    "date": "2019-05-01T14:00:00Z",
                    "value": 0.5
                },
                {
                    "date": "2019-05-01T15:00:00Z",
                    "value": 0.46
                },
                {
                    "date": "2019-05-01T16:00:00Z",
                    "value": 0.42
                },
                {
                    "date": "2019-05-01T17:00:00Z",
                    "value": 0.39
                }
            ],
            "datacenter": 2
        }
    };
    
    slicingdice.insert(insertData).then((resp) => {
        console.log(resp);
    }, (err) => {
        console.error(err);
    });
    
    >?php
    use Slicer\SlicingDice;
    $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
    
    $insertData = array(
        "server-01" => array(
            "disk-space" => array(
                array(
                    "date" => "2019-05-01T10:00:00Z",
                    "value" => 0.73
                ),
                array(
                    "date" => "2019-05-01T11:00:00Z",
                    "value" => 0.69
                ),
                array(
                    "date" => "2019-05-01T12:00:00Z",
                    "value" => 0.62
                ),
                array(
                    "date" => "2019-05-01T13:00:00Z",
                    "value" => 0.59
                )
            ),
            "datacenter" => 1
        ),
        "server-02" => array(
            "disk-space" => array(
                array(
                    "date" => "2019-05-01T08:00:00Z",
                    "value" => 0.81
                ),
                array(
                    "date" => "2019-05-01T09:00:00Z",
                    "value" => 0.74
                ),
                array(
                    "date" => "2019-05-01T10:00:00Z",
                    "value" => 0.66
                ),
                array(
                    "date" => "2019-05-01T10:30:00Z",
                    "value" => 0.64
                )
            ),
            "datacenter" => 1
        ),
        "server-03" => array(
            "disk-space" => array(
                array(
                    "date" => "2019-05-01T14:00:00Z",
                    "value" => 0.5
                ),
                array(
                    "date" => "2019-05-01T15:00:00Z",
                    "value" => 0.46
                ),
                array(
                    "date" => "2019-05-01T16:00:00Z",
                    "value" => 0.42
                ),
                array(
                    "date" => "2019-05-01T17:00:00Z",
                    "value" => 0.39
                )
            ),
            "datacenter" => 2
        )
    );
    
    print_r($slicingdice->insert($insertData));
    ?>
    using System.Collections.Generic;
    using Slicer;
    using Newtonsoft.Json;
    
    namespace SlicerTester.Console
    {
        class Program
        {
            static void Main(string[] args)
            {
                var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
    
                var insertData = new Dictionary<string, dynamic>{
    
                    {"server-01", new Dictionary<string, dynamic>{
                        {"disk-space", new List<dynamic>{
                            new Dictionary>string, dynamic>{
                                {"date", "2019-05-01T10:00:00Z"},
                                {"value", 0.73}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T11:00:00Z"},
                                {"value", 0.69}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T12:00:00Z"},
                                {"value", 0.62}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T13:00:00Z"},
                                {"value", 0.59}
                            }
                        }},
                        {"datacenter", 1}
                    }},
                    {"server-02", new Dictionary<string, dynamic>{
                        {"disk-space", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T08:00:00Z"},
                                {"value", 0.81}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T09:00:00Z"},
                                {"value", 0.74}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T10:00:00Z"},
                                {"value", 0.66}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T10:30:00Z"},
                                {"value", 0.64}
                            }
                        }},
                        {"datacenter", 1}
                    }},
                    {"server-03", new Dictionary<string, dynamic>{
                        {"disk-space", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T14:00:00Z"},
                                {"value", 0.5}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T15:00:00Z"},
                                {"value", 0.46}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T16:00:00Z"},
                                {"value", 0.42}
                            },
                            new Dictionary<string, dynamic>{
                                {"date", "2019-05-01T17:00:00Z"},
                                {"value", 0.39}
                            }
                        }},
                        {"datacenter", 2}
                    }}
                };
    
                var result = slicingdice.Insert(insertData);
                System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
            }
        }
    }
    
    package main
    import (
        "fmt"
        "github.com/SlicingDice/slicingdice-go/slicingdice"
    )
    func main() {
        keys := new(slicingdice.APIKey)
        keys.MasterKey = "MASTER_API_KEY"
        slicingdice := slicingdice.New(keys, 60)
    
        insertData := map[string]interface{}{
            "server-01": map[string]interface{}{
                "disk-space": []interface{}{
                    map[string]interface{}{
                        "date": "2019-05-01T10:00:00Z",
                        "value": 0.73,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T11:00:00Z",
                        "value": 0.69,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T12:00:00Z",
                        "value": 0.62,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T13:00:00Z",
                        "value": 0.59,
                    },
                },
                "datacenter": 1,
            },
            "server-02": map[string]interface{}{
                "disk-space": []interface{}{
                    map[string]interface{}{
                        "date": "2019-05-01T08:00:00Z",
                        "value": 0.81,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T09:00:00Z",
                        "value": 0.74,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T10:00:00Z",
                        "value": 0.66,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T10:30:00Z",
                        "value": 0.64,
                    },
                },
                "datacenter": 1,
            },
            "server-03": map[string]interface{}{
                "disk-space": []interface{}{
                    map[string]interface{}{
                        "date": "2019-05-01T14:00:00Z",
                        "value": 0.5,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T15:00:00Z",
                        "value": 0.46,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T16:00:00Z",
                        "value": 0.42,
                    },
                    map[string]interface{}{
                        "date": "2019-05-01T17:00:00Z",
                        "value": 0.39,
                    },
                },
                "datacenter": 2,
            }
        }
    
        fmt.Println(slicingdice.Insert(insertData))
    }

    Querying your data

    It's possible to do multiple queries using the API and you can also make queries using the SDK Clients or any SQL workbench you prefer. For this tutorial purpose, we'll make three different data analysis as you'll see below.

    • 1st analysis
    • On this first analysis, we'll answer the following question:
      What was the average available disk space usage from Data Center 1 server in the first two days of May 2019?

      To answer the question, you'll make an aggregation query that is a powerful way to cross data in order to find insights and unexpected patterns.

      The query below will ask to SlicingDice to filter all servers (entities) from datacenter 1 and then make an average on all values for the disk-space column that were generated between 2019-05-01 and 2019-05-02

      curl -X POST https://api.slicingdice.com/v1/query/aggregation \
          -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
          -H 'Content-Type: application/json' \
          -d '{
          "filter": [
              {
                  "datacenter": {
                      "equals": 1
                  }
              }
          ],
          "query": [
              {
                  "disk-space": "avg",
                  "between": [
                      "2019-05-01T00:00:00Z",
                      "2019-05-02T23:59:59Z"
                  ]
              }
          ]
      }'
      curl -X POST https://api.slicingdice.com/v1/sql \
      	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
      	    -H 'Content-Type: application/sql' \
      	    -d 'SELECT AVG([disk-space.value]) FROM default WHERE [disk-space.date] BETWEEN '2019-05-01T00:00:00Z' AND '2019-05-02T23:59:59Z' AND datacenter = 1;'
      from pyslicer import SlicingDice
      slicingdice = SlicingDice(master_key='MASTER_API_KEY')
      
      query_data = {
          "filter": [
              {
                  "datacenter": {
                      "equals": 1
                  }
              }
          ],
          "query": [
              {
                  "disk-space": "avg",
                  "between": [
                      "2019-05-01T00:00:00Z",
                      "2019-05-02T23:59:59Z"
                  ]
              }
          ]
      }
      
      print(slicingdice.aggregation(query_data))
      import com.slicingdice.jslicer.SlicingDice;
      import java.io.IOException;
      import org.json.JSONObject;
      import org.json.JSONArray;
      
      public class Example {
          public static void main(String[] args) throws IOException {
              SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
      
              JSONObject queryData = new JSONObject()
              .put("filter", new JSONArray()
                  .put(new JSONObject()
                      .put("datacenter", new JSONObject()
                          .put("equals", 1))))
              .put("query", new JSONArray()
                  .put(new JSONObject()
                      .put("disk-space", "avg")
                      .put("between", new JSONArray()
                          .put("2019-05-01T00:00:00Z")
                          .put("2019-05-02T23:59:59Z"))));
              JSONObject result = slicingdice.aggregation(queryData);
              System.out.println(result.toString());
          }
      }
      require 'rbslicer'
      slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
      
      query_data = {
          "filter" => [
              {
                  "datacenter" => {
                      "equals" => 1
                  }
              }
          ],
          "query" => [
              {
                  "disk-space" => "avg",
                  "between" => [
                      "2019-05-01T00:00:00Z",
                      "2019-05-02T23:59:59Z"
                  ]
              }
          ]
      }
      
      puts slicingdice.aggregation(query_data)
      const SlicingDice = require('slicerjs');
      
      const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
      
      const queryData = {
          "filter": [
              {
                  "datacenter": {
                      "equals": 1
                  }
              }
          ],
          "query": [
              {
                  "disk-space": "avg",
                  "between": [
                      "2019-05-01T00:00:00Z",
                      "2019-05-02T23:59:59Z"
                  ]
              }
          ]
      };
      
      slicingdice.aggregation(queryData).then((resp) => {
          console.log(resp);
      }, (err) => {
          console.error(err);
      });
      <?php
      use Slicer\SlicingDice;
      $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
      
      $queryData = array(
          "filter" => array(
              array(
                  "datacenter" => array(
                      "equals" => 1
                  )
              )
          ),
          "query" => array(
              array(
                  "disk-space" => "avg",
                  "between" => array(
                      "2019-05-01T00:00:00Z",
                      "2019-05-02T23:59:59Z"
                  )
              )
          )
      );
      
      print_r($slicingdice->aggregation($queryData));
      ?>
      using System.Collections.Generic;
      using Slicer;
      using Newtonsoft.Json;
      
      namespace SlicerTester.Console
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
      
                  var queryData = new Dictionary<string, dynamic>{
                      {"filter", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"datacenter", new Dictionary<string, dynamic>{
                                  {"equals", 1}
                              }}
                          }
                      }},
                      {"query", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"disk-space", "avg"},
                              {"between", new List<dynamic>{
                                  "2019-05-01T00:00:00Z",
                                  "2019-05-02T23:59:59Z"
                              }}
                          }
                      }}
                  };
      
                  var result = slicingdice.Aggregation(queryData);
                  System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
              }
          }
      }
      package main
      import (
          "fmt"
          "github.com/SlicingDice/slicingdice-go/slicingdice"
      )
      func main() {
          keys := new(slicingdice.APIKey)
          keys.MasterKey = "MASTER_API_KEY"
          slicingdice := slicingdice.New(keys, 60)
      
          queryData := map[string]interface{}{
              "filter": []interface{}{
                  map[string]interface{}{
                      "datacenter": map[string]interface{}{
                          "equals": 1,
                      },
                  },
              },
              "query": []interface{}{
                  map[string]interface{}{
                      "disk-space": "avg",
                      "between": []interface{}{
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      },
                  },
              },
          }
      
          fmt.Println(slicingdice.Aggregation(queryData))
      }

      After runnign this query, you should be able to see the following result.

      {
         "status":"success",
         "result":{
            "disk-space":{
               "avg":0.685
            }
         },
         "took":0.089
      }

      As you can see at the result above, the disk utilization is around 68,5% in the data center 1 servers in the first two days of May 2019.

    • 2nd analysis
    • Now another question we'll make is the following one:
      How many servers presented some instability in the first two days of May 2019?

      We can answer this question using the Count Entities query that are useful to know how many unique entities (in this case, servers) you have that satisfies some set of conditions.

      In this case, we want to know how many unique servers (entities) have the status value as unstable between 2019-05-01 and 2019-05-02. We will also insert a name for this query, calling it as number-of-unstable-servers.

      curl -X POST https://api.slicingdice.com/v1/query/count/entity \
          -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
          -H 'Content-Type: application/json' \
          -d '{
          "query-name": "number-of-unstable-servers",
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ]
      }'
      curl -X POST https://api.slicingdice.com/v1/sql \
      	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
      	    -H 'Content-Type: application/sql' \
      	    -d 'SELECT COUNT([entity-id]) FROM default WHERE status = 'unstable' AND [status.date] BETWEEN '2019-05-01T00:00:00Z' AND '2019-05-02T23:59:59Z';'
      from pyslicer import SlicingDice
      slicingdice = SlicingDice(master_key='MASTER_API_KEY')
      
      query_data = {
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name": "number-of-unstable-servers"
      }
      
      print(slicingdice.count_entity(query_data))
      import com.slicingdice.jslicer.SlicingDice;
      import java.io.IOException;
      import org.json.JSONObject;
      import org.json.JSONArray;
      
      public class Example {
          public static void main(String[] args) throws IOException {
              SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
      
              JSONObject queryData = new JSONObject()
              .put("query", new JSONArray()
                  .put(new JSONObject()
                      .put("status", new JSONObject()
                          .put("equals", "unstable")
                          .put("between", new JSONArray()
                              .put("2019-05-01T00:00:00Z")
                              .put("2019-05-02T23:59:59Z")))))
              .put("query-name", "number-of-unstable-servers");
              JSONObject result = slicingdice.countEntity(queryData);
              System.out.println(result.toString());
          }
      }
      require 'rbslicer'
      slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
      
      query_data = {
          "query" => [
              {
                  "status" => {
                      "equals" => "unstable",
                      "between" => [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name" => "number-of-unstable-servers"
      }
      
      puts slicingdice.count_entity(query_data)
      const SlicingDice = require('slicerjs');
      
      const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
      
      const queryData = {
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ],
          "query-name": "number-of-unstable-servers"
      };
      
      slicingdice.countEntity(queryData).then((resp) => {
          console.log(resp);
      }, (err) => {
          console.error(err);
      });
      <?php
      use Slicer\SlicingDice;
      $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
      
      $queryData = array(
          "query" => array(
              array(
                  "status" => array(
                      "equals" => "unstable",
                      "between" => array(
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      )
                  )
              )
          ),
          "query-name" => "number-of-unstable-servers"
      );
      
      print_r($slicingdice->countEntity($queryData));
      ?>
      using System.Collections.Generic;
      using Slicer;
      using Newtonsoft.Json;
      
      namespace SlicerTester.Console
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
      
                  var queryData = new Dictionary<string, dynamic>{
                      {"query", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"status", new Dictionary<string, dynamic>{
                                  {"equals", "unstable"},
                                  {"between", new List<dynamic>{
                                      "2019-05-01T00:00:00Z",
                                      "2019-05-02T23:59:59Z"
                                  }}
                              }}
                          }
                      }},
                      {"query-name", "number-of-unstable-servers"}
                  };
      
                  var result = slicingdice.CountEntity(queryData);
                  System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
              }
          }
      }
      package main
      import (
          "fmt"
          "github.com/SlicingDice/slicingdice-go/slicingdice"
      )
      func main() {
          keys := new(slicingdice.APIKey)
          keys.MasterKey = "MASTER_API_KEY"
          slicingdice := slicingdice.New(keys, 60)
      
          queryData := map[string]interface{}{
              "query": []interface{}{
                  map[string]interface{}{
                      "status": map[string]interface{}{
                          "equals": "unstable",
                          "between": []interface{}{
                              "2019-05-01T00:00:00Z",
                              "2019-05-02T23:59:59Z",
                          },
                      },
                  },
              },
              "query-name": "number-of-unstable-servers",
          }
      
          fmt.Println(slicingdice.CountEntity(queryData))
      }
      

      After run this query, you'll see the following result.

      {
         "status":"success",
         "result":{
            "number-of-unstable-servers":2
         },
         "took":0.04
      }

      As you can see above, the results shows that 2 servers presented some instability in the last 24 hours. But which of them? Check the next analysis to find out.

    • 3rd analysis
    • Based on the second second the question to be answered is:
      What are the servers that are unstable in the first two days of May 2019?

      To answer the question, we need to execute a Result data extraction that allows you to retrieve data from stored columns. In this case, we're extracting data from the default dimension and extracting the entity-id from servers that have the status value as unstable between 2019-05-01 and 2019-05-02

      curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
          -H 'Authorization: MASTER_API_KEY' \
          -H 'Content-Type: application/json' \
          -d '{
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ]
      }'
      curl -X POST https://api.slicingdice.com/v1/sql \
      	    -H 'Authorization: PASTE_YOUR_PERSONAL_DEMO_API_KEY_HERE' \
      	    -H 'Content-Type: application/sql' \
      	    -d 'SELECT [entity-id] FROM default WHERE status = 'unstable' AND [status.date] BETWEEN '2019-05-01T00:00:00Z' AND '2019-05-02T23:59:59Z';'
      from pyslicer import SlicingDice
      slicingdice = SlicingDice(master_key='MASTER_API_KEY')
      
      query_data = {
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ]
      }
      
      print(slicingdice.result(query_data))
      import com.slicingdice.jslicer.SlicingDice;
      import java.io.IOException;
      import org.json.JSONObject;
      import org.json.JSONArray;
      
      public class Example {
          public static void main(String[] args) throws IOException {
              SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");
      
              JSONObject queryData = new JSONObject()
              .put("query", new JSONArray()
                  .put(new JSONObject()
                      .put("status", new JSONObject()
                          .put("equals", "unstable")
                          .put("between", new JSONArray()
                              .put("2019-05-01T00:00:00Z")
                              .put("2019-05-02T23:59:59Z")))));
              JSONObject result = slicingdice.result(queryData);
              System.out.println(result.toString());
          }
      }
      require 'rbslicer'
      slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')
      
      query_data = {
          "query" => [
              {
                  "status" => {
                      "equals" => "unstable",
                      "between" => [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ]
      }
      
      puts slicingdice.result(query_data)
      const SlicingDice = require('slicerjs');
      
      const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});
      
      const queryData = {
          "query": [
              {
                  "status": {
                      "equals": "unstable",
                      "between": [
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      ]
                  }
              }
          ]
      };
      
      slicingdice.result(queryData).then((resp) => {
          console.log(resp);
      }, (err) => {
          console.error(err);
      });
      <?php
      use Slicer\SlicingDice;
      $slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
      
      $queryData = array(
          "query" => array(
              array(
                  "status" => array(
                      "equals" => "unstable",
                      "between" => array(
                          "2019-05-01T00:00:00Z",
                          "2019-05-02T23:59:59Z"
                      )
                  )
              )
          )
      );
      
      print_r($slicingdice->result($queryData));
      ?>
      using System.Collections.Generic;
      using Slicer;
      using Newtonsoft.Json;
      
      namespace SlicerTester.Console
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");
      
                  var queryData = new Dictionary<string, dynamic>{
                      {"query", new List<dynamic>{
                          new Dictionary<string, dynamic>{
                              {"status", new Dictionary<string, dynamic>{
                                  {"equals", "unstable"},
                                  {"between", new List<dynamic>{
                                      "2019-05-01T00:00:00Z",
                                      "2019-05-02T23:59:59Z"
                                  }}
                              }}
                          }
                      }}
                  };
      
                  var result = slicingdice.Result(queryData);
                  System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
              }
          }
      }
      package main
      import (
          "fmt"
          "github.com/SlicingDice/slicingdice-go/slicingdice"
      )
      func main() {
          keys := new(slicingdice.APIKey)
          keys.MasterKey = "MASTER_API_KEY"
          slicingdice := slicingdice.New(keys, 60)
      
          queryData := map[string]interface{}{
              "query": []interface{}{
                  map[string]interface{}{
                      "status": map[string]interface{}{
                          "equals": "unstable",
                          "between": []interface{}{
                              "2019-05-01T00:00:00Z",
                              "2019-05-02T23:59:59Z",
                          },
                      },
                  },
              },
          }
      
          fmt.Println(slicingdice.Result(queryData))
      }

      After run this query, you'll see the following result.

      {
         "status":"success",
         "count":2,
         "data":{
           "server-01": {},
           "server-02": {}
         },
         "took":0.085,
         "next-page":null,
         "page":1
      }

      As you can see the result shows that the server-01 and server-02 were unstable on the defined period.


    Visualizing your data

    You can use the Data Visualization tool to create charts to visualize your data. On this section, you'll learn how to create one to visualize the answer for the following question:

    What are the servers sorted by the lowest available disk space on 01 May 2019?

    The answer for this question would look like the following chart. Below you'll learn how to build it.


    Creating the dataset for visualization

    Before creating a chart to visualize your data, you need to create a dataset. Watch the following quick video or read the written instructions below.

    Go to the Data Visualization Module, find the database name and click on Browse datasets. Click on Write SQL query and insert the following code to build a visualization dataset with all data you have stored.

    SELECT * FROM default;

    After that, click on Run. You'll see that the module returned the fields and data you have. Click on Done, name your dataset, click on Rename, then click on Done again to save your dataset.


    Creating the chart

    After the dataset is created, you can now create your chart. Watch the following time-lapse video to see how the chart at the start of this section was made or if you prefer read how to create your own.

    To create a chart, in the Dataset Browser, click on the dataset you just created and then select the option Create saved chart. The chart designer will open. You should use the following parameters:

    • In the Category Axis, choose entity-id
    • In the Value axis, select disk-space value and select the Minimum measure.
    • Still in the Value Axis, click on Add breakdown dimension and select disk-space days and select the Days as a measure.
    • Turn the chart to horizontal.
    • In the Filters section, select the disk-space date then click on Apply.
    • In the Sort section, click on the entity-id field, and select to be sorted by Measure. Select the field as disk-space value and the measure as Minimum. Click on Apply.
    • In the Format section, click on Colors option and change the option as By measure. Select the field as disk-space value and the measure as Minimum
    • Click on the Palette option and change the Color scheme as Yellow-Green. Change the number of steps to 3.
    • On the Elements tab, click on the Title option. In the Text field, insert the title as "Minimum disk space on 01 May 2019".
    • Go to the Legend option and click on the Visible switch.
    • Click on the Axis Y option. click on the Labels option and select the Percentage option.
    • Click on the Labels option. Click on the Number format option and select the Percentage option. Return and select the font size as 17.
    • Click on the floppy disk icon, insert a name for the saved chart and click OK.