Skip to content

Instantly share code, notes, and snippets.

@garethahealy
Created December 10, 2016 17:15
Show Gist options
  • Save garethahealy/7986adf64bfcc63763e76f469712f3d4 to your computer and use it in GitHub Desktop.
Save garethahealy/7986adf64bfcc63763e76f469712f3d4 to your computer and use it in GitHub Desktop.
hawkular-timestamp-precision.sh
#!/usr/bin/env bash
METRIC_ID="my-first-metric"
QUOTA_NAMESPACE="test"
HAWKULAR_URL="https://hawkular-metrics.apps.10.2.2.2.xip.io/hawkular/metrics"
HAWKULAR_TOKEN=$(oc whoami -t)
HAWKULAR_TENANT="testing1"
CREATE_JSON_PAYLOAD=$(cat <<EOF
{
"id" : "$METRIC_ID",
"tags" : {
"namespace" : "$QUOTA_NAMESPACE",
"quota" : "true"
},
"type" : "counter",
"tenantId" : "$HAWKULAR_TENANT"
}
EOF
)
echo $CREATE_JSON_PAYLOAD | curl -k -X POST -H "Content-Type: application/json" -H "Hawkular-Tenant: $HAWKULAR_TENANT" -H "Authorization: Bearer $HAWKULAR_TOKEN" $HAWKULAR_URL/counters -d @-
ADD_JSON_PAYLOAD_WRONG_TIMESTAMP=$(cat <<EOF
[
{
"timestamp": $(date +%s),
"value": 1,
"tags" : {
"namespace" : "$QUOTA_NAMESPACE",
"quota" : "true"
}
}
]
EOF
)
echo $ADD_JSON_PAYLOAD_WRONG_TIMESTAMP | curl -k -X POST -H "Content-Type: application/json" -H "Hawkular-Tenant: $HAWKULAR_TENANT" -H "Authorization: Bearer $HAWKULAR_TOKEN" $HAWKULAR_URL/counters/$METRIC_ID/raw -d @-
HTTP_STATUS=$(curl -k -X GET --write-out %{http_code} --silent --output /dev/null -H "Content-Type: application/json" -H "Hawkular-Tenant: $HAWKULAR_TENANT" -H "Authorization: Bearer $HAWKULAR_TOKEN" $HAWKULAR_URL/counters/$METRIC_ID/raw)
if [ $HTTP_STATUS == "204" ]; then
echo "No content, but we've posted data..."
fi
ADD_JSON_PAYLOAD=$(cat <<EOF
[
{
"timestamp": $(date +%s%N | cut -b1-13),
"value": 2,
"tags" : {
"namespace" : "$QUOTA_NAMESPACE",
"quota" : "true"
}
}
]
EOF
)
echo $ADD_JSON_PAYLOAD | curl -k -X POST -H "Content-Type: application/json" -H "Hawkular-Tenant: $HAWKULAR_TENANT" -H "Authorization: Bearer $HAWKULAR_TOKEN" $HAWKULAR_URL/counters/$METRIC_ID/raw -d @-
curl -k -X GET -H "Content-Type: application/json" -H "Hawkular-Tenant: $HAWKULAR_TENANT" -H "Authorization: Bearer $HAWKULAR_TOKEN" $HAWKULAR_URL/counters/$METRIC_ID/raw
echo "Now we should of seen data above due to correct timestamp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment