-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 56d1c24
Showing
15 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
builds: | ||
16318fd8b9dea2a69c153199dec6e382c035e233: | ||
version: 16318fd8b9dea2a69c153199dec6e382c035e233 | ||
sha1: a8b114a4f220ad570299318f5cece01ffbebd8c0 | ||
blobstore_id: 26a67da1-70ab-4ad7-92c3-922ed66d0e69 | ||
format-version: '2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
builds: | ||
11d238e06a154b9a8539712c54432ffc968bf7c5: | ||
version: 11d238e06a154b9a8539712c54432ffc968bf7c5 | ||
sha1: a63307c67af09d5a936c8f0180521727ad3ffa14 | ||
blobstore_id: ace8c27e-4c19-4f0e-80c8-58787ec9225f | ||
format-version: '2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
config/dev.yml | ||
config/private.yml | ||
config/settings.yml | ||
releases/*.tgz | ||
releases/**/*.tgz | ||
dev_releases | ||
.blobs | ||
blobs | ||
.dev_builds | ||
.idea | ||
.DS_Store | ||
.final_builds/jobs/**/*.tgz | ||
.final_builds/packages/**/*.tgz | ||
*.swp | ||
*~ | ||
|
||
/deployments | ||
.torus.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
telegraf/telegraf-1.2.1_linux_amd64.tar.gz: | ||
object_id: e61a55cf-53f9-46d3-9a02-279e82f424e1 | ||
sha: 5c61cabe4ac5c5fde972262194dd26e561cd8579 | ||
size: 9635266 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
blobstore: | ||
provider: s3 | ||
options: | ||
bucket_name: bosh-release-telegraf | ||
final_name: c-telegraf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
check process telegraf-system | ||
with pidfile /var/vcap/sys/run/telegraf-system/telegraf-system.pid | ||
start program "/var/vcap/jobs/telegraf-system/bin/telegraf-system_ctl start" | ||
stop program "/var/vcap/jobs/telegraf-system/bin/telegraf-system_ctl stop" | ||
group vcap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
name: telegraf-system | ||
|
||
templates: | ||
bin/telegraf-system_ctl: bin/telegraf-system_ctl | ||
bin/pid_utils.sh: bin/pid_utils.sh | ||
config/telegraf.conf.erb: config/telegraf.conf | ||
|
||
packages: | ||
- telegraf | ||
|
||
properties: | ||
telegraf.tags: | ||
description: Telegraf global tags as a dictionary | ||
default: {} | ||
|
||
telegraf.influxdb.url: | ||
description: InfluxDB url | ||
default: http://localhost:8086 | ||
telegraf.influxdb.database: | ||
description: InfluxDB database | ||
default: system | ||
telegraf.influxdb.retention_policy: | ||
description: InfluxDB database retention policy | ||
default: autogen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
SCRIPT=$(basename $0) | ||
mkdir -p /var/vcap/sys/log/monit | ||
|
||
exec 1>> /var/vcap/sys/log/monit/$SCRIPT.log | ||
exec 2>> /var/vcap/sys/log/monit/$SCRIPT.err.log | ||
|
||
echo "------------ `basename $0` $* at `date` --------------" | tee /dev/stderr | ||
|
||
function pid_is_running() { | ||
declare pid="$1" | ||
ps -p "${pid}" >/dev/null 2>&1 | ||
} | ||
|
||
# pid_guard | ||
# | ||
# @param pidfile | ||
# @param name [String] an arbitrary name that might show up in STDOUT on errors | ||
# | ||
# Run this before attempting to start new processes that may use the same :pidfile:. | ||
# If an old process is running on the pid found in the :pidfile:, exit 1. Otherwise, | ||
# remove the stale :pidfile: if it exists. | ||
# | ||
function pid_guard() { | ||
declare pidfile="$1" name="$2" | ||
|
||
echo "------------ STARTING $(basename "$0") at $(date) --------------" | tee /dev/stderr | ||
|
||
if [ ! -f "${pidfile}" ]; then | ||
return 0 | ||
fi | ||
|
||
local pid | ||
pid=$(head -1 "${pidfile}") | ||
|
||
if pid_is_running "${pid}"; then | ||
echo "${name} is already running, please stop it first" | ||
exit 1 | ||
fi | ||
|
||
echo "Removing stale pidfile" | ||
rm "${pidfile}" | ||
} | ||
|
||
# wait_pid_death | ||
# | ||
# @param pid | ||
# @param timeout | ||
# | ||
# Watch a :pid: for :timeout: seconds, waiting for it to die. | ||
# If it dies before :timeout:, exit 0. If not, exit 1. | ||
# | ||
# Note that this should be run in a subshell, so that the current | ||
# shell does not exit. | ||
# | ||
function wait_pid_death() { | ||
declare pid="$1" timeout="$2" | ||
|
||
local countdown | ||
countdown=$(( timeout * 10 )) | ||
|
||
while true; do | ||
if ! pid_is_running "${pid}"; then | ||
return 0 | ||
fi | ||
|
||
if [ ${countdown} -le 0 ]; then | ||
return 1 | ||
fi | ||
|
||
countdown=$(( countdown - 1 )) | ||
sleep 0.1 | ||
done | ||
} | ||
|
||
# kill_and_wait | ||
# | ||
# @param pidfile | ||
# @param timeout [default 25s] | ||
# | ||
# For a pid found in :pidfile:, send a `kill -6`, then wait for :timeout: seconds to | ||
# see if it dies on its own. If not, send it a `kill -9`. If the process does die, | ||
# exit 0 and remove the :pidfile:. If after all of this, the process does not actually | ||
# die, exit 1. | ||
# | ||
# Note: | ||
# Monit default timeout for start/stop is 30s | ||
# Append 'with timeout {n} seconds' to monit start/stop program configs | ||
# | ||
function kill_and_wait() { | ||
declare pidfile="$1" timeout="${2:-25}" sigkill_on_timeout="${3:-1}" | ||
|
||
if [ ! -f "${pidfile}" ]; then | ||
echo "Pidfile ${pidfile} doesn't exist" | ||
exit 0 | ||
fi | ||
|
||
local pid | ||
pid=$(head -1 "${pidfile}") | ||
|
||
if [ -z "${pid}" ]; then | ||
echo "Unable to get pid from ${pidfile}" | ||
exit 1 | ||
fi | ||
|
||
if ! pid_is_running "${pid}"; then | ||
echo "Process ${pid} is not running" | ||
rm -f "${pidfile}" | ||
exit 0 | ||
fi | ||
|
||
echo "Killing ${pidfile}: ${pid} " | ||
kill "${pid}" | ||
|
||
if ! wait_pid_death "${pid}" "${timeout}"; then | ||
if [ "${sigkill_on_timeout}" = "1" ]; then | ||
echo "Kill timed out, using kill -9 on ${pid}" | ||
kill -9 "${pid}" | ||
sleep 0.5 | ||
fi | ||
fi | ||
|
||
if pid_is_running "${pid}"; then | ||
echo "Timed Out" | ||
exit 1 | ||
else | ||
echo "Stopped" | ||
rm -f "${pidfile}" | ||
fi | ||
} | ||
|
||
check_mount() { | ||
opts=$1 | ||
exports=$2 | ||
mount_point=$3 | ||
|
||
if grep -qs $mount_point /proc/mounts; then | ||
echo "Found NFS mount $mount_point" | ||
else | ||
echo "Mounting NFS..." | ||
mount $opts $exports $mount_point | ||
if [ $? != 0 ]; then | ||
echo "Cannot mount NFS from $exports to $mount_point, exiting..." | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
# Check the syntax of a sudoers file. | ||
check_sudoers() { | ||
/usr/sbin/visudo -c -f "$1" | ||
} | ||
|
||
# Check the syntax of a sudoers file and if it's ok install it. | ||
install_sudoers() { | ||
src="$1" | ||
dest="$2" | ||
|
||
check_sudoers "$src" | ||
|
||
if [ $? -eq 0 ]; then | ||
chown root:root "$src" | ||
chmod 0440 "$src" | ||
cp -p "$src" "$dest" | ||
else | ||
echo "Syntax error in sudoers file $src" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Add a line to a file if it is not already there. | ||
file_must_include() { | ||
file="$1" | ||
line="$2" | ||
|
||
# Protect against empty $file so it doesn't wait for input on stdin. | ||
if [ -n "$file" ]; then | ||
grep --quiet "$line" "$file" || echo "$line" >> "$file" | ||
else | ||
echo 'File name is required' | ||
exit 1 | ||
fi | ||
} | ||
|
||
running_in_container() { | ||
grep -q -E '/instance|/docker/' /proc/self/cgroup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash -eu | ||
|
||
JOB_NAME=telegraf-system | ||
|
||
JOB_DIR=/var/vcap/jobs/$JOB_NAME | ||
RUN_DIR=/var/vcap/sys/run/$JOB_NAME | ||
LOG_DIR=/var/vcap/sys/log/$JOB_NAME | ||
PIDFILE=$RUN_DIR/$JOB_NAME.pid | ||
|
||
source $JOB_DIR/bin/pid_utils.sh | ||
|
||
case $1 in | ||
start) | ||
pid_guard $PIDFILE $JOB_NAME | ||
|
||
mkdir -p $RUN_DIR | ||
mkdir -p $LOG_DIR | ||
|
||
PATH=/var/vcap/packages/telegraf/bin:$PATH | ||
|
||
# check configuration | ||
echo "checking telegraf configuration..." | ||
telegraf --config $JOB_DIR/config/telegraf.conf --test > /dev/null | ||
echo "telegraf configuration OK" | ||
echo | ||
|
||
# store pid in $PIDFILE | ||
echo $$ > $PIDFILE | ||
|
||
exec telegraf \ | ||
--config $JOB_DIR/config/telegraf.conf \ | ||
>>$LOG_DIR/$JOB_NAME.log 2>&1 | ||
|
||
;; | ||
|
||
stop) | ||
kill_and_wait $PIDFILE | ||
;; | ||
|
||
*) | ||
echo "Usage: ctl {start|stop}" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[global_tags] | ||
service = "<%= spec.deployment.sub(/-[0-9a-f]{20}$/, '') %>" | ||
node_type = "<%= spec.name %>" | ||
instance = "<%= spec.index %>" | ||
<% if_p("telegraf.tags") do |tags| tags.each do |tag, value| %> | ||
<%= tag %> = "<%= value %>" | ||
<% end; end %> | ||
|
||
[agent] | ||
interval = "1m" | ||
flush_interval = "1m" | ||
flush_jitter = "15s" | ||
|
||
[[outputs.influxdb]] | ||
urls = ["<%= p("telegraf.influxdb.url") %>"] | ||
database = "<%= p("telegraf.influxdb.database") %>" | ||
retention_policy = "<%= p("telegraf.influxdb.retention_policy") %>" | ||
|
||
[[inputs.cpu]] | ||
percpu = false | ||
totalcpu = true | ||
[[inputs.disk]] | ||
ignore_fs = ["tmpfs", "devtmpfs", "none"] | ||
[[inputs.diskio]] | ||
devices = ["sda", "sdb", "sdc"] | ||
[[inputs.kernel]] | ||
[[inputs.mem]] | ||
[[inputs.processes]] | ||
[[inputs.swap]] | ||
[[inputs.system]] | ||
[[inputs.net]] | ||
[[inputs.netstat]] | ||
[[inputs.nstat]] | ||
dump_zeros = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -u | ||
|
||
tar xfz telegraf/telegraf-*.tar.gz \ | ||
--strip-components 3 \ | ||
--wildcards \ | ||
-C $BOSH_INSTALL_TARGET './*/usr/bin/telegraf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
name: telegraf | ||
files: | ||
- telegraf/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
packages: | ||
- name: telegraf | ||
version: 11d238e06a154b9a8539712c54432ffc968bf7c5 | ||
fingerprint: 11d238e06a154b9a8539712c54432ffc968bf7c5 | ||
sha1: a63307c67af09d5a936c8f0180521727ad3ffa14 | ||
dependencies: [] | ||
jobs: | ||
- name: telegraf-system | ||
version: 16318fd8b9dea2a69c153199dec6e382c035e233 | ||
fingerprint: 16318fd8b9dea2a69c153199dec6e382c035e233 | ||
sha1: a8b114a4f220ad570299318f5cece01ffbebd8c0 | ||
commit_hash: 80f31f96 | ||
uncommitted_changes: true | ||
name: c-telegraf | ||
version: '1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
builds: | ||
a8b815c2-9a70-4860-b921-1a07538305cc: | ||
version: '1' | ||
format-version: '2' |
Empty file.