@@ -22,9 +22,10 @@ POSTGRES_EXPORTER_PIDFILE=/tmp/postgres_exporter.pid
2222CONFIG_DIR=' /opt/cpm/conf'
2323QUERIES=(
2424 queries_backrest
25- queries_common
25+ queries_global
2626 queries_per_db
2727 queries_nodemx
28+ queries_pg_stat_statements_reset
2829)
2930
3031function trap_sigterm() {
@@ -118,103 +119,87 @@ else
118119 then
119120 cat ${CONFIG_DIR?} /${query?} .yml >> /tmp/queries.yml
120121 else
121- echo_err " Custom Query file ${query?} .yml does not exist (it should).."
122+ echo_err " Query file ${query?} .yml does not exist (it should).."
122123 exit 1
123124 fi
124125 done
125126
126127 VERSION=$( PGPASSWORD=" ${EXPORTER_PG_PASSWORD} " ${PG_DIR?} /bin/psql -h " ${EXPORTER_PG_HOST} " -p " ${EXPORTER_PG_PORT} " -U " ${EXPORTER_PG_USER} " -qtAX -c " SELECT current_setting('server_version_num')" " ${EXPORTER_PG_DATABASE} " )
127- if (( ${VERSION?} >= 90500 )) && (( ${VERSION?} < 90600 ))
128+ if (( ${VERSION?} >= 90600 )) && (( ${VERSION?} < 100000 ))
128129 then
129- if [[ -f ${CONFIG_DIR?} /queries_pg95 .yml ]]
130+ if [[ -f ${CONFIG_DIR?} /pg96/queries_general .yml ]]
130131 then
131- cat ${CONFIG_DIR?} /queries_pg95 .yml >> /tmp/queries.yml
132+ cat ${CONFIG_DIR?} /pg96/queries_general .yml >> /tmp/queries.yml
132133 else
133- echo_err " Custom Query file queries_pg95.yml does not exist (it should).."
134- fi
135- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg95.yml ]]
136- then
137- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg95.yml >> /tmp/queries.yml
138- else
139- echo_warn " Custom Query file queries_pg_stat_statements_pg95.yml not loaded."
140- fi
141- elif (( ${VERSION?} >= 90600 )) && (( ${VERSION?} < 100000 ))
142- then
143- if [[ -f ${CONFIG_DIR?} /queries_pg96.yml ]]
144- then
145- cat ${CONFIG_DIR?} /queries_pg96.yml >> /tmp/queries.yml
146- else
147- echo_err " Custom Query file queries_pg96.yml does not exist (it should).."
148- fi
149- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg96.yml ]]
150- then
151- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg96.yml >> /tmp/queries.yml
152- else
153- echo_warn " Custom Query file queries_pg_stat_statements_pg96.yml not loaded."
134+ echo_err " Query file queries_general.yml does not exist (it should).."
154135 fi
155136 elif (( ${VERSION?} >= 100000 )) && (( ${VERSION?} < 110000 ))
156137 then
157- if [[ -f ${CONFIG_DIR?} /queries_pg10 .yml ]]
138+ if [[ -f ${CONFIG_DIR?} /pg10/queries_general .yml ]]
158139 then
159- cat ${CONFIG_DIR?} /queries_pg10 .yml >> /tmp/queries.yml
140+ cat ${CONFIG_DIR?} /pg10/queries_general .yml >> /tmp/queries.yml
160141 else
161- echo_err " Custom Query file queries_pg10 .yml does not exist (it should).."
142+ echo_err " Query file queries_general .yml does not exist (it should).."
162143 fi
163- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg10 .yml ]]
144+ if [[ -f ${CONFIG_DIR?} /pg10/queries_pg_stat_statements .yml ]]
164145 then
165- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg10 .yml >> /tmp/queries.yml
146+ cat ${CONFIG_DIR?} /pg10/queries_pg_stat_statements .yml >> /tmp/queries.yml
166147 else
167- echo_warn " Custom Query file queries_pg_stat_statements_pg10 .yml not loaded."
148+ echo_warn " Query file queries_pg_stat_statements .yml not loaded."
168149 fi
169150 elif (( ${VERSION?} >= 110000 )) && (( ${VERSION?} < 120000 ))
170151 then
171- if [[ -f ${CONFIG_DIR?} /queries_pg11 .yml ]]
152+ if [[ -f ${CONFIG_DIR?} /pg11/queries_general .yml ]]
172153 then
173- cat ${CONFIG_DIR?} /queries_pg11 .yml >> /tmp/queries.yml
154+ cat ${CONFIG_DIR?} /pg11/queries_general .yml >> /tmp/queries.yml
174155 else
175- echo_err " Custom Query file queries_pg11 .yml does not exist (it should).."
156+ echo_err " Query file queries_general .yml does not exist (it should).."
176157 fi
177- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg11 .yml ]]
158+ if [[ -f ${CONFIG_DIR?} /pg11/queries_pg_stat_statements .yml ]]
178159 then
179- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg11 .yml >> /tmp/queries.yml
160+ cat ${CONFIG_DIR?} /pg11/queries_pg_stat_statements .yml >> /tmp/queries.yml
180161 else
181- echo_warn " Custom Query file queries_pg_stat_statements_pg11 .yml not loaded."
162+ echo_warn " Query file queries_pg_stat_statements .yml not loaded."
182163 fi
183164 elif (( ${VERSION?} >= 120000 )) && (( ${VERSION?} < 130000 ))
184165 then
185- if [[ -f ${CONFIG_DIR?} /queries_pg12 .yml ]]
166+ if [[ -f ${CONFIG_DIR?} /pg12/queries_general .yml ]]
186167 then
187- cat ${CONFIG_DIR?} /queries_pg12 .yml >> /tmp/queries.yml
168+ cat ${CONFIG_DIR?} /pg12/queries_general .yml >> /tmp/queries.yml
188169 else
189- echo_err " Custom Query file queries_pg12 .yml does not exist (it should).."
170+ echo_err " Query file queries_general .yml does not exist (it should).."
190171 fi
191- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg12 .yml ]]
172+ if [[ -f ${CONFIG_DIR?} /pg12/queries_pg_stat_statements .yml ]]
192173 then
193- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg12 .yml >> /tmp/queries.yml
174+ cat ${CONFIG_DIR?} /pg12/queries_pg_stat_statements .yml >> /tmp/queries.yml
194175 else
195- echo_warn " Custom Query file queries_pg_stat_statements_pg12 .yml not loaded."
176+ echo_warn " Query file queries_pg_stat_statements .yml not loaded."
196177 fi
197- elif (( ${VERSION?} >= 130000 ))
178+ elif (( ${VERSION?} >= 130000 ))
198179 then
199- if [[ -f ${CONFIG_DIR?} /queries_pg13 .yml ]]
180+ if [[ -f ${CONFIG_DIR?} /pg13/queries_general .yml ]]
200181 then
201- cat ${CONFIG_DIR?} /queries_pg13 .yml >> /tmp/queries.yml
182+ cat ${CONFIG_DIR?} /pg13/queries_general .yml >> /tmp/queries.yml
202183 else
203- echo_err " Custom Query file queries_pg13 .yml does not exist (it should).."
184+ echo_err " Query file queries_general .yml does not exist (it should).."
204185 fi
205- if [[ -f ${CONFIG_DIR?} /queries_pg_stat_statements_pg13 .yml ]]
186+ if [[ -f ${CONFIG_DIR?} /pg13/queries_pg_stat_statements .yml ]]
206187 then
207- cat ${CONFIG_DIR?} /queries_pg_stat_statements_pg13 .yml >> /tmp/queries.yml
188+ cat ${CONFIG_DIR?} /pg13/queries_pg_stat_statements .yml >> /tmp/queries.yml
208189 else
209- echo_warn " Custom Query file queries_pg_stat_statements_pg13 .yml not loaded."
190+ echo_warn " Query file queries_pg_stat_statements .yml not loaded."
210191 fi
211192 else
212193 echo_err " Unknown or unsupported version of PostgreSQL. Exiting.."
213194 exit 1
214195 fi
215196fi
216197
217- sed -i -e " s/#PGBACKREST_INFO_THROTTLE_MINUTES#/${PGBACKREST_INFO_THROTTLE_MINUTES:- 10} /g" -e " s/#PG_STAT_STATEMENTS_LIMIT#/${PG_STAT_STATEMENTS_LIMIT:- 20} /g" /tmp/queries.yml
198+ sed -i \
199+ -e " s/#PGBACKREST_INFO_THROTTLE_MINUTES#/${PGBACKREST_INFO_THROTTLE_MINUTES:- 10} /g" \
200+ -e " s/#PG_STAT_STATEMENTS_LIMIT#/${PG_STAT_STATEMENTS_LIMIT:- 20} /g" \
201+ -e " s/#PG_STAT_STATEMENTS_THROTTLE_MINUTES#/${PG_STAT_STATEMENTS_THROTTLE_MINUTES:- -1} /g" \
202+ /tmp/queries.yml
218203
219204PG_OPTIONS=" --extend.query-path=${QUERY_DIR?} /queries.yml --web.listen-address=:${POSTGRES_EXPORTER_PORT} "
220205
0 commit comments