summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_pgsql.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 54d2d58..d3116b0 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -147,7 +147,9 @@ main (int argc, char **argv)
147 PGconn *conn; 147 PGconn *conn;
148 char *conninfo = NULL; 148 char *conninfo = NULL;
149 149
150 int elapsed_time; 150 struct timeval start_timeval;
151 struct timeval end_timeval;
152 double elapsed_time;
151 int status = STATE_UNKNOWN; 153 int status = STATE_UNKNOWN;
152 int query_status = STATE_UNKNOWN; 154 int query_status = STATE_UNKNOWN;
153 155
@@ -199,13 +201,19 @@ main (int argc, char **argv)
199 asprintf (&conninfo, "%s password = '%s'", conninfo, pgpasswd); 201 asprintf (&conninfo, "%s password = '%s'", conninfo, pgpasswd);
200 202
201 /* make a connection to the database */ 203 /* make a connection to the database */
202 time (&start_time); 204 gettimeofday (&start_timeval, NULL);
203 conn = PQconnectdb (conninfo); 205 conn = PQconnectdb (conninfo);
204 time (&end_time); 206 gettimeofday (&end_timeval, NULL);
205 elapsed_time = (int) (end_time - start_time); 207
208 while (start_timeval.tv_usec > end_timeval.tv_usec) {
209 --end_timeval.tv_sec;
210 end_timeval.tv_usec += 1000000;
211 }
212 elapsed_time = (double)(end_timeval.tv_sec - start_timeval.tv_sec)
213 + (double)(end_timeval.tv_usec - start_timeval.tv_usec) / 1000000.0;
206 214
207 if (verbose) 215 if (verbose)
208 printf("Time elapsed: %d\n", elapsed_time); 216 printf("Time elapsed: %f\n", elapsed_time);
209 217
210 /* check to see that the backend connection was successfully made */ 218 /* check to see that the backend connection was successfully made */
211 if (verbose) 219 if (verbose)
@@ -239,10 +247,10 @@ main (int argc, char **argv)
239 PQprotocolVersion (conn), PQbackendPID (conn)); 247 PQprotocolVersion (conn), PQbackendPID (conn));
240 } 248 }
241 249
242 printf (_(" %s - database %s (%d sec.)|%s\n"), 250 printf (_(" %s - database %s (%f sec.)|%s\n"),
243 state_text(status), dbName, elapsed_time, 251 state_text(status), dbName, elapsed_time,
244 fperfdata("time", elapsed_time, "s", 252 fperfdata("time", elapsed_time, "s",
245 (int)twarn, twarn, (int)tcrit, tcrit, TRUE, 0, FALSE,0)); 253 !!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, TRUE, 0, FALSE,0));
246 254
247 if (pgquery) 255 if (pgquery)
248 query_status = do_query (conn, pgquery); 256 query_status = do_query (conn, pgquery);