Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Refactor to allow packaging of oracledb_exporter #308

Merged
merged 5 commits into from
Apr 27, 2023

Conversation

schmikei
Copy link
Contributor

@schmikei schmikei commented Apr 14, 2023

Description

Refactors the code to be importable via applications such as the grafana agent.

No code can be imported via the main package. I have also validated that this code can be imported via packaging it into the grafana-agent, albeit it utilized a different driver.

https://github.com/grafana/agent

Fixes #285

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
    -- it should not but let me know if the changes require a doc update!!

How Has This Been Tested?

Built the binary and ran with the refactor:

DATA_SOURCE_NAME=oracle://user:password@localhost:1521/orcllocalnet ./oracledb_exporter --scrape.interval 5s

curled endpoint:

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 5.4196e-05
go_gc_duration_seconds{quantile="0.25"} 0.000119196
go_gc_duration_seconds{quantile="0.5"} 0.000250948
go_gc_duration_seconds{quantile="0.75"} 0.001607656
go_gc_duration_seconds{quantile="1"} 0.021227839
go_gc_duration_seconds_sum 0.132146638
go_gc_duration_seconds_count 61
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 11
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.19.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 865616
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.13496552e+08
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.462088e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 1.76922e+06
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 9.115696e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 865616
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 4.964352e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 2.670592e+06
# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 3978
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 2.301952e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 7.634944e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.681500415226576e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.
# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 1.773198e+06
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 4800
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 15600
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 69984
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 130176
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.194304e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.1848e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 753664
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 753664
# HELP go_memstats_sys_bytes Number of bytes obtained from system.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 2.0296968e+07
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
go_threads 7
# HELP oracledb_activity_execute_count Generic counter metric from v$sysstat view in Oracle.
# TYPE oracledb_activity_execute_count gauge
oracledb_activity_execute_count 1.16266909e+08
# HELP oracledb_activity_parse_count_total Generic counter metric from v$sysstat view in Oracle.
# TYPE oracledb_activity_parse_count_total gauge
oracledb_activity_parse_count_total 3.0518142e+07
# HELP oracledb_activity_user_commits Generic counter metric from v$sysstat view in Oracle.
# TYPE oracledb_activity_user_commits gauge
oracledb_activity_user_commits 1.361322e+06
# HELP oracledb_activity_user_rollbacks Generic counter metric from v$sysstat view in Oracle.
# TYPE oracledb_activity_user_rollbacks gauge
oracledb_activity_user_rollbacks 6
# HELP oracledb_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, goversion from which oracledb_exporter was built, and the goos and goarch for the build.
# TYPE oracledb_exporter_build_info gauge
oracledb_exporter_build_info{branch="",goarch="amd64",goos="linux",goversion="go1.19.4",revision="a6064cad07d88e02e20048141272930eeeffd5a3-modified",tags="unknown",version=""} 1
# HELP oracledb_exporter_last_scrape_duration_seconds Duration of the last scrape of metrics from Oracle DB.
# TYPE oracledb_exporter_last_scrape_duration_seconds gauge
oracledb_exporter_last_scrape_duration_seconds 0.297279433
# HELP oracledb_exporter_last_scrape_error Whether the last scrape of metrics from Oracle DB resulted in an error (1 for error, 0 for success).
# TYPE oracledb_exporter_last_scrape_error gauge
oracledb_exporter_last_scrape_error 0
# HELP oracledb_exporter_scrapes_total Total number of times Oracle DB was scraped for metrics.
# TYPE oracledb_exporter_scrapes_total counter
oracledb_exporter_scrapes_total 30
# HELP oracledb_process_count Gauge metric with count of processes.
# TYPE oracledb_process_count gauge
oracledb_process_count 77
# HELP oracledb_resource_current_utilization Generic counter metric from v$resource_limit view in Oracle (current value).
# TYPE oracledb_resource_current_utilization gauge
oracledb_resource_current_utilization{resource_name="branches"} 0
oracledb_resource_current_utilization{resource_name="cmtcallbk"} 0
oracledb_resource_current_utilization{resource_name="dml_locks"} 0
oracledb_resource_current_utilization{resource_name="enqueue_locks"} 37
oracledb_resource_current_utilization{resource_name="enqueue_resources"} 28
oracledb_resource_current_utilization{resource_name="gcs_resources"} 0
oracledb_resource_current_utilization{resource_name="gcs_shadows"} 0
oracledb_resource_current_utilization{resource_name="ges_big_msgs"} 0
oracledb_resource_current_utilization{resource_name="ges_cache_ress"} 0
oracledb_resource_current_utilization{resource_name="ges_locks"} 0
oracledb_resource_current_utilization{resource_name="ges_procs"} 0
oracledb_resource_current_utilization{resource_name="ges_reg_msgs"} 0
oracledb_resource_current_utilization{resource_name="ges_ress"} 0
oracledb_resource_current_utilization{resource_name="ges_rsv_msgs"} 0
oracledb_resource_current_utilization{resource_name="k2q_locks"} 0
oracledb_resource_current_utilization{resource_name="max_rollback_segments"} 23
oracledb_resource_current_utilization{resource_name="max_shared_servers"} 1
oracledb_resource_current_utilization{resource_name="parallel_max_servers"} 8
oracledb_resource_current_utilization{resource_name="processes"} 79
oracledb_resource_current_utilization{resource_name="sessions"} 95
oracledb_resource_current_utilization{resource_name="smartio_buffer_memory"} 0
oracledb_resource_current_utilization{resource_name="smartio_metadata_memory"} 0
oracledb_resource_current_utilization{resource_name="smartio_overhead_memory"} 0
oracledb_resource_current_utilization{resource_name="smartio_sessions"} 0
oracledb_resource_current_utilization{resource_name="sort_segment_locks"} 0
oracledb_resource_current_utilization{resource_name="temporary_table_locks"} 0
oracledb_resource_current_utilization{resource_name="transactions"} 0
# HELP oracledb_resource_limit_value Generic counter metric from v$resource_limit view in Oracle (UNLIMITED: -1).
# TYPE oracledb_resource_limit_value gauge
oracledb_resource_limit_value{resource_name="branches"} -1
oracledb_resource_limit_value{resource_name="cmtcallbk"} -1
oracledb_resource_limit_value{resource_name="dml_locks"} -1
oracledb_resource_limit_value{resource_name="enqueue_locks"} 6060
oracledb_resource_limit_value{resource_name="enqueue_resources"} -1
oracledb_resource_limit_value{resource_name="gcs_resources"} -1
oracledb_resource_limit_value{resource_name="gcs_shadows"} -1
oracledb_resource_limit_value{resource_name="ges_big_msgs"} -1
oracledb_resource_limit_value{resource_name="ges_cache_ress"} -1
oracledb_resource_limit_value{resource_name="ges_locks"} -1
oracledb_resource_limit_value{resource_name="ges_procs"} 0
oracledb_resource_limit_value{resource_name="ges_reg_msgs"} -1
oracledb_resource_limit_value{resource_name="ges_ress"} -1
oracledb_resource_limit_value{resource_name="ges_rsv_msgs"} 0
oracledb_resource_limit_value{resource_name="k2q_locks"} -1
oracledb_resource_limit_value{resource_name="max_rollback_segments"} 65535
oracledb_resource_limit_value{resource_name="max_shared_servers"} -1
oracledb_resource_limit_value{resource_name="parallel_max_servers"} 32767
oracledb_resource_limit_value{resource_name="processes"} 320
oracledb_resource_limit_value{resource_name="sessions"} 504
oracledb_resource_limit_value{resource_name="smartio_buffer_memory"} -1
oracledb_resource_limit_value{resource_name="smartio_metadata_memory"} -1
oracledb_resource_limit_value{resource_name="smartio_overhead_memory"} -1
oracledb_resource_limit_value{resource_name="smartio_sessions"} -1
oracledb_resource_limit_value{resource_name="sort_segment_locks"} -1
oracledb_resource_limit_value{resource_name="temporary_table_locks"} -1
oracledb_resource_limit_value{resource_name="transactions"} -1
# HELP oracledb_sessions_value Gauge metric with count of sessions by status and type.
# TYPE oracledb_sessions_value gauge
oracledb_sessions_value{status="ACTIVE",type="BACKGROUND"} 62
oracledb_sessions_value{status="ACTIVE",type="USER"} 3
oracledb_sessions_value{status="INACTIVE",type="USER"} 3
# HELP oracledb_tablespace_bytes Generic counter metric of tablespaces bytes in Oracle.
# TYPE oracledb_tablespace_bytes gauge
oracledb_tablespace_bytes{tablespace="SYSAUX",type="PERMANENT"} 1.671757824e+09
oracledb_tablespace_bytes{tablespace="SYSTEM",type="PERMANENT"} 1.482686464e+09
oracledb_tablespace_bytes{tablespace="TEMP",type="TEMPORARY"} 0
oracledb_tablespace_bytes{tablespace="UNDOTBS1",type="UNDO"} 2.3396352e+07
oracledb_tablespace_bytes{tablespace="USERS",type="PERMANENT"} 2.818048e+06
# HELP oracledb_tablespace_free Generic counter metric of tablespaces free bytes in Oracle.
# TYPE oracledb_tablespace_free gauge
oracledb_tablespace_free{tablespace="SYSAUX",type="PERMANENT"} 3.268796416e+10
oracledb_tablespace_free{tablespace="SYSTEM",type="PERMANENT"} 3.287703552e+10
oracledb_tablespace_free{tablespace="TEMP",type="TEMPORARY"} 3.4359721984e+10
oracledb_tablespace_free{tablespace="UNDOTBS1",type="UNDO"} 3.4336325632e+10
oracledb_tablespace_free{tablespace="USERS",type="PERMANENT"} 3.4356903936e+10
# HELP oracledb_tablespace_max_bytes Generic counter metric of tablespaces max bytes in Oracle.
# TYPE oracledb_tablespace_max_bytes gauge
oracledb_tablespace_max_bytes{tablespace="SYSAUX",type="PERMANENT"} 3.4359721984e+10
oracledb_tablespace_max_bytes{tablespace="SYSTEM",type="PERMANENT"} 3.4359721984e+10
oracledb_tablespace_max_bytes{tablespace="TEMP",type="TEMPORARY"} 3.4359721984e+10
oracledb_tablespace_max_bytes{tablespace="UNDOTBS1",type="UNDO"} 3.4359721984e+10
oracledb_tablespace_max_bytes{tablespace="USERS",type="PERMANENT"} 3.4359721984e+10
# HELP oracledb_tablespace_used_percent Gauge metric showing as a percentage of how much of the tablespace has been used.
# TYPE oracledb_tablespace_used_percent gauge
oracledb_tablespace_used_percent{tablespace="SYSAUX",type="PERMANENT"} 4.865457947472548
oracledb_tablespace_used_percent{tablespace="SYSTEM",type="PERMANENT"} 4.315187604516795
oracledb_tablespace_used_percent{tablespace="TEMP",type="TEMPORARY"} 0
oracledb_tablespace_used_percent{tablespace="UNDOTBS1",type="UNDO"} 0.06809237866038259
oracledb_tablespace_used_percent{tablespace="USERS",type="PERMANENT"} 0.008201603031922832
# HELP oracledb_up Whether the Oracle database server is up.
# TYPE oracledb_up gauge
oracledb_up 1
# HELP oracledb_wait_time_administrative Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_administrative gauge
oracledb_wait_time_administrative 0
# HELP oracledb_wait_time_application Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_application gauge
oracledb_wait_time_application 0
# HELP oracledb_wait_time_commit Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_commit gauge
oracledb_wait_time_commit 0.002
# HELP oracledb_wait_time_concurrency Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_concurrency gauge
oracledb_wait_time_concurrency 0.002
# HELP oracledb_wait_time_configuration Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_configuration gauge
oracledb_wait_time_configuration 0
# HELP oracledb_wait_time_network Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_network gauge
oracledb_wait_time_network 0
# HELP oracledb_wait_time_other Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_other gauge
oracledb_wait_time_other 0.002
# HELP oracledb_wait_time_scheduler Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_scheduler gauge
oracledb_wait_time_scheduler 0
# HELP oracledb_wait_time_system_io Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_system_io gauge
oracledb_wait_time_system_io 0.006
# HELP oracledb_wait_time_user_io Generic counter metric from v$waitclassmetric view in Oracle.
# TYPE oracledb_wait_time_user_io gauge
oracledb_wait_time_user_io 0
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 3.56
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 65536
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 10
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.7661952e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.68150026925e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 7.45873408e+08
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes 1.8446744073709552e+19

