Compare commits

...

4 Commits

Author SHA1 Message Date
Joachim Desroches 81c9288e96
Make the exporter listen on IPv6. 2022-09-15 15:28:33 +02:00
Joachim Desroches dd8323939e
Connect to PSQL database. 2021-09-27 15:35:20 +02:00
Joachim Desroches b36749db03
Use clang-format. 2021-09-27 14:48:30 +02:00
Joachim Desroches d26b6b0b4a
Try rewriting in C. 2021-09-27 14:46:40 +02:00
3 changed files with 35 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
exporter

32
exporter.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#define USER "odoo"
#define HTTP_PORT 9402
#define INTERVAL 10
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stdout, "Invalid number of arguments. Usage: %s [dbname]\n",
argv[0]);
exit(EXIT_FAILURE);
}
/* Setup database connection parameters */
char connstring[STRLEN];
sprintf(connstring, "database = %s, user = %s", argv[1], USER);
/* Connect to the database */
PGconn *conn = PQconnectdb(connstring);
if (conn == NULL) {
fprintf(stderr, "Out of memory connecting the PostgreSQL\n.");
exit(EXIT_FAILURE);
} else if (PQstatus(conn) != CONNECTION_OK) {
fprintf(stderr, PQerrorMessage(conn));
PQfinish(conn);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}

View File

@ -10,6 +10,7 @@ import sys
USER = "odoo"
HTTP_HOST = "::"
HTTP_PORT = 9402
INTERVAL = 10
@ -26,7 +27,7 @@ if __name__ == '__main__':
"Remaining days before Odoo license expiration")
# Serve metrics over HTTP
start_http_server(HTTP_PORT)
start_http_server(host=HTTP_HOST, port=HTTP_PORT)
# Open connection
with psycopg2.connect(database=DBNAME, user=USER) as conn: