How to monitor OpenCloud RDS data bases from Zabbix

Sergio Carmona
Cobalt Bond
Published in
5 min readOct 31, 2017

by Sergio Carmona, Cloud, Monitoring and Security expert at Cobalt Bond

In this story I am going to tell you how you can monitor RDS instances (Databases as a service) running in Telefonica OpenCloud from your Zabbix monitoring platform.

About a year ago we moved our monitoring infrastructure from Nagios to Zabbix. For years we worked with Nagios as deep as we could (templating, customizing,etc.), but we were still looking for a more flexible and scalable platform and so, we finally built a cloud monitoring platform based on Zabbix and Grafana. The platform is running in the Telefonica public cloud OpenCloud) it is autoscalable and we can monitor almost anything no matter if the target is hosted on premises or in the cloud.

One of the things that people miss when using RDS instances in public clouds (AWS, Azure, Bluemix, Telefonica OpenCloud, etc.) is the possibility to install a monitoring agent or enabling SNMP to monitor your instances, as you are accessing a platform rather than infrastructure.

With Zabbix you have the posibility of building your custom items based on externalscripts, and OpenCloud provides you an API to access your tenant resources…so you just only have to use them.

OpenCloud API Authentication

To interact with OpenCloud API you need first to make an authentication request to obtain a TOKEN. This token will allow you to interact with the rest of the API functions.

This is a linux shell script to obtain the token:

url="https://iam.na-mexico-1.telefonicaopencloud.com/v3/auth/tokens"result="$(curl -sS -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{"auth":{"identity":{ "methods":["password"],"password":{ "user":{"id":"'$uid'","password":"'$upwd'"}}},"scope":{"project":{"id":"'$upid'"}}}}' $url -i)"
log "DEBUG" "Got token RESULT: $result"
while IFS=':' read key value;
do
value=${value##+([[:space:]])}; value=${value%%+([[:space:]])}
case "$key" in
X-Subject-Token)
cto="$value"
;;
esac
done <<< "$result"

You will need to provide the script with an OpenCloud userid $uidits password $upwdand the tenant’s project id $upid

The script will loop to find the X-Subject-Token value in the header response and store it in the variable cto.

OpenCloud API RDS instances querying

Now we can use the token to query OpenCloud about our RDS instances.

First we can make an script for Zabbix to autodiscover RDS instances in your OpenCloud tenant:

curl -sS -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" -H "X-Language: en-us" -X GET "https://rds.na-mexico-1.telefonicaopencloud.com/rds/v1/$PROJECTID/instances" | jq --compact-output '.instances[] |{"{#OMC_RDS_ID}": .id, "{#OMC_RDS_NAME}": .name}' | gawk 'BEGIN{first=0;}{if (first == 0){print "{\"data\":[";print $0;first=1}else{printf ",%s",$0;}}END{print "]}";}'

This script will need a valid TOKEN and your tenant’s project id and will query OpenCloud for the name and id of your RDS instances. The script uses jq to parse json result from OpenCloud API and awkto format a new json to be used by Zabbix.

You can make your wrapper, and install it in your Zabbix Proxy or Server in the external library path. Usually: /usr/lib/zabbix/externalscripts

For example lets call our wrapper (that calls the token generator script and then query for RDS instances) omc_rds_getinstances.sh

Configuring Zabbix autodiscovery rules

Now in Zabbix we can create a new host (lets call it CB-OMC) and store common parameters (user, password, projectid) as user macros:

User macros on Host configuration

Then we can create a discovery rule that uses our wrapper script and pass the user macros we have set up above, as parameters

Discovery rule configuration

Querying metrics from Cloud Eye (CES)

Now we need to create another external script that will use the RDS instances ID obtained from our discovery rule and query CES for RDS metrics.

curl -sS -H "X-Auth-Token: $TOKEN" -X GET "https://ces.na-mexico-1.telefonicaopencloud.com/V1.0/$PROJECTID/metric-data?namespace=SYS.$SERVICEID&metric_name=$METRICID&dim.0=$INSTANCEID&from=$FROM&to=$TO&period=$PERIOD&filter=$FILTER" | jq 'last(.datapoints[].max)'

The script needs a lot of input parameters:

  • The authentication TOKEN
  • The Tenant’s project ID
  • The Service ID (RDS in this cases)
  • The Metric ID (what we want to measure for example cpu_util)
  • The instance ID (That was obtained from the discover rule)
  • The start time of the query (in epoch)
  • The end time of the query (in epoch)
  • The data monitoring interval (seconds)
  • The data aggregation mode (Max, Min, Avg, Sum or Variance)

Again we would need to create a wrapper script that obtains an authetication token and receive the rest of the input parameters from Zabbix. We need to store the script in the same path /usr/lib/zabbix/externalscripts of your Zabbix Proxy or Server. Lets call it omc_ces_getMetric.sh

Zabbix item prototypes for metrics

Now from Zabbix we can create item protoypes linked to our discovery rule to query for different metrics. For example, we can create an item prototype to query for Active connections in the RDS instance:

We can use the following item key

omc_ces_getMetric.sh["{$OMC_ID}","{$OMC_PASS}","{$OMC_PROJECTID}","RDS","rds007_conn_active_count","rds_instance_id,{#OMC_RDS_ID}","3600000","1","max"]

Where $OMC_ID, $OMC_PASS, and $OMC_PROJECTID are obtained from the user macros we configured in the host. $OMC_RDS_ID is obtained from the discovery rule output and passed to the item protoype, and the rest are Cloud Eye (CES) parameters related to the metric we are querying.

Item prototype configuration

You can make as many item prototypes as you want. Some examples:

RDS item prototype examples

Now, Zabbix will periodically poll OpenCloud to detect changes in the RDS instances list and if so start checking automatically the items you have configured

Zabbix triggers prototypes

You can also create trigger prototypes to create automatically alerts based on the item prototypes values:

Trigger prototypes

Monitoring RDS Data

Now we can query Zabbix for latest monitoring data and have a look at our autodiscovered RDS monitoring data:

Zabbix monitoring latest data

Grafana dashboards

We can use Grafana to create a nice dashboard:

Grafana dashboards

This is my first story at Medium, hope you have found it useful and interesting.

In the next few days I will come back with another story to explain how to launch a Fortigate VM as an ECS in OpenCloud to enhance security and extend network features.

Comments are welcome!!

Cheers.

--

--