Просмотр исходного кода

Install collectd from package.

Use newer native "write HTTP" plugin to send metrics to Librato, if configured.
Alex Payne 9 лет назад
Родитель
Сommit
d2483d0435

+ 0
- 206
roles/monitoring/files/etc_init.d_collectd Просмотреть файл

@@ -1,206 +0,0 @@
1
-#! /bin/bash
2
-#
3
-# collectd - start and stop the statistics collection daemon
4
-# http://collectd.org/
5
-#
6
-# Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
7
-# Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
8
-#
9
-
10
-### BEGIN INIT INFO
11
-# Provides:          collectd
12
-# Required-Start:    $local_fs $remote_fs
13
-# Required-Stop:     $local_fs $remote_fs
14
-# Should-Start:      $network $named $syslog $time cpufrequtils
15
-# Should-Stop:       $network $named $syslog
16
-# Default-Start:     2 3 4 5
17
-# Default-Stop:      0 1 6
18
-# Short-Description: manage the statistics collection daemon
19
-# Description:       collectd is the statistics collection daemon.
20
-#                    It is a small daemon which collects system information
21
-#                    periodically and provides mechanisms to monitor and store
22
-#                    the values in a variety of ways.
23
-### END INIT INFO
24
-
25
-. /lib/lsb/init-functions
26
-
27
-export PATH=/opt/collectd/sbin:/opt/collectd/bin:/sbin:/bin:/usr/sbin:/usr/bin
28
-
29
-DISABLE=0
30
-
31
-DESC="statistics collection and monitoring daemon"
32
-NAME=collectd
33
-DAEMON=/opt/collectd/sbin/collectd
34
-
35
-CONFIGFILE=/opt/collectd/etc/collectd.conf
36
-PIDFILE=/opt/collectd/var/run/collectd.pid
37
-
38
-USE_COLLECTDMON=1
39
-COLLECTDMON_DAEMON=/opt/collectd/sbin/collectdmon
40
-COLLECTDMON_PIDFILE=/opt/collectd/var/run/collectdmon.pid
41
-
42
-MAXWAIT=30
43
-
44
-# Gracefully exit if the package has been removed.
45
-test -x $DAEMON || exit 0
46
-
47
-if [ -r /etc/default/$NAME ]; then
48
-	. /etc/default/$NAME
49
-fi
50
-
51
-if test "$ENABLE_COREFILES" == 1; then
52
-	ulimit -c unlimited
53
-fi
54
-
55
-if test "$USE_COLLECTDMON" == 1; then
56
-	_PIDFILE="$COLLECTDMON_PIDFILE"
57
-else
58
-	_PIDFILE="$PIDFILE"
59
-fi
60
-
61
-# return:
62
-#   0 if config is fine
63
-#   1 if there is a syntax error
64
-#   2 if there is no configuration
65
-check_config() {
66
-	if test ! -e "$CONFIGFILE"; then
67
-		return 2
68
-	fi
69
-	if ! $DAEMON -t -C "$CONFIGFILE"; then
70
-		return 1
71
-	fi
72
-	return 0
73
-}
74
-
75
-# return:
76
-#   0 if the daemon has been started
77
-#   1 if the daemon was already running
78
-#   2 if the daemon could not be started
79
-#   3 if the daemon was not supposed to be started
80
-d_start() {
81
-	if test "$DISABLE" != 0; then
82
-		# we get here during restart
83
-		log_progress_msg "disabled by /etc/default/$NAME"
84
-		return 3
85
-	fi
86
-
87
-	if test ! -e "$CONFIGFILE"; then
88
-		# we get here during restart
89
-		log_progress_msg "disabled, no configuration ($CONFIGFILE) found"
90
-		return 3
91
-	fi
92
-
93
-	check_config
94
-	rc="$?"
95
-	if test "$rc" -ne 0; then
96
-		log_progress_msg "not starting, configuration error"
97
-		return 2
98
-	fi
99
-
100
-	if test "$USE_COLLECTDMON" == 1; then
101
-		start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
102
-			--exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE" \
103
-			|| return 2
104
-	else
105
-		start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
106
-			--exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE" \
107
-			|| return 2
108
-	fi
109
-	return 0
110
-}
111
-
112
-still_running_warning="
113
-WARNING: $NAME might still be running.
114
-In large setups it might take some time to write all pending data to
115
-the disk. You can adjust the waiting time in /etc/default/collectd."
116
-
117
-# return:
118
-#   0 if the daemon has been stopped
119
-#   1 if the daemon was already stopped
120
-#   2 if daemon could not be stopped
121
-d_stop() {
122
-	PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
123
-
124
-	start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
125
-	rc="$?"
126
-
127
-	if test "$rc" -eq 2; then
128
-		return 2
129
-	fi
130
-
131
-	sleep 1
132
-	if test -n "$PID" && kill -0 $PID 2> /dev/null; then
133
-		i=0
134
-		while kill -0 $PID 2> /dev/null; do
135
-			i=$(( $i + 2 ))
136
-			echo -n " ."
137
-
138
-			if test $i -gt $MAXWAIT; then
139
-				log_progress_msg "$still_running_warning"
140
-				return 2
141
-			fi
142
-
143
-			sleep 2
144
-		done
145
-		return "$rc"
146
-	fi
147
-	return "$rc"
148
-}
149
-
150
-case "$1" in
151
-	start)
152
-		log_daemon_msg "Starting $DESC" "$NAME"
153
-		d_start
154
-		case "$?" in
155
-			0|1) log_end_msg 0 ;;
156
-			2) log_end_msg 1 ;;
157
-			3) log_end_msg 255; true ;;
158
-			*) log_end_msg 1 ;;
159
-		esac
160
-		;;
161
-	stop)
162
-		log_daemon_msg "Stopping $DESC" "$NAME"
163
-		d_stop
164
-		case "$?" in
165
-			0|1) log_end_msg 0 ;;
166
-			2) log_end_msg 1 ;;
167
-		esac
168
-		;;
169
-	status)
170
-		status_of_proc -p "$_PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
171
-		;;
172
-	restart|force-reload)
173
-		log_daemon_msg "Restarting $DESC" "$NAME"
174
-		check_config
175
-		rc="$?"
176
-		if test "$rc" -eq 1; then
177
-			log_progress_msg "not restarting, configuration error"
178
-			log_end_msg 1
179
-			exit 1
180
-		fi
181
-		d_stop
182
-		rc="$?"
183
-		case "$rc" in
184
-			0|1)
185
-				sleep 1
186
-				d_start
187
-				rc2="$?"
188
-				case "$rc2" in
189
-					0|1) log_end_msg 0 ;;
190
-					2) log_end_msg 1 ;;
191
-					3) log_end_msg 255; true ;;
192
-					*) log_end_msg 1 ;;
193
-				esac
194
-				;;
195
-			*)
196
-				log_end_msg 1
197
-				;;
198
-		esac
199
-		;;
200
-	*)
201
-		echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
202
-		exit 3
203
-		;;
204
-esac
205
-
206
-# vim: syntax=sh noexpandtab sw=4 ts=4 :

