Home

Awesome

Logstash Mesos Framework

This is a Mesos framework for running Logstash in your cluster. When another program on any Mesos agent logs an event, it will be parsed by Logstash and sent to central log locations. There are many ways to log an event, such as syslog or writing to a log file. Programs can simply log to localhost or a local file, so you do not have to configure them to talk to an external Logstash endpoint. This framework is suitable for non-critical logging of events which may be dropped, such as resource usage statistics. We currently advise using other systems for business-critical event logging, such as PCI DSS events.

This framework tries to launch a Logstash process on every Mesos agent. Specifically, it accepts a Mesos offer if the offered agent does not yet have Logstash running, and the offer has enough resources to run Logstash. This does not guarantee the presence of Logstash on every agent, but most clusters can gain high allocation if they reserve resources for the logstash role.

Running

Requirements

Running directly

After satisfying the above requirements, start the Logstash framework by starting a Docker container from your mesos/logstash-scheduler image, like this:

> docker run mesos/logstash-scheduler \
    --mesos.zookeeper.server=123.0.0.12:5181 \
    --mesos.master=123.0.0.11:5050 \
    --framework-name=logstash \
    --mesos-role='*' \
    --mesos-user=root \
    --logstash.heap-size=64 \
    --logstash.elasticsearch-host=elasticsearch.service.consul:1234 \
    --logstash.executor-image=mesos/logstash-executor \
    --logstash.executor-version=latest \
    --logstash.syslog-port=514 \
    --logstash.collectd-port=25826 \
    --executor.cpus=0.5 \
    --executor.heap-size=128 \
    --enable.collectd=true \
    --enable.syslog=true \
    --enable.file=true \
    --enable.docker=true \
    --executor.file-path='/var/log/*,/home/jhf/example.log'

To reconfigure the Logstash framework, you must tear it down and start a new one.

We support providing configuration options with command-line arguments and environment variables. This means the following two docker commands are equivalent:

# Using command-line arguments
docker run mesos/logstash-scheduler --mesos.zookeeper.server=123.0.0.12:5181 --mesos.master=123.0.0.11:5050

# Using environment variables
docker run -e MESOS_ZOOKEEPER_SERVER=123.0.0.12:5181 -e MESOS_MASTER=123.0.0.11:5050 mesos/logstash-scheduler

Note that command-line arguments take precedence: if both a command-line argument and an environment variable are provided, the value of the command-line argument will be used.

Here is the full list of configuration options:

Command-line argumentEnvironment variableDefaultWhat it does
--mesos.zookeeper.server=HMESOS_ZOOKEEPER_SERVER=HRequiredThe Logstash framework will use ZooKeeper at host H, which must be in the format host:port
--mesos.master=HMESOS_MASTER=HRequiredThe Logstash framework will use Mesos master at host H, which must be in the format host:port
--mesos-framework-name=NMESOS_FRAMEWORK_NAME=NlogstashThe Logstash framework will show up in the Mesos Web UI with name N, and the ZK state will be rooted at znode N
--mesos-role=RMESOS_ROLE=RlogstashThe Logstash framework role will register with Mesos with framework role R
--mesos-user=UMESOS_USER=UrootLogstash tasks will be launched with Unix user U
--logstash.heap-size=HLOGSTASH_HEAP_SIZE=H32The memory allocation pool for the Logstash process will be limited to H megabytes
--logstash.elasticsearch-host=HLOGSTASH_ELASTICSEARCH_HOST=HAbsentIf present, Logstash will forward its logs to an Elasticsearch instance H, which must be in the format ofhost:port
--logstash.executor-image=SLOGSTASH_EXECUTOR_IMAGE=Smesos/logstash-executorThe Logstash framework will use the Docker image with name S as the executor on new Mesos Agents
--logstash.executor-version=SLOGSTASH_EXECUTOR_VERSION=SlatestThe Logstash framework will use version S of the Docker image on new Mesos Agents
--logstash.syslog-port=ILOGSTASH_SYSLOG_PORT=I514Every Mesos agent will listen for syslog messages on port I. Must be enabled with --enable.syslog=true
--logstash.collectd-port=ILOGSTASH_COLLECTD_PORT=I25826Every Mesos agent will listen for collectd messages on port I. Must be enabled with --enable.collectd=true
--logstash.config-file=FLOGSTASH_CONFIG_FILE=FAbsentUse your own logstash configuration file. This will usually disable the --enable.* flags.
--executor.cpus=CEXECUTOR_CPUS=C0.2The Logstash framework will only accept resource offers with at least C CPUs. C must be a decimal greater than 0
--executor.heap-size=HEXECUTOR_HEAP_SIZE=H64The memory allocation pool for the executor will be limited to H megabytes
--enable.collectd=BENABLE_COLLECTD=BfalseIff B is true, Logstash will listen for collectd events on UDP port 25826 on all executors
--enable.syslog=BENABLE_SYSLOG=BfalseIff B is true, Logstash will listen for syslog events on TCP port 514 on all executors
--enable.file=BENABLE_FILE=BfalseIff B is true, each line in files matching the --file.path pattern will be treated as a log event
--enable.docker=BENABLE_DOCKER=BtrueRun executors in Docker containers. If disabled Mesos will distribute executors and Logstash automatically via http.
--executor.file-path=PEXECUTOR_FILE_PATH=P`` (empty)All files at paths matching P, a comma-separated list of file path glob patterns, will be watched for log lines

