11.1.5.3. How to use custom meter by using some scripts

This chapter explains how to create custom meter by using sample script (custom_meter_scripts.tar.gz) described in API reference.

Create custom meter

The script used this time registers the memory information of the virtual server in the monitoring platform as a custom meter.
Script itself need to be arranged according to customer’s environment.

Download sample script

Download the sample script in the API reference on the virtual server for which you want to obtain memory information.

# wget https://ecl.ntt.com/en/documents/api-references/monitoring/_downloads/custom_meter_scripts.tar.gz

Once download is complete, extract the file. File path can be updated as you wish.

# tar zxvf custom_meter_scripts.tar.gz

Once extracting the file completed, following files are available.

custom_meter_scripts
 |
 + bin/
 |  |
 |  + save_token
 |  + send_custom_meter
 |
 + load_average_01.sh
 + load_average_05.sh
 + load_average_15.sh
 + use_memory.sh
 + ping_status.sh
 + ping_rtt_avg.sh
 + save_token.sh
 + setup.conf
 + token
save_token
Script for get token.
You don’t need to edit this file since get token api calls save_token.sh .

No need to edit

send_custom_meter
Script for send data to custom meter.
You don’t need to edit since api calls each shell scripts.

No need to edit

load_average_01.sh

Get the value of load average every one minutes by uptime commands and send data as custom meter.

Update as appropriate

load_average_05.sh

Get the value of load average every five minutes by uptime commands and send data as custom meter.

Update as appropriate

load_average_15.sh

Get the value of load average every fifteen minutes by uptime commands and send data as custom meter.

Update as appropriate

use_memory.sh

Get usage of memory in used by 'free -m' command, and send data to custom meter.

Update as appropriate

ping_status.sh

Get the result of sending the packet three times with the ping command and send it as a custom meter (success = 0, failure = 1)

Update as appropriate

ping_rtt_avg.sh

Send the packet three times with the ping command, acquire the average value of RTT, and send it as a custom meter

Update as appropriate

save_token.sh

Get token by calling API.

No need to edit

setup.conf

Configure parameter to execute sample script.

Update as appropriate

token
It is a file to record a token.
Since tokens are recorded by save_token.sh, editing is unnecessary

No need to edit


Environment setting

Edit setup.con to call API on customer’s environment. In this case, these scripts will be running on JP2 region. Please set tenant ID and API key according to customer's environment.

# vi setup.conf

export AUTH_URL=https://keystone-jp2-ecl.api.ntt.com
export MONITORING_URL=https://monitoring-jp2-ecl.api.ntt.com
export TENANT_ID=<tenantID>
export USER_NAME=<API key>
export PASSWORD=<API secret key>

Get Token

Once environment setting is completed, get token by using API. Acquired token will be recoded in token file as long as communication to API endpoint is success.

# sh save_token.sh
# cat token
8ee901ded...488efc28050

Edit script file

Next, edit the script file. As an example, edit use_memory.sh and ping_status.sh. The contents of each are as follows.

  • use_memory.sh
#!/bin/sh

. ./setup.conf

free -m | grep Mem: | awk {'print $3'} | send_custom_meter (RESOURCE_ID) (METER_NAME) (METER_TYPE) (METER_UNIT)
  • ping_status.sh
#!/bin/sh

. ./setup.conf

IP="(IP_ADDRESS)"

ping ${IP} -c 3 >> /dev/null
if [ $? == 0 ] ;
then
  PING_STATUS=0
else
  PING_STATUS=1
fi
echo ${PING_STATUS} | send_custom_meter (RESOURCE_ID) (METER_NAME) (METER_TYPE) (METER_UNIT)
RESOURCE_ID
Specify resource ID
RESOURCE_ID is configured <namespace>_<UUID>. Please refer to following chapter for <namespace>.
Here, specify resource ID of virtual server which memory usage is collected.
METER_NAME

Configure custom meter name.

METER_TYPE
Configure data type of custom meter. This configuration categorizes data.
Data type can be configured as follows;
cumulative: Cumulative value
delta: Difference value
gauge: Value at the timing
METER_UNIT

Specify the unit of custom meter value

IP_ADDRESS

ping Specify the IP address of the destination host


■The list of <namespace> in each menu>

<Menu>

<namespace>

Virtual Server Instance

nova

Virtual Server Volume

cinder

Firewall

firewall

Firewall interface

firewall-interface

Load Balancer

load-balancer

Load Balancer Interface

load-balancer-interface
Managed Load Balancer managed-lb

Managed Load Balancer Policy

managed-lb-policy

Baremetal Server

baremetal-server

Internet Connectivity

internet-connectivity

Internet-connectivity Gateway Interface

internet-gw-interface

VPN Connectivity

vpn-connectivity

VPN Connectivity Interface

vpn-gw-interface

Logical Network

logical-network

Logical Network Interface

logical-network-port

Inter-DC connectivity

interdc-connectivity

Inter-DC connectivity Interface

interdc-gw-interface

Get and send data

Execute the script configured. This completes getting usage data and send it to Monitoring service. However, at the first time, data will not be stored since only creating custom meter at initial running.

# sh use_memory.sh

To send data eventually, you need configure this script in cron. It is possible to receive data at intervals of 1 minute at the shortest. Please note that it will not be accepted if it is shorter than 1 minute.

# crontab -e
*/5 * * * * cd /root/custom_meter_scripts; sh use_memory.sh

Note

It takes a few minutes to display sent data on Monitoring graph.

Note

If sample value is not registered for 24 hours, the custom meter will turn to be inactive. If inactive custom meter is automatically deleted after 31days passed (default retention period), the alarm configured for this meter will also be automatically deleted at the same time. You can extend this period for 397 days when sign up advanced plan in Monitoring.(*Custom meters cannot be deleted by user operation other than automatic deletion.)


Check a Graph of Custom Meter

Data sent by API to Monitoring server will be displayed as graph on ECL2.0 Monitoring control panel.
Please refer to Verifying Meters ( Monitoring Items ) for how to check.
The graph will be displayed by selecting the meter for the resource specified at calling API.
カスタムメーターグラフ

Alert setting for Custom Meter

Alarm can be configured in the same method as other meters.
Please refer to Using Monitoring Alarms for details.