Skip to content

Commit 2cb9555

Browse files
author
Leon Sodhi
committed
Merge pull request #14 from papertrail/import-from-r_s
Copied and updated examples and various sections in the readme
2 parents 435de6d + 3f8702d commit 2cb9555

10 files changed

+386
-3
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ X64_PLATFORMS := windows linux darwin
99
BUILD_PAIRS := $(foreach p,$(X86_PLATFORMS), $(p)/386 )
1010
BUILD_PAIRS += $(foreach p,$(X64_PLATFORMS), $(p)/amd64 )
1111

12-
BUILD_DOCS := README.md LICENSE example_config.yaml
12+
BUILD_DOCS := README.md LICENSE example_config.yml
1313

1414
package: $(BUILD_PAIRS)
1515

README.md

+206-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ option or the `-d` invocation flag are required.
4343
Precompiled binaries for Mac, Linux and Windows are available on the
4444
[remote_syslog2 releases page][releases].
4545

46-
Untar the package and copy the "remote_syslog" executable into your $PATH.
46+
Untar the package, copy the "remote_syslog" executable into your $PATH,
47+
and then customize the included example_config.yml with the log file paths
48+
to read and the host/port to log to.
4749

50+
Optionally, move and rename the configuration file to `/etc/log_files.yml` so
51+
that remote_syslog picks it up automatically. For example:
52+
53+
sudo cp ./remote_syslog /usr/local/bin
54+
sudo cp example_config.yml /etc/log_files.yml
55+
sudo vi /etc/log_files.yml
56+
57+
Configuration directives can also be specified as command-line arguments (below).
4858

4959
## Usage
5060

@@ -66,6 +76,201 @@ Untar the package and copy the "remote_syslog" executable into your $PATH.
6676
--tls=false: Connect via TCP with TLS
6777

6878