+ 3
- 61
roles/monitoring/tasks/collectd.yml Просмотреть файл

@@ -1,66 +1,8 @@
1
-- name: Add wheezy-backports to be compatible with Dovecot packages on Debian 7
2
-  apt_repository: repo='deb http://http.debian.net/debian wheezy-backports main'
3
-  when: ansible_distribution_release == 'wheezy'
4
-  tags:
5
-    - dependencies
6
-
7
-- name: Install collectd dependencies on wheezy from backports
8
-  apt: pkg={{ item }} state=installed default_release=wheezy-backports
9
-  with_items:
10
-    - libcurl4-openssl-dev
11
-    - librrd2-dev
12
-    - python-dev
13
-  when: ansible_distribution_release == 'wheezy'
14
-  tags:
15
-    - dependencies
16
-
17
-- name: Install collectd dependencies on distributions other than wheezy
18
-  apt: pkg={{ item }} state=installed
19
-  with_items:
20
-    - libcurl4-openssl-dev
21
-    - librrd2-dev
22
-    - python-dev
23
-  when: ansible_distribution_release != 'wheezy'
24
-  tags:
25
-    - dependencies
26
-
27
-- name: Download collectd
28
-  get_url: url=http://collectd.org/files/collectd-{{collectd_version}}.tar.gz
29
-           dest=/root/collectd-{{collectd_version}}.tar.gz
30
-
31
-- name: Extract collectd
32
-  unarchive: src=/root/collectd-{{collectd_version}}.tar.gz
33
-             dest=/root copy=no
34
-             creates=/root/collectd-{{collectd_version}}
35
-
36
-- name: Build and install collectd
37
-  shell: ./configure ; make all ; make install
38
-         executable=/bin/bash
39
-         chdir=/root/collectd-{{collectd_version}}
40
-         creates=/opt/collectd/sbin/collectdmon
41
-
42
-- name: Copy collectd init file into place
43
-  copy: src=etc_init.d_collectd dest=/etc/init.d/collectd mode=0755
44
-
45
-- name: Download collectd-librato plugin
46
-  get_url: url=https://github.com/librato/collectd-librato/archive/v{{collectd_librato_version}}.tar.gz
47
-           dest=/root/collectd-librato-{{collectd_librato_version}}.tar.gz
48
-  when: collectd_librato_email|length > 0
49
-
50
-- name: Extract collectd-librato plugin
51
-  unarchive: src=/root/collectd-librato-{{collectd_librato_version}}.tar.gz
52
-             dest=/root copy=no
53
-             creates=/root/collectd-librato-{{collectd_librato_version}}
54
-  when: collectd_librato_email|length > 0
55
-
56
-- name: Install collectd-librato plugin
57
-  command: make install
58
-           chdir=/root/collectd-librato-{{collectd_librato_version}}
59
-           creates=/opt/collectd-librato-{{collectd_librato_version}}
60
-  when: collectd_librato_email|length > 0
1
+- name: Install collectd
2
+  apt: pkg=collectd state=installed
61 3
 
