Skip to content

Commit

Permalink
[#3] OS/CPU/Memory information
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 25, 2022
1 parent 4edb103 commit 2539c1c
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sql/pgexporter_ext--0.1.0.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
CREATE FUNCTION pgexporter_used_space(text) RETURNS bigint
AS '$libdir/pgexporter_ext'
LANGUAGE C IMMUTABLE STRICT;
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_used_space FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_used_space TO pg_monitor;

CREATE FUNCTION pgexporter_free_space(text) RETURNS bigint
AS '$libdir/pgexporter_ext'
LANGUAGE C IMMUTABLE STRICT;
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_free_space FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_free_space TO pg_monitor;

CREATE FUNCTION pgexporter_total_space(text) RETURNS bigint
AS '$libdir/pgexporter_ext'
LANGUAGE C IMMUTABLE STRICT;
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_total_space FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_total_space TO pg_monitor;
52 changes: 52 additions & 0 deletions sql/pgexporter_ext--0.1.1--0.2.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CREATE FUNCTION pgexporter_version() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_version FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_version TO pg_monitor;

CREATE FUNCTION pgexporter_os_info(OUT name text,
OUT version text,
OUT architecture text,
OUT host_name text,
OUT domain_name text,
OUT process_count int,
OUT uptime_seconds int
)
RETURNS SETOF record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_os_info FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_os_info TO pg_monitor;

CREATE FUNCTION pgexporter_cpu_info(OUT vendor text,
OUT model_name text,
OUT number_of_cores int,
OUT clock_speed_hz int8,
OUT l1dcache_size int,
OUT l1icache_size int,
OUT l2cache_size int,
OUT l3cache_size int
)
RETURNS SETOF record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_cpu_info FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_cpu_info TO pg_monitor;

CREATE FUNCTION pgexporter_memory_info(OUT total_memory int8,
OUT used_memory int8,
OUT free_memory int8,
OUT swap_total int8,
OUT swap_used int8,
OUT swap_free int8,
OUT cache_total int8
)
RETURNS SETOF record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

REVOKE ALL ON FUNCTION pgexporter_memory_info FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pgexporter_memory_info TO pg_monitor;
8 changes: 8 additions & 0 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ pgexporter_ext_free_space(char* path);
unsigned long
pgexporter_ext_total_space(char* path);

/**
* Trim whitespace from a string
* @param s The string
* @return The result
*/
char*
pgexporter_ext_trim_whitespace(char* s);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 2539c1c

Please sign in to comment.