79+
## Example
80+
81+
Daemonize and collect messages from files listed in `./example_config.yml` as
82+
well as the file `/var/log/mysqld.log`. Write PID to `/tmp/remote_syslog.pid`
83+
and send to port `logs.papertrailapp.com:12345`:
84+
85+
$ remote_syslog -c example_config.yml -p 12345 --pid-file=/tmp/remote_syslog.pid /var/log/mysqld.log
86+
87+
Stay attached to the terminal, look for and use `/etc/log_files.yml` if it
88+
exists, and send with facility local0 to `a.example.com:514`:
89+
90+
$ remote_syslog -D -d a.example.com -f local0 /var/log/mysqld.log
91+
92+
93+
## Auto-starting at boot
94+
95+
Sample init files can be found [here](https://github.com/papertrail/remote_syslog2/blob/master/examples/). You may be able to:
96+
97+
$ cp examples/remote_syslog.init.d /etc/init.d/remote_syslog
98+
$ chmod 755 /etc/init.d/remote_syslog
99+
100+
And then ensure it's started at boot, either by using:
101+
102+
$ sudo update-rc.d remote_syslog defaults
103+
104+
or by creating a link manually:
105+
106+
$ sudo ln -s /etc/init.d/remote_syslog /etc/rc3.d/S30remote_syslog
107+
108+
remote_syslog will daemonize by default.
109+
110+
Init files: [remote_syslog.init.d](https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.init.d) (init.d), OS X [launchd](https://github.com/papertrail/remote_syslog2/blob/master/examples/com.papertrailapp.remote_syslog.plist), [supervisor](https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.supervisor.conf), Ubuntu [upstart](https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.upstart.conf)
111+
112+
113+
## Sending messages securely ##
114+
115+
If the receiving system supports sending syslog over TCP with TLS, you can
116+
pass the `--tls` option when running `remote_syslog`:
117+
118+
$ remote_syslog -D --tls -p 1234 /var/log/mysqld.log
119+
120+
or add `protocol: tls` to your configuration file.
121+
122+
123+
## Configuration
124+
125+
By default, remote_syslog looks for a configuration in `/etc/log_files.yml`.
126+
127+
The archive comes with a [sample config](https://github.com/papertrail/remote_syslog2/blob/master/example_config.yml). Optionally:
128+
129+
$ cp example_config.yml.example /etc/log_files.yml
130+
131+
`log_files.yml` has filenames to log from (as an array) and hostname and port
132+
to log to (as a hash). Wildcards are supported using * and standard shell
133+
globbing. Filenames given on the command line are additive to those in
134+
the config file.
135+
136+
Only 1 destination server is supported; the command-line argument wins.
137+
138+
files:
139+
- /var/log/httpd/access_log
140+
- /var/log/httpd/error_log
141+
- /var/log/mysqld.log
142+
- /var/run/mysqld/mysqld-slow.log
143+
destination:
144+
host: logs.papertrailapp.com
145+
port: 12345
146+
protocol: tls
147+
148+
remote_syslog sends the name of the file without a path ("mysqld.log") as
149+
the syslog tag (program name).
150+
151+
After changing the configuration file, restart `remote_syslog` using the
152+
init script or by manually killing and restarting the process. For example:
153+
154+
/etc/init.d/remote_syslog restart
155+
156+
157+
## Advanced Configuration (Optional)
158+
159+
Here's an [advanced config](https://github.com/papertrail/remote_syslog2/blob/master/examples/log_files.yml.example.advanced) which uses all options.
160+
161+
### Override hostname
162+
163+
Provide `--hostname somehostname` or use the `hostname` configuration option:
164+
165+
hostname: somehostname
166+
167+
168+
### Detecting new files
169+
170+
remote_syslog automatically detects and activates new log files that match
171+
its file specifiers. For example, `*.log` may be provided as a file specifier,
172+
and remote_syslog will detect a `some.log` file created after it was started.
173+
Globs are re-checked every 10 seconds.
174+
175+
Note: messages may be written to files in the 0-10 seconds between when the
176+
file is created and when the periodic glob check detects it. This data is not
177+
acted on.
178+
179+
If globs are specified on the command-line, enclose each one in single-quotes
180+
(`'*.log'`) so the shell passes the raw glob string to remote_syslog (rather
181+
than the current set of matches). This is not necessary for globs defined in
182+
the config file.
183+
184+
185+
### Log rotation
186+
187+
External log rotation scripts often move or remove an existing log file
188+
and replace it with a new one (at a new inode). The Linux standard script
189+
[logrotate](http://iain.cx/src/logrotate/) supports a `copytruncate` config
190+
option. With that option, `logrotate` will copy files, operate on the copies,
191+
and truncate the original so that the inode remains the same.
192+
193+
This comes closest to ensuring that programs watching these files (including
194+
`remote_syslog`) will not be affected by, or need to be notified of, the
195+
rotation. The only tradeoff of `copytruncate` is slightly higher disk usage
196+
during rotation, so we recommend this option whether or not you use
197+
`remote_syslog`.
198+
199+
200+
### Excluding files from being sent
201+
202+
Provide one or more regular expressions to prevent certain files from being
203+
matched.
204+
205+
exclude_files:
206+
- \.\d$
207+
- .bz2
208+
- .gz
209+
210+
211+
### Excluding lines matching a pattern
212+
213+
There may be certain log messages that you do not want to be sent. These may be
214+
repetitive log lines that are "noise" that you might not be able to filter out
215+
easily from the respective application. To filter these lines, use the
216+
exclude_patterns with an array or regexes:
217+
218+
exclude_patterns:
219+
- exclude this
220+
- \d+ things
221+
222+
223+
### Multiple instances
224+
225+
Run multiple instances to specify unique syslog hostnames.
226+
227+
To do that, provide an alternate PID path as a command-line option to the
228+
additional instance(s). For example:
229+
230+
--pid-file=/var/run/remote_syslog_2.pid
231+
232+
Note: Daemonized programs use PID files to identify whether the program is already
233+
running ([more](http://unix.stackexchange.com/questions/12815/what-are-pid-and-lock-files-for/12818#12818)). Like other daemons, remote_syslog will refuse to run as a
234+
daemon (the default mode) when a PID file is present. If a .pid file is
235+
present but the daemon is not actually running, remove the PID file.
236+
237+
### Choosing app name
238+
239+
remote_syslog uses the log file name (like "access_log") as the syslog
240+
program name, or what the syslog RFCs call the "tag." This is ideal unless
241+
remote_syslog watches many files that have the same name.
242+
243+
In that case, tell remote_syslog to set another program name by creating
244+
symbolic link to the generically-named file:
245+
246+
cd /path/to/logs
247+
ln -s generic_name.log unique_name.log
248+
249+
Point remote_syslog at unique_name.log. It will use that as the program name.
250+
251+
252+
## Troubleshooting
253+
254+
When running remote_syslog in the foreground using the `-D` switch, if you
255+
receive the error:
256+
257+
Error creating fsnotify watcher: inotify_init: too many open files
258+
259+
determine the maximum number of inotify instances that can be created using:
260+
261+
cat /proc/sys/fs/inotify/max_user_instances
262+
263+
and then increase this limit using:
264+
265+
echo VALUE >> /proc/sys/fs/inotify/max_user_instances
266+
267+
where VALUE is greater than the present setting. Confirm that remote_syslog starts
268+
up and then apply this new value permanently by adding the following to
269+
`/etc/sysctl.conf:`:
270+
271+
fs.inotify.max_user_instances = VALUE
272+
273+
69274
## Reporting bugs
70275

71276
1. See whether the issue has already been reported: <https://github.com/papertrail/remote_syslog2/issues/>

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
mkdir -p $BUILDPATH
88

99
godep go build -o $BUILDPATH/remote_syslog2 .
10-
cp README.md LICENSE example_config.yaml $BUILDPATH
10+
cp README.md LICENSE example_config.yml $BUILDPATH
1111

1212
cd $BUILDPATH/..
1313
rm -f remote_syslog2.tar.gz
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<!-- Put this file in /Library/LaunchDaemons/ -->
4+
<plist version = "1.0">
5+
<dict>
6+
<key>Label</key>
7+
<string>com.papertrailapp.remote_syslog</string>
8+
<key>RunAtLoad</key>
9+
<true/>
10+
<key>KeepAlive</key>
11+
<true/>
12+
<key>UserName</key>
13+
<string>root</string>
14+
<key>ProgramArguments</key>
15+
<array>
16+
<string>remote_syslog</string>
17+
<string>-D</string>
18+
</array>
19+
</dict>
20+
</plist>

examples/log_files.yml.example

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
files:
2+
- /var/log/httpd/access_log
3+
- /var/log/httpd/error_log
4+
- /opt/misc/*.log
5+
- /var/log/mysqld.log
6+
- /var/run/mysqld/mysqld-slow.log
7+
destination:
8+
host: logs.papertrailapp.com
9+
port: 12345 # NOTE: change to your Papertrail port
10+
protocol: tls
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# see README - demonstrates all optional arguments and more glob formats
2+
files:
3+
- /var/log/httpd/access_log
4+
- /var/log/httpd/error_log
5+
- /opt/misc/*.log
6+
- /home/**/*.log
7+
- /var/log/mysqld.log
8+
- /var/run/mysqld/mysqld-slow.log
9+
exclude_files:
10+
- old
11+
- 200\d
12+
hostname: www42 # override OS hostname
13+
exclude_patterns:
14+
- exclude this
15+
- \d+ things
16+
destination:
17+
host: logs.papertrailapp.com
18+
port: 12345 # NOTE: change this to YOUR papertrail port!
19+
protocol: tls
20+
new_file_check_interval: 10 # Check every 10 seconds

0 commit comments

Comments
 (0)