Want a demo? Take the docker-compose file located in cpudemo/
(yes, this one) and store it locally. From its location run:
The first run may take some time since the docker engine has to download several images.
Also, the Hawkular first start is longer because it has to setup schema in Cassandra.
Then open Grafana (http://localhost:3000), log in (admin/admin), click on "Home" and you will see that a dashboard is already listed:
You can see it’s updated regularly with your host’s CPU usage (to be more accurate, it’s the system load average over the past minute).
How does it work?
It’s actually very simple. A shell script runs top
and extracts the system load average.
That value is pushed to Hawkular every 10 seconds under the tenant $TENANT
and gauge load-avg
.
while :
do
loadavg=`awk '{ print $1 }' /proc/loadavg`
ux_timestamp=`date +%s`
timestamp=$(($ux_timestamp * 1000))
curl -u jdoe:password -X POST http://hawkular:8080/hawkular/metrics/gauges/load-avg/raw \
-d "[{\"timestamp\": $timestamp, \"value\": $loadavg}]" \
-H "Content-Type: application/json" -H "Hawkular-Tenant: $TENANT"
sleep 10
done
This script is then included in a docker image (jotak/hawkular-grafana-cpudemo
) with a simple Dockerfile:
FROM centos:7
ADD ./push-cpu.sh /tmp/push-cpu.sh
RUN chmod +x /tmp/push-cpu.sh
ENTRYPOINT ["/tmp/push-cpu.sh"]
The docker image is on dockerhub so you don’t have to worry about building it.
And finally, all the glue is done in the docker-compose file:
docker-compose.yml
hawkular:
# (same as before)
hawkular-cassandra:
# (same as before)
grafana:
# (same as before)
bootstrap:
image: "jotak/hawkular-grafana-bootstrap:latest"
environment:
- TENANT=cpudemo
- DASHBOARDS=cpudemo
cpudemo:
image: "jotak/hawkular-grafana-cpudemo:latest"
environment:
- TENANT=cpudemo
As you can see, we just configured the tenant and dashboards in bootstrap
,
and added a section for our new image jotak/hawkular-grafana-cpudemo
with the same tenant configured.