Skip to content

erichester76/gcloud-api-alerta

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alerta API on Google Cloud

Alerta is a monitoring tool used for alert consolidation, de-duplication and correlation.

To deploy Alerta API to Google Cloud use the Google App Engine Flexible Environment with Cloud SQL for PostgreSQL for a fully managed service.

Note: The following steps will incur costs. See https://cloud.google.com/sql/pricing#pg-pricing

Installation

Run the Alerta API in Google Cloud by cloning this repo, creating a Cloud SQL instance and deploying the application to Google App Engine.

To create an PostgreSQL instance either use the Google Cloud Console or install the gcloud SDK and run:

$ gcloud sql instances create [INSTANCE_NAME] \
--database-version=POSTGRES_9_6 --storage-type=SSD --tier=db-f1-micro

$ gcloud sql users set-password postgres no-host \
--instance [INSTANCE_NAME] --password [PASSWORD]

Note: Change the --storage-type and --tier as appropriate.

Log in to psql to create a database using GCloud Shell or gcloud (you will be prompted for the password set above):

$ gcloud sql connect [INSTANCE_NAME] --user postgres

Password for user postgres:
*******
psql (9.6.2, server 9.6.1)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128, compression: off)
Type "help" for help.

postgres=> CREATE DATABASE monitoring;
CREATE DATABASE

Configuration

Copy the app.yaml.example file to app.yaml and set the DATABASE_URL and beta_settings for the PostgreSQL instance using the INSTANCE_CONNECTION_NAME generated above:

env_variables:
  DATABASE_URL: postgres://USER:PASSWORD@/DATABASE?host=/cloudsql/INSTANCE_CONNECTION_NAME

beta_settings:
    cloud_sql_instances: INSTANCE_CONNECTION_NAME

Example

env_variables:
  DATABASE_URL: postgres://postgres:p0stgr3s@/monitoring?host=/cloudsql/alerta5:europe-west2:monitoring

beta_settings:
    cloud_sql_instances: alerta5:europe-west2:monitoring

Deploy

To deploy the Alerta API and lauch a browser to view the API index page run:

$ gcloud app deploy
$ gcloud app browse

Note: Add --verbosity=info to any gcloud command to get more verbose logging.

Housekeeping

An App Engine Cron schedule can be configured to run a housekeeping job every minute which expires alerts which have timed-out and deletes expired and closed alerts.

To enable the cron job run:

$ gcloud app deploy cron.yaml

Scaling Down

To scale down the app deploy using --version dev then it can be stopped and started easily:

$ gcloud app deploy --version dev
$ gcloud app versions stop dev
$ gcloud app versions start dev

Testing

Create a Service Account for remote access and download the Cloud SQL Proxy.

$ cloud_sql_proxy ...

TBC

Troubleshooting

All gcloud commands take --verbosity which can be used to output more verbose logging like so:

$ gcloud app deploy --verbosity=info

To tail the application logs run:

$ gcloud app logs tail -s default
2017-09-23 10:57:59 default[20170923t115438]  2017/09/23 10:57:59 Ready for new connections
2017-09-23 10:57:59 default[20170923t115438]  2017/09/23 10:57:59 errors parsing config:
2017-09-23 10:57:59 default[20170923t115438]  	googleapi: Error 403: Access Not Configured.
Cloud SQL Administration API has not been used in project 465218335446 before or it is disabled.
Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview?project=465218335446
then retry. If you enabled this API recently, wait a few minutes for the action to propagate
to our systems and retry., accessNotConfigured

To connect to the database instance using psql run:

$ gcloud sql connect [INSTANCE_NAME] --user postgres

References

License

Copyright (c) 2017 Nick Satterly. Available under the MIT License.

About

Deploy Alerta API to Google Cloud

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published