62 4
 - name: Copy collectd configuration file into place
63
-  template: src=opt_etc_collectd.conf.j2 dest=/opt/collectd/etc/collectd.conf
5
+  template: src=etc_collectd_collectd.conf.j2 dest=/etc/collectd/collectd.conf
64 6
   notify: restart collectd
65 7
 
66 8
 - name: Ensure collectd is a system service

roles/monitoring/templates/opt_etc_collectd.conf.j2 → roles/monitoring/templates/etc_collectd_collectd.conf.j2 Просмотреть файл

@@ -1,4 +1,4 @@
1
-BaseDir     "/opt/collectd"
1
+BaseDir "/etc/collectd"
2 2
 
3 3
 LoadPlugin syslog
4 4
 LoadPlugin cpu
@@ -7,26 +7,23 @@ LoadPlugin load
7 7
 LoadPlugin memory
8 8
 LoadPlugin disk
9 9
 LoadPlugin df
10
+LoadPlugin rrdtool
11
+
12
+<Plugin rrdtool>
13
+  DataDir "/opt/collectd/var/lib/collectd/rrd"
14
+</Plugin>
10 15
 
11 16
 {% if (collectd_librato_email|length and collectd_librato_api_token|length) %}
12 17
 <LoadPlugin python>
13 18
   Globals true
14 19
 </LoadPlugin>
15 20
 
16
-<Plugin python>
17
-  ModulePath "/opt/collectd-librato-{{ collectd_librato_version }}/lib"
18
-  Import "collectd-librato"
19
-
20
-  <Module "collectd-librato">
21
-    Email    "{{ collectd_librato_email }}"
22
-    APIToken "{{ collectd_librato_api_token }}"
23
-    TypesDB  "/opt/collectd/share/collectd/types.db"
24
-  </Module>
25
-</Plugin>
26
-{% else %}
27
-LoadPlugin rrdtool
28
-
29
-<Plugin rrdtool>
30
-  DataDir "/opt/collectd/var/lib/collectd/rrd"
21
+<Plugin write_http>
22
+  <URL "https://collectd.librato.com/v1/measurements">
23
+    User "{{ collectd_librato_email }}"
24
+    Password "{{ collectd_librato_api_token }}"
25
+    Format "JSON"
26
+  </URL>
31 27
 </Plugin>
32 28
 {% endif %}
29
+

Загрузка…
Отмена
Сохранить