Skip to content

Commit

Permalink
Merge pull request #330 from tsegismont/rhmap_poc
Browse files Browse the repository at this point in the history
RHMAP samples
  • Loading branch information
tsegismont committed Sep 9, 2015
2 parents da7ed29 + 3a72af3 commit 0b97b0e
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
<exclude>src/main/docker/cassandra.yaml</exclude>
<!-- Exclude JAX-RS impl diff file -->
<exclude>api/diff.txt</exclude>
<!-- Exclude sample page dependencies -->
<exclude>samples/rhmap/web/libs/**</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
93 changes: 93 additions & 0 deletions samples/rhmap/script/send_availability.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
#
# Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Send an availability data point to an Hawkukar Metrics server.
#
# See 'usage' function for basic understanding.
#
# Note that the value parameter expects integers. This makes it easy to use this script to process the exit code of
# a command or another script. For example:
# ===
# $> check_jvm_is_up
# $> CODE=$?
# $> send_availability "http://localhost:8080/hawkular/metrics" "my_tenant" "hostname.jvm" "$CODE"
# ===
#

#set -x

function usage {
echo "Usage: send_availability url tenant metric <value>
url: the Hawkular Metrics server URL, i.e. 'http://localhost:8080/hawkular/metrics'
tenant: the id of the tenant in Hawkular Metrics
metric: the id of the metric the data point belongs to
value: if present, must be a number; 0 means 'up', any other value 'down'; absent means 'unknown'
"
}

function error {
echo "ERROR: $1" 1>&2
}

MIN_ARGUMENTS=3
MAX_ARGUMENTS=$((MIN_ARGUMENTS + 1))

if [ $# -lt ${MIN_ARGUMENTS} -o $# -gt ${MAX_ARGUMENTS} ]; then
error "Wrong number of arguments"
usage
exit 1
fi

if [ $# -eq ${MIN_ARGUMENTS} ]; then
AVAIL="unknown"
else
VALUE_ARG=$4
if [ "$VALUE_ARG" -eq "$VALUE_ARG" ] 2>/dev/null; then
if [ ${VALUE_ARG} -eq 0 ]; then
AVAIL="up"
else
AVAIL="down"
fi
else
error "Value argument must be an integer."
usage
exit 1
fi
fi

HAWKULAR_METRICS_URL="$1/availability/data"
TENANT_ID=$2
METRIC_ID=$3

TIMESTAMP=$(date +%s%3N)
read -r -d '' JSON <<- EOV
[{"id":"${METRIC_ID}","data":[{"timestamp":${TIMESTAMP},"value":"${AVAIL}"}]}]
EOV

RESPONSE=$(curl -i --silent -H "Hawkular-Tenant: $TENANT_ID" -H "Content-Type: application/json" \
${HAWKULAR_METRICS_URL} --data ${JSON})
STATUS_LINE=$(echo ${RESPONSE} | head -n 1)
STATUS=$(echo ${STATUS_LINE} | awk '{print $2}')

if [ ${STATUS} -ne 200 ]; then
error "Failed to persist availability data point: $RESPONSE"
exit 1
fi

exit 0
3 changes: 3 additions & 0 deletions samples/rhmap/web/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "libs"
}
1 change: 1 addition & 0 deletions samples/rhmap/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs
11 changes: 11 additions & 0 deletions samples/rhmap/web/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rhmap-poc",
"authors": [
"Red Hat"
],
"dependencies": {
"hawkular-charts": "0.4.15",
"jquery-ui": "1.11.4",
"jqueryui-timepicker-addon": "1.5.5"
}
}
115 changes: 115 additions & 0 deletions samples/rhmap/web/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Chart POC</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="libs/jquery-ui/themes/base/jquery-ui.css">
<link rel="stylesheet" href="libs/jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.css">
<link rel="stylesheet" href="libs/hawkular-charts/css/hawkular-charts.css">

<script type="text/javascript" src="libs/jquery/dist/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="libs/jquery-ui/jquery-ui.js" charset="utf-8"></script>
<script type="text/javascript" src="libs/jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.js"
charset="utf-8"></script>
<script type="text/javascript" src="libs/angular/angular.js" charset="utf-8"></script>
<script type="text/javascript" src="libs/d3/d3.js" charset="utf-8"></script>
<script type="text/javascript" src="libs/d3-tip/index.js" charset="utf-8"></script>
<script type="text/javascript" src="libs/moment/moment.js"></script>
<script type="text/javascript" src="libs/hawkular-charts/hawkular-charts.js"></script>

<script>
$(function () {
$("input.ui-datetime").datetimepicker({
dateFormat: "yy-mm-dd",
timeFormat: "HH:mm:ss",
showSecond: true
});
});

var myApp = angular.module("myApp", ["hawkular.charts"]);

myApp.controller("AvailTestController", function ($scope, $http) {
var dateTimeFormat = "YYYY-MM-DD HH:mm:ss";

$scope.reset = function () {
$scope.url = "http://localhost:8080/hawkular/metrics";
$scope.tenantId = "default";
$scope.metric = "test";

var now = moment();
$scope.start = now.clone().subtract(5, 'm').format(dateTimeFormat);
$scope.end = now.format(dateTimeFormat);

$scope.availAllChartData = [];
};

$scope.hasData = function () {
return $scope.availAllChartData.length > 0;
};

$scope.update = function () {
var start = moment($scope.start, dateTimeFormat, true);
if (!start.isValid()) {
error("Invalid start moment");
return;
}
var end = moment($scope.end, dateTimeFormat, true);
if (!end.isValid()) {
error("Invalid end moment");
return;
}
if (end - start <= 0) {
error("Invalid time range");
return;
}

$http.get($scope.url + "/availability/" + $scope.metric + "/data", {
headers: {
"Hawkular-Tenant": $scope.tenantId
},
params: {
"start": start.valueOf(),
"end": end.valueOf()
}
}).then(function (response) {
$scope.availAllChartData = response.data;
}, function (response) {
console.error(response);
window.alert("HTTP error")
});
};

$scope.reset();
});

function error(msg) {
window.alert("ERROR: " + msg);
}

</script>

</head>
<body ng-app="myApp">

<h3>Availability</h3>

<div ng-controller="AvailTestController">
<div>URL: <input ng-model="url"></div>
<div>Tenant: <input ng-model="tenantId"></div>
<div>Metric: <input ng-model="metric"></div>
<div>Start Date: <input ng-model="start" class="ui-datetime"></div>
<div>End Date: <input ng-model="end" class="ui-datetime"></div>
<div>
<button ng-click="update()">Update</button>
<button ng-click="reset()">Reset</button>
</div>
<hr>
<span ng-hide="hasData()">No data</span>
<availability-chart ng-show="hasData()" data="{{availAllChartData}}"></availability-chart>
<hr>
</div>

</body>
</html>

0 comments on commit 0b97b0e

Please sign in to comment.