This script will pull metrics from Megaport API and push them to DataDog. It uses the the Megaport API to gather the last 30 minutes worth of mbps in/out samples. These samples are then pushed via the DataDog API. Megaport provides their metrics at ~5 minute intervals. DataDog will not care about the duplicated samples and will do a no-op.
NOTE This is only for routers of type "MCR2". If you would like to view bandwidth data from another Megaport product you will need to change the "products" address URI. Please refer to: https://dev.megaport.com/#service-metrics--2
- Megaport user and password (I would recommend creating a new read-only user for this)
- An AWS account with access to Lambda
- DataDog API key
- Linux or OS X
- User pyenv or venv to create a virtual environment (optional, but recommended)
make install
- Uncomment the last line in lambda_function.py
python lambda_function.py
make build
- Create a new Lambda in AWS
- Upload function.zip, which was created by
make build
- Create a trigger based on a CloudWatch event and choose "schedule" then input a desired cron. I do a trigger every 5 minutes.
cron(0/5 * * * ? *)
- Create three environment variables:
DD_API_KEY
,MP_PASSWORD
, andMP_USERNAME
. Input your sensitive values. - Test
If you do not specific a custom metric prefix, you should see your metric as megaport.*
in DataDog. There you can make a dashboard and monitors to your liking.