Running as Marathon app

To run the Logstash framework as a Marathon app use the following app template (save e.g. as logstash.json): You can use the "env" map to configure the framework with environment variables, as above.

{
  "id": "/logstash",
  "cpus": 1,
  "mem": 1024.0,
  "instances": 1,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "mesos/logstash-scheduler:0.0.6",
      "network": "HOST"
    }
  },
  "env": {
    "MESOS_ZOOKEEPER_SERVER": "123.0.0.12:5181",
    "MESOS_MASTER": "123.0.0.11:5050",
    "FRAMEWORK_NAME": "logstash",
    "MESOS_ROLE": "logstash",
    "MESOS_USER": "root",
    "LOGSTASH_HEAP_SIZE": "64",
    "LOGSTASH_ELASTICSEARCH_URL": "http://elasticsearch.service.consul:1234",
    "EXECUTOR_CPUS": "0.5",
    "EXECUTOR_HEAP_SIZE": "128",
    "ENABLE_COLLECTD": "true",
    "ENABLE_SYSLOG": "true",
    "ENABLE_FILE": "true",
    "ENABLE_DOCKER": "true",
    "EXECUTOR_FILE_PATH": "/var/log/*,/home/jhf/example.log"
  }
}

Please keep in mind that if you start the Logstash app as a Marathon app that this will start a scheduler on one arbitrary agent. The scheduler itself will try to start one (only one) executor on each node. To scale the application from within Marathon makes no sense because only one scheduler per framework is allowed to run and the framework scales itself to all agents.

<a name="newversion"></a>Updating to a newer version (or reinstalling the app)

When reinstalling, you must manually go into your zookeeper ui and remove the path /logstash/frameworkId. This is so that the reinstalled app will be able to register without losing the Logstash docker and agent configurations.

<a name="building"></a>Building the artifacts

The Logstash framework consists of two artifacts: the mesos/logstash-scheduler and mesos/logstash-executor images. To build the images, first install these dependencies:

Then run the following command from this directory, which will build a Java .jar for the scheduler and the executor, wrap them in Docker images, and run the test suite on them:

./gradlew --info clean build

To test you have the two images:

> docker images
REPOSITORY                  TAG                        IMAGE ID            CREATED             VIRTUAL SIZE
mesos/logstash-scheduler    latest                     3230c945e0f1        2 seconds ago       498.2 MB
mesos/logstash-executor     latest                     cdbc9d56ef73        2 seconds ago       589.7 MB
...

Scheduler shutdown and restarts

The scheduler will always de-register the framework when shut down gracefully by SIGTERM (a.k.a. CTRL-C). To restart the scheduler without Logstash instances being stopped the scheduler has to be stopped with a SIGKILL (a.k.a. kill -9 PID) and then started again with the same framework name.

Limitations

Disk space limitations

Log files will be streamed into local files within the logstash-mesos container. This requires disk space which is hard to estimate beforehand, since it depends on the number of available log files.

The intention is to do a best guess when allocating resources from Mesos (Work in Progress).

Full deployment not guaranteed

This framework accepts a Mesos offer if the offered agent does not yet have Logstash running, and the offer has enough resources to run Logstash. This does not guarantee the presence of Logstash on every agent, because we are dependent on Mesos giving us appropriate offers for every agent. Most clusters can gain high allocation if they reserve resources for the logstash role, but we cannot guarantee full allocation.

Security

There is no mechanism which ensures that the Logstash output might overlap with other Logstash configurations. In other words: Logstash might observe one framework and output to the same destination it's using for another framework.

Sponsors

This project is sponsored by Cisco Cloud Services. Thank you for contributing to the Open Source community!