项目作者: jthomas

项目描述 :
Serverless "Logstash Forwarder" for pushing OpenWhisk actions logs into Elasticsearch
高级语言: JavaScript
项目地址: git://github.com/jthomas/openwhisk-logstash-forwarder.git
创建时间: 2017-11-21T10:06:33Z
项目社区:https://github.com/jthomas/openwhisk-logstash-forwarder

开源协议:MIT License

下载


openwhisk-logstash-forwarder

Serverless implementation of a “logstash forwarder“ for Apache OpenWhisk.

Pushes OpenWhisk actions logs into ElasticSearch using Lumberjack input for Logstash.

Demo

usage

This project contains a single OpenWhisk action (logstash-forwarder). The action is scheduled to run on a timer using the alarms trigger feed.

Each time the action is triggered, it retrieves and indexes all new log messages for monitored actions.

Log messages are stored in the following format in action activation records.

  1. 2017-11-13T15:45:25.278483919Z stdout: log message content....
  2. 2017-11-13T15:45:25.278483919Z stderr: err message content....

The Lumberjack input for Logstash is used to push log messages into ElasticSearch.

Log messages are indexed with the following JSON object syntax.

  1. {
  2. "line": "2017-11-13T15:45:25.278483919Z stdout: log message content....",
  3. "activation": "<ACTIVATION_ID>",
  4. "action": "<ACTION_NAME>",
  5. "namespace": "<ACTION_NAMESPACE>"
  6. }

Using Kibana, log messages can be searched and monitored using dashboards.

Kibana UI

configuration

Event parameters are used to control the runtime configuration properties.

  • actions - list of action names to monitor for logs.
  • from - monitor logs since this unix time.
  • logstash - connection details passed to client library.
    • host - logstash host name
    • port - logstash port

Properties can be stored as default parameters on the action or using alarm trigger feed event parameters.

installation

This project needs an instance of OpenWhisk platform and an ELK-stack service accessible on a public IP address.

create openwhisk account

Register an account with an instance of the OpenWhisk platform.

elk-stack instance

There are many offerings for managed ELK services in the cloud. If you want to run a local instance for testing, follow these instructions…

  • Use Docker to run a local instance of the ELK service.

    1. $ docker run -p 5601:5601 -p 5000:5000 -it --name elk sebp/elk:es241_l240_k461
  • Use Burrow.io to create public hostname and port from localhost port 5000.

  • Visit Kibana running on localhost to check service is working.

set monitoring configuration

Monitoring properties are configured in the config.json file. This controls the actions to monitor, log retrieval start time and logstash service details.

  • Update the configuration file with the monitoring configuration properties.

    1. {
    2. "actions": ["sample_action"], <-- list of action names
    3. "from": 0, <-- monitor logs from this unix time
    4. "logstash": {
    5. "host": "my_host.com", <-- host name for logstash service
    6. "port": 5000 <-- port for logstash service (5000)
    7. "rejectUnauthorized": false <-- support use of self-signed certificates
    8. }
    9. }

deploy

This project can be deployed using The Serverless Framework or the OpenWhisk CLI.

using the serverless framework

using wsk cli

  • Install the OpenWhisk CLI tool.

  • Register OpenWhisk account credentials with the tool.

    1. $ wsk property set --apihost openwhisk.ng.bluemix.net --auth <API_KEY>
  • Create action package from source files and dependencies.

    1. $ zip -r action.zip dist/ node_modules/ package.json
  • Deploy action with default configuration parameters.

    1. $ wsk action create logstash-forwarder action.zip --kind nodejs:6 --param-file config.json
  • Create trigger using feed from alarm package.

    1. $ wsk trigger create once-a-minute --feed /whisk.system/alarms/alarm --param cron "* * * * *"
  • Bind action and trigger with a rule.

    1. $ wsk rule create index-logs once-a-minute logstash-forwarder

monitoring processed logs

Once project resources are deployed, the logstash-forwarder action will be invoked once a minute.

Listing activation records shows the trigger being fired, which invokes the rule and runs the action.

  1. $ wsk activation list
  2. activations
  3. feb935cd51ba4885b935cd51ba2885fe logstash-forwarder
  4. 40dc649bfd2b44219c649bfd2be421cd once-a-minute
  5. a1616bce50d14340a16bce50d10340db index-logs

Check the logs from the logstash-forwarder action to see what activation records have been retrieved for the monitored actions.

  1. $ wsk activation logs feb935cd51ba4885b935cd51ba2885fe
  2. 2017-11-20T15:12:05.620558134Z stdout: search activations (myaction) since 1511187779602
  3. 2017-11-20T15:12:05.680260278Z stdout: found 2 activations (myaction): 056b3d8d7ac04879ab3d8d7ac0a8793c, 8ac54796ab9c44fc854796ab9c04fc02
  4. 2017-11-20T15:12:05.988628046Z stdout: LAST_ACTIVATION myaction 1511188316441

alternatives

This project “pushes” logs into ElasticSearch using the Lumberjack input plugin for Logstash.

There is an OpenWhisk plugin for Logstash, which “pulls” log messages from the platform. The plugin makes Logstash responsible for polling the OpenWhisk platform for logs.

Using the plugin removes the need to run a custom action to manage log ingestion. However, many hosted ELK services do not allow the installation of custom plugins.

development

The action code uses Node.js 8 features (async/await) that are not available on the default OpenWhisk Node.js runtime.

Babel is used to transpile the source code to overcome this issue. Use npm run build to run the build tools prior to deployment.

Unit tests are available in the test directory and can be executed with npm test.