open-nomad/website/source/docs/jobops/logs.html.md

94 lines
4.0 KiB
Markdown
Raw Normal View History

2016-06-28 20:08:53 +00:00
---
layout: "docs"
page_title: "Operating a Job: Accessing Logs"
sidebar_current: "docs-jobops-logs"
description: |-
Learn how to operate a Nomad Job.
---
2016-06-30 00:46:45 +00:00
# Accessing Logs
Accessing applications logs is critical when debugging issues, performance
2016-06-30 20:32:33 +00:00
problems or even for verifying the application is starting correctly. To make
2016-06-30 00:46:45 +00:00
this as simple as possible, Nomad provides both a CLI tool and an API for
accessing application logs and data files.
To see this in action we can just run the example job which created using `nomad
init`:
```
$ nomad init
Example job file written to example.nomad
```
2016-06-30 20:32:33 +00:00
This job will start a redis instance in a Docker container. We can run it now:
2016-06-30 00:46:45 +00:00
```
$ nomad run example.nomad
==> Monitoring evaluation "7a3b78c0"
Evaluation triggered by job "example"
Allocation "c3c58508" created: node "b5320e2d", group "cache"
Evaluation status changed: "pending" -> "complete"
==> Evaluation "7a3b78c0" finished with status "complete"
```
We can grab the allocation ID from above and use the [`nomad fs`
command](/docs/commands/fs.html) to access the applications logs. Logs are
stored under the following directory structure:
`alloc/logs/<task-name>.<stdout/stderr>.<index>`. Nomad has built in log
2016-06-30 20:32:33 +00:00
rotation, documented in the [Jobspec](/docs/jobspec/index.html#log_rotation).
The index is a monotonically increasing number starting at zero and incremented
each time the log is rotated.
2016-06-30 00:46:45 +00:00
2016-06-30 20:32:33 +00:00
Thus to access the `stdout` we can issue the below command:
2016-06-30 00:46:45 +00:00
```
$ nomad fs c3c58508 alloc/logs/redis.stdout.0
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.1 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1:M 28 Jun 19:49:30.504 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 28 Jun 19:49:30.505 # Server started, Redis version 3.2.1
1:M 28 Jun 19:49:30.505 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 28 Jun 19:49:30.505 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 28 Jun 19:49:30.505 * The server is now ready to accept connections on port 6379
```
2016-06-30 20:32:33 +00:00
Replacing `stdout` for `stderr` would display the respective `stderr` output.
2016-06-30 00:46:45 +00:00
While this works well for quickly accessing logs, we recommend running a
log-shipper for long term storage of logs. In many cases this will not be needed
and the above will suffice but for use cases in which log retention is needed
Nomad can accomodate.
Since we place application logs inside the `alloc/` directory, all tasks within
the same task group have access to each others logs. Thus we can have a task
group as follows:
```
group "my-group" {
task "log-producer" {...}
task "log-shipper" {...}
}
```
In the above example, the `log-producer` task is the application that should be
run and will be producing the logs we would like to ship and the `log-shipper`
reads these logs from the `alloc/logs/` directory and ships them to a long term
storage such as S3.