blob: 2c5b39080a6bd34864155974c6ef0bf3acadf452 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#!/bin/sh
# $FreeBSD$
#
# $Id: mysqlard.server.sh 40 2006-01-20 20:26:11Z dewitge $
#
# MySQL Activity Report
# mysqlard Start script for the MySQL Activity Report Daemon
#
# Copyright 2004 Gert Dewit <gert.dewit@sos.be>
#
# chkconfig: - 79 11
# description: MySQL Activity Report Daemon
# processname: mysqlard
# config: %%PREFIX%%/etc/mysqlard.cnf
# pidfile: /var/run/mysqlard.pid
. /etc/rc.subr
# Source the config script
if [ -z "$datadir" ] ; then
echo Loading defaultsettings
. %%PREFIX%%/etc/mysqlard.cnf
fi
########################################################################
# Options, change them in %%PREFIX%%/etc/mysqlard.cnf or you can override
# them here, but that's not recommended. Read the comments in
# %%PREFIX%%/etc/mysqlard.cnf if you want to know what you're changing.
step=${step:="60"}
minsamples=${minsamples:="720"}
datadir=${datadir:="%%PREFIX%%/www/mysqlard"}
pidfile=/var/run/mysqlard.pid
RRDTOOL=${RRDTOOL:="%%PREFIX%%/bin/rrdtool"}
MYSQLARD=${MYSQLARD:="%%PREFIX%%/sbin/mysqlard"}
MYSQLUSER=${MYSQLUSER:="mysqlar"}
MYSQLHOST=${MYSQLHOST:=""}
########################################################################
# don't change anything below this line, but heck, I can't stop you ;-)
confile=${confile:="${datadir}/connections.rrd"}
tabfile=${tabfile:="${datadir}/table_cache.rrd"}
keyfile=${keyfile:="${datadir}/key_cache.rrd"}
queryfile=${queryfile:="${datadir}/queries.rrd"}
slavefile=${slavefile:="${datadir}/slave.rrd"}
slaveopt=
if [ -n "$slave" ]; then
slaveopt=-L
fi
if [ -n "$MYSQLHOST" ] ; then
MYSQLHOST=--host=$MYSQLHOST
fi
# functions
avgsamps () {
avg=$(($1 / $2))
if [ ${avg} -lt 1 ]
then
avg=1
fi
echo ${avg}
}
archives () {
arch=$(($1 / $2))
if [ $(($2 * ${arch} * $3)) -lt $4 ]
then
arch=$((${arch} + 1))
fi
echo ${arch}
}
# calculated values
heartbeat=$((${step} * 2))
hoursamps=$((3600 / ${step}))
houravgs=$(avgsamps ${hoursamps} ${minsamples})
hourarchives=$(archives ${hoursamps} ${houravgs} ${step} 3600)
daysamps=$((86400 / ${step}))
dayavgs=$(avgsamps ${daysamps} ${minsamples})
dayarchives=$(archives ${daysamps} ${dayavgs} ${step} 86400)
weeksamps=$((604800 / ${step}))
weekavgs=$(avgsamps ${weeksamps} ${minsamples})
weekarchives=$(archives ${weeksamps} ${weekavgs} ${step} 604800)
monthsamps=$((2678400 / ${step}))
monthavgs=$(avgsamps ${monthsamps} ${minsamples})
montharchives=$(archives ${monthsamps} ${monthavgs} ${step} 2678400)
yearsamps=$((31622400 / ${step}))
yearavgs=$(avgsamps ${yearsamps} ${minsamples})
yeararchives=$(archives ${yearsamps} ${yearavgs} ${step} 31622400)
# calculated RRA's
hourrra="RRA:AVERAGE:0.5:${houravgs}:${hourarchives}"
dayrra="RRA:AVERAGE:0.5:${dayavgs}:${dayarchives}"
weekrra="RRA:AVERAGE:0.5:${weekavgs}:${weekarchives}"
monthrra="RRA:AVERAGE:0.5:${monthavgs}:${montharchives}"
yearrra="RRA:AVERAGE:0.5:${yearavgs}:${yeararchives}"
allrras="${hourrra} ${dayrra} ${weekrra} ${monthrra} ${yearrra}"
initrrd () {
if [ ! -f ${confile} ]
then
${RRDTOOL} create ${confile} --step ${step} \
DS:threads_connected:GAUGE:${heartbeat}:0:U \
DS:max_connections:GAUGE:${heartbeat}:0:U \
${allrras}
fi
if [ ! -f ${tabfile} ]
then
${RRDTOOL} create ${tabfile} --step ${step} \
DS:open_tables:GAUGE:${heartbeat}:0:U \
DS:table_cache:GAUGE:${heartbeat}:0:U \
DS:created_tmp_tables:COUNTER:${heartbeat}:0:U \
DS:created_tmp_disk_t:COUNTER:${heartbeat}:0:U \
${allrras}
fi
if [ ! -f ${keyfile} ]
then
${RRDTOOL} create ${keyfile} --step ${step} \
DS:key_reads:COUNTER:${heartbeat}:0:U \
DS:key_read_requests:COUNTER:${heartbeat}:0:U \
DS:key_buffer_size:GAUGE:${heartbeat}:0:U \
DS:key_blocks_used:GAUGE:${heartbeat}:0:U \
DS:select_full_join:COUNTER:${heartbeat}:0:U \
DS:select_range_check:COUNTER:${heartbeat}:0:U \
DS:handler_read_key:COUNTER:${heartbeat}:0:U \
DS:handler_read_rnd:COUNTER:${heartbeat}:0:U \
DS:slow_queries:COUNTER:${heartbeat}:0:U \
${allrras}
fi
if [ ! -f ${queryfile} ]
then
${RRDTOOL} create ${queryfile} --step ${step} \
DS:questions:COUNTER:${heartbeat}:0:U \
DS:com_select:COUNTER:${heartbeat}:0:U \
DS:com_insert:COUNTER:${heartbeat}:0:U \
DS:com_update:COUNTER:${heartbeat}:0:U \
DS:com_delete:COUNTER:${heartbeat}:0:U \
${allrras}
fi
if [ ! -f ${slavefile} ]
then
${RRDTOOL} create ${slavefile} --step ${step} \
DS:read_master_log_pos:COUNTER:${heartbeat}:0:U \
DS:exec_master_log_pos:COUNTER:${heartbeat}:0:U \
${allrras}
fi
}
status() {
if [ -f $pidfile ]
then
echo $0 is running. PID `cat ${pidfile}`
else
echo $0 is not running.
fi
}
case "$1" in
start)
initrrd
${MYSQLARD} --step=${step} --datadir=${datadir} --user=${MYSQLUSER}
$MYSQLHOST --pidfile=${pidfile} ${slaveopt}
;;
stop)
kill `cat ${pidfile}`
rm -f ${pidfile}
;;
initrrd)
initrrd
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|status|initrrd}"
exit 1
esac
exit $?
|