项目作者: jthomas

项目描述 :
This project uses IBM Cloud Monitoring to save metrics from IBM Cloud Functions
高级语言: JavaScript
项目地址: git://github.com/jthomas/cloud-functions-metrics-service.git
创建时间: 2017-12-21T10:53:54Z
项目社区:https://github.com/jthomas/cloud-functions-metrics-service

开源协议:MIT License

下载


cloud-functions-metrics-service

This project uses IBM Cloud Monitoring to save metrics from IBM Cloud Functions.

Metrics collected by the openwhisk-metrics library are forwarded into the external monitoring service.

usage

Metrics can be forwarded into IBM Cloud Monitoring in real-time or sent in batches using a background process.

  • Real-time ingestion ensures metrics appear immediately in the monitoring service. Metrics forwarded using the batch ingestion won’t be available until the next background task execution.
  • Batch ingestion does not add any delay to action invocations. Real-time ingestion saves invocation metrics each time the action handler is called. This adds a (small) delay to each invocation, where the library calls the external metrics service.

real-time ingestion

  • Install OpenWhisk metrics and IBM Cloud Monitoring service libraries

    1. $ npm install openwhisk-metrics cloud-functions-metrics-service
  • Wrap action handlers using external libraries

    1. const metrics = require('openwhisk-metrics')
    2. const service = require('cloud-functions-metrics-service')
    3. metrics.service = service.client({
    4. host: 'metrics.ng.bluemix.net',
    5. scope: '...',
    6. api_key: '...'
    7. })
    8. const main = params => {
    9. return { message: "Hello World" }
    10. }
    11. exports.main = metrics(main)

Configuration options for the openwhisk-metrics library are available in the project repository.

Configuration options for the IBM Cloud Monitoring service are available in the project repository.

Metrics forwarded using external real-time ingestion will not be logged to the console. If you want to enable this for debugging or testing, use this code snippet.

  1. const client = service.client({
  2. host: 'metrics.ng.bluemix.net',
  3. scope: '...',
  4. api_key: '...'
  5. })
  6. const log = metrics.service
  7. metrics.service = values => {
  8. log.save(values)
  9. return client.save(values)
  10. }

batch ingestion

set up metric collectors

  • Set up action handlers with openwhisk-metrics

    1. const metrics = require('openwhisk-metrics')
    2. const main = params => {
    3. return { message: "Hello World" }
    4. }
    5. module.exports.main = metrics(main)

All actions you want to collect metrics for should use the library as above. Use the action names in the configuration below for the background task.

create metric forwarder action

  • Download project repository

    1. $ git clone https://github.com/jthomas/cloud-functions-metrics-service
    2. $ cd cloud-functions-metrics-service
  • Create action deployment package.

    1. $ npm install
    2. $ zip -r action.zip index.js package.json lib node_modules
  • Fill in authentication parameters in action configuration file (config.json).

    1. {
    2. "actions": ["action_names_to_monitor"],
    3. "service": {
    4. "host": "metrics.ng.bluemix.net",
    5. "scope": "...",
    6. "api_key": "..."
    7. }
    8. }

    Configuration options for the IBM Cloud Monitoring service are available in the project repository.

  • Create new OpenWhisk action from deployment package and configuration file.

    1. $ wsk action create metric-forwarder --kind nodejs:8 action.zip --param-file config.json
  • Create trigger feed for alarm package to run metric-forwarder on periodic schedule.

    1. $ wsk trigger create interval \
    2. --feed /whisk.system/alarms/interval \
    3. --param minutes 10 \
  • Bind trigger to action using rule.

    1. $ wsk rule create forward-metrics-on-interval interval metric-forwarder