Screenshots (if appropriate):

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • Updated version in Makefile respecting semver v2

@schmikei schmikei marked this pull request as ready for review April 14, 2023 19:39
@schmikei schmikei marked this pull request as draft April 14, 2023 19:45
@schmikei schmikei marked this pull request as ready for review April 14, 2023 19:48
@Yannig
Copy link
Collaborator

Yannig commented Apr 15, 2023

Looks great!
I'm asking two more things:

  • Is it possible to add a little howto in Markdown in order to understand how to integrate it with grafana agent?
  • Can you change the version to a new major version (v0.5)?

In any case, thanks for your job.

@schmikei schmikei force-pushed the refactor-collector-package branch from e79a63b to 39c37fd Compare April 19, 2023 17:14
@schmikei
Copy link
Contributor Author

Also before we contemplate merging this and releasing a major version I'd like to get your thoughts on a driver update that wouldn't require users to download the RPMs.

I can write up an issue but I found that https://github.com/sijms/go-ora works without having code users to import the oracle sdk RPMs. It also is more actively used but there was a lot of the build system that is related to working with https://github.com/mattn/go-oci8. Many popular projects like https://github.com/open-telemetry/opentelemetry-collector-contrib/ and https://github.com/DataDog/datadog-agent use this library pretty effectively as to not have users manually do all the installation to use the driver and is more portable.

I will create an issue for this when I have a free moment to explore/research it further but just wanted to give a heads up that I think that will be a pre-requisite for us to fully adopt this base repo in the Grafana Agent rather than a fork :)

@@ -472,6 +472,48 @@ Everything must compile, including mattn driver for oracle.

Next build ./... in oracledb-exporter dir, or install it.

## Import into your Golang Application
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also let me know if this snippet is too long for your preference :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's perfect.

@Yannig
Copy link
Collaborator

Yannig commented Apr 20, 2023

That's an impressive job done so far !

For the driver, I was already considering to move to https://github.com/sijms/go-ora but didn't manage to make it.

So, if you have time to do it, don't hesitate and go ahead :)

@Yannig
Copy link
Collaborator

Yannig commented Apr 26, 2023

Is it ok for you to merge?

@schmikei
Copy link
Contributor Author

Is it ok for you to merge?

Yep I believe so!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package structure disallows wrapping of Exporter
2 participants