├── .gitignore ├── Dockerfile ├── LICENSE ├── METRICS.md ├── README.md ├── config └── config.go ├── docker-compose.yml ├── exporter ├── gather.go ├── http.go ├── metrics.go ├── prometheus.go └── structs.go ├── go.mod ├── go.sum ├── main.go └── renovate.json /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | .vscode 3 | !.vscode/settings.json 4 | !.vscode/tasks.json 5 | !.vscode/launch.json 6 | !.vscode/extensions.json 7 | nsx-t-exporter 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.23-alpine as build 2 | LABEL maintainer "SAP" 3 | 4 | RUN apk --no-cache add ca-certificates \ 5 | && apk --no-cache add --virtual build-deps git build-base 6 | 7 | COPY ./ /go/src/github.com/sapcc/github.com/sapcc/nsx-t-exporter 8 | WORKDIR /go/src/github.com/sapcc/github.com/sapcc/nsx-t-exporter 9 | 10 | RUN go get \ 11 | && go test ./... \ 12 | && go build -o /bin/main 13 | 14 | FROM alpine:3.20 15 | LABEL source_repository="https://github.com/sapcc/nsx-t-exporter" 16 | 17 | RUN apk --no-cache add ca-certificates \ 18 | && addgroup nsxv3exporter \ 19 | && adduser -S -G nsxv3exporter nsxv3exporter 20 | USER nsxv3exporter 21 | COPY --from=build /bin/main /bin/main 22 | ENV LISTEN_PORT=9191 23 | EXPOSE 9191 24 | ENTRYPOINT [ "/bin/main" ] 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /METRICS.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Below are an example of the metrics as exposed by this exporter (filteer by nsxv3 for NSX-T metrics). 4 | 5 | ``` 6 | # HELP go_gc_duration_seconds A summary of the GC invocation durations. 7 | # TYPE go_gc_duration_seconds summary 8 | go_gc_duration_seconds{quantile="0"} 0.000101154 9 | go_gc_duration_seconds{quantile="0.25"} 0.000101154 10 | go_gc_duration_seconds{quantile="0.5"} 0.000125166 11 | go_gc_duration_seconds{quantile="0.75"} 0.000136703 12 | go_gc_duration_seconds{quantile="1"} 0.000136703 13 | go_gc_duration_seconds_sum 0.000363023 14 | go_gc_duration_seconds_count 3 15 | # HELP go_goroutines Number of goroutines that currently exist. 16 | # TYPE go_goroutines gauge 17 | go_goroutines 9 18 | # HELP go_info Information about the Go environment. 19 | # TYPE go_info gauge 20 | go_info{version="go1.10.3"} 1 21 | # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. 22 | # TYPE go_memstats_alloc_bytes gauge 23 | go_memstats_alloc_bytes 1.864664e+06 24 | # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed. 25 | # TYPE go_memstats_alloc_bytes_total counter 26 | go_memstats_alloc_bytes_total 5.788456e+06 27 | # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. 28 | # TYPE go_memstats_buck_hash_sys_bytes gauge 29 | go_memstats_buck_hash_sys_bytes 1.443752e+06 30 | # HELP go_memstats_frees_total Total number of frees. 31 | # TYPE go_memstats_frees_total counter 32 | go_memstats_frees_total 28176 33 | # HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started. 34 | # TYPE go_memstats_gc_cpu_fraction gauge 35 | go_memstats_gc_cpu_fraction -2.6893967619215566e-09 36 | # HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata. 37 | # TYPE go_memstats_gc_sys_bytes gauge 38 | go_memstats_gc_sys_bytes 405504 39 | # HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use. 40 | # TYPE go_memstats_heap_alloc_bytes gauge 41 | go_memstats_heap_alloc_bytes 1.864664e+06 42 | # HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used. 43 | # TYPE go_memstats_heap_idle_bytes gauge 44 | go_memstats_heap_idle_bytes 2.179072e+06 45 | # HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use. 46 | # TYPE go_memstats_heap_inuse_bytes gauge 47 | go_memstats_heap_inuse_bytes 3.391488e+06 48 | # HELP go_memstats_heap_objects Number of allocated objects. 49 | # TYPE go_memstats_heap_objects gauge 50 | go_memstats_heap_objects 10816 51 | # HELP go_memstats_heap_released_bytes Number of heap bytes released to OS. 52 | # TYPE go_memstats_heap_released_bytes gauge 53 | go_memstats_heap_released_bytes 0 54 | # HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system. 55 | # TYPE go_memstats_heap_sys_bytes gauge 56 | go_memstats_heap_sys_bytes 5.57056e+06 57 | # HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection. 58 | # TYPE go_memstats_last_gc_time_seconds gauge 59 | go_memstats_last_gc_time_seconds 1.5814228009209583e+09 60 | # HELP go_memstats_lookups_total Total number of pointer lookups. 61 | # TYPE go_memstats_lookups_total counter 62 | go_memstats_lookups_total 63 63 | # HELP go_memstats_mallocs_total Total number of mallocs. 64 | # TYPE go_memstats_mallocs_total counter 65 | go_memstats_mallocs_total 38992 66 | # HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures. 67 | # TYPE go_memstats_mcache_inuse_bytes gauge 68 | go_memstats_mcache_inuse_bytes 13888 69 | # HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system. 70 | # TYPE go_memstats_mcache_sys_bytes gauge 71 | go_memstats_mcache_sys_bytes 16384 72 | # HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures. 73 | # TYPE go_memstats_mspan_inuse_bytes gauge 74 | go_memstats_mspan_inuse_bytes 56544 75 | # HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system. 76 | # TYPE go_memstats_mspan_sys_bytes gauge 77 | go_memstats_mspan_sys_bytes 81920 78 | # HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place. 79 | # TYPE go_memstats_next_gc_bytes gauge 80 | go_memstats_next_gc_bytes 4.194304e+06 81 | # HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations. 82 | # TYPE go_memstats_other_sys_bytes gauge 83 | go_memstats_other_sys_bytes 2.056528e+06 84 | # HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator. 85 | # TYPE go_memstats_stack_inuse_bytes gauge 86 | go_memstats_stack_inuse_bytes 720896 87 | # HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator. 88 | # TYPE go_memstats_stack_sys_bytes gauge 89 | go_memstats_stack_sys_bytes 720896 90 | # HELP go_memstats_sys_bytes Number of bytes obtained from system. 91 | # TYPE go_memstats_sys_bytes gauge 92 | go_memstats_sys_bytes 1.0295544e+07 93 | # HELP go_threads Number of OS threads created. 94 | # TYPE go_threads gauge 95 | go_threads 13 96 | # HELP nsxv3_cluster_control_status NSX-T control cluster status - STABLE=1, NO_CONTROLLERS=0, UNSTABLE=-1, DEGRADED=-2, UNKNOWN=-3 97 | # TYPE nsxv3_cluster_control_status gauge 98 | nsxv3_cluster_control_status{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 99 | # HELP nsxv3_cluster_management_last_successful_data_fetch NSX-T last successful data fetch in UNIX timestamp converted to float64 100 | # TYPE nsxv3_cluster_management_last_successful_data_fetch gauge 101 | nsxv3_cluster_management_last_successful_data_fetch{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 102 | # HELP nsxv3_cluster_management_offline_nodes NSX-T management cluster offline nodes 103 | # TYPE nsxv3_cluster_management_offline_nodes gauge 104 | nsxv3_cluster_management_offline_nodes{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 105 | # HELP nsxv3_cluster_management_online_nodes NSX-T management cluster online nodes 106 | # TYPE nsxv3_cluster_management_online_nodes gauge 107 | nsxv3_cluster_management_online_nodes{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 108 | # HELP nsxv3_cluster_management_status NSX-T management cluster status - STABLE=1, INITIALIZING=0, UNSTABLE=-1, DEGRADED=-2, UNKNOWN=-3 109 | # TYPE nsxv3_cluster_management_status gauge 110 | nsxv3_cluster_management_status{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 111 | # HELP nsxv3_cluster_management_database_status NSX-T management cluster database status - RUNNING=0, STOPPED=1 112 | # TYPE nsxv3_cluster_management_database_status gauge 113 | nsxv3_cluster_management_database_status{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 114 | # HELP nsxv3_control_node_connectivity NSX-T control node connectivity - CONNECTED=1, DISCONNECTED=0, UNKNOWN=-1 115 | # TYPE nsxv3_control_node_connectivity gauge 116 | nsxv3_control_node_connectivity{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1 117 | # HELP nsxv3_control_node_management_connectivity NSX-T control node management connectivity - CONNECTED > 0, DISCONNECTED = 0, UNKNOWN < 0 118 | # TYPE nsxv3_control_node_management_connectivity gauge 119 | nsxv3_control_node_management_connectivity{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1 120 | # HELP nsxv3_logical_port_operational_state NSX-T logical port operational state - UP=1, DOWN=0, UNKNOWN=-1 121 | # TYPE nsxv3_logical_port_operational_state gauge 122 | nsxv3_logical_port_operational_state{id="df227f58-1dae-4a3a-9a0b-ae2c6c68250d",nsxv3_manager_hostname="nsxm-l-01a.corp.local",transport_node_id="1845a490-7aae-4a6b-915f-d587e3c19a72"} 1 123 | # HELP nsxv3_logical_switch_admin_state NSX-T logical switch admin state - UP=1, DOWN=0 124 | # TYPE nsxv3_logical_switch_admin_state gauge 125 | nsxv3_logical_switch_admin_state{id="3517fcb7-4723-432f-b55e-49632f809632",name="openstack-tz-3200",nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 126 | nsxv3_logical_switch_admin_state{id="f2a216a7-0df0-4377-84b6-294f7742dc8f",name="test",nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 127 | # HELP nsxv3_logical_switch_state NSX-T logical switch overall state - SUCCESS=1, IN_PROGRESS=0, FAILED=-1, PARTIAL_SUCCESS=-2, ORPHANED=-3, UNKNOWN=-4 128 | # TYPE nsxv3_logical_switch_state gauge 129 | nsxv3_logical_switch_state{id="3517fcb7-4723-432f-b55e-49632f809632",nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 130 | nsxv3_logical_switch_state{id="f2a216a7-0df0-4377-84b6-294f7742dc8f",nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 131 | # HELP nsxv3_management_node_connectivity NSX-T management node connectivity - CONNECTED > 0, DISCONNECTED = 0, UNKNOWN < 0 132 | # TYPE nsxv3_management_node_connectivity gauge 133 | nsxv3_management_node_connectivity{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1 134 | # HELP nsxv3_management_node_cpu_cores NSX-T management node cpu cores 135 | # TYPE nsxv3_management_node_cpu_cores gauge 136 | nsxv3_management_node_cpu_cores{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 4 137 | # HELP nsxv3_management_node_firewall_rule_count NSX-T management node firewall rule count 138 | # TYPE nsxv3_management_node_firewall_rule_count gauge 139 | nsxv3_management_node_firewall_rule_count{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 3876 140 | # HELP nsxv3_management_node_firewall_section_count NSX-T management node firewall section count 141 | # TYPE nsxv3_management_node_firewall_section_count gauge 142 | nsxv3_management_node_firewall_section_count{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1822 143 | # HELP nsxv3_management_node_firewall_total_section_count NSX-T management node firewall all sections type count 144 | # TYPE nsxv3_management_node_firewall_total_section_count gauge 145 | nsxv3_management_node_firewall_total_section_count{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 14 146 | # HELP nsxv3_management_node_load_average NSX-T management node average load 147 | # TYPE nsxv3_management_node_load_average gauge 148 | nsxv3_management_node_load_average{minutes="1",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 8.79 149 | nsxv3_management_node_load_average{minutes="15",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 7.4 150 | nsxv3_management_node_load_average{minutes="5",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 9.65 151 | # HELP nsxv3_management_node_memory_cached NSX-T management node cached memory 152 | # TYPE nsxv3_management_node_memory_cached gauge 153 | nsxv3_management_node_memory_cached{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 804228 154 | # HELP nsxv3_management_node_memory_total NSX-T management node memory total 155 | # TYPE nsxv3_management_node_memory_total gauge 156 | nsxv3_management_node_memory_total{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1.6417744e+07 157 | # HELP nsxv3_management_node_memory_use NSX-T management node memory use 158 | # TYPE nsxv3_management_node_memory_use gauge 159 | nsxv3_management_node_memory_use{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1.329284e+07 160 | # HELP nsxv3_management_node_storage_total NSX-T management node storage total 161 | # TYPE nsxv3_management_node_storage_total gauge 162 | nsxv3_management_node_storage_total{filesystem="/",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1.052392e+07 163 | nsxv3_management_node_storage_total{filesystem="/boot",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 951704 164 | nsxv3_management_node_storage_total{filesystem="/config",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 2.9896572e+07 165 | nsxv3_management_node_storage_total{filesystem="/config_bak",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 2.9896572e+07 166 | nsxv3_management_node_storage_total{filesystem="/dev",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 8.193648e+06 167 | nsxv3_management_node_storage_total{filesystem="/dev/shm",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 8.208872e+06 168 | nsxv3_management_node_storage_total{filesystem="/image",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 4.3458352e+07 169 | nsxv3_management_node_storage_total{filesystem="/os_bak",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1.052392e+07 170 | nsxv3_management_node_storage_total{filesystem="/repository",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 3.183296e+07 171 | nsxv3_management_node_storage_total{filesystem="/run",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 1.641776e+06 172 | nsxv3_management_node_storage_total{filesystem="/run/lock",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 5120 173 | nsxv3_management_node_storage_total{filesystem="/sys/fs/cgroup",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 8.208872e+06 174 | nsxv3_management_node_storage_total{filesystem="/tmp",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 3.806856e+06 175 | nsxv3_management_node_storage_total{filesystem="/var/dump",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 9.553956e+06 176 | nsxv3_management_node_storage_total{filesystem="/var/log",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 2.7695564e+07 177 | # HELP nsxv3_management_node_storage_use NSX-T management node storage use 178 | # TYPE nsxv3_management_node_storage_use gauge 179 | nsxv3_management_node_storage_use{filesystem="/",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 4.42704e+06 180 | nsxv3_management_node_storage_use{filesystem="/boot",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 8420 181 | nsxv3_management_node_storage_use{filesystem="/config",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 95972 182 | nsxv3_management_node_storage_use{filesystem="/config_bak",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 44992 183 | nsxv3_management_node_storage_use{filesystem="/dev",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 0 184 | nsxv3_management_node_storage_use{filesystem="/dev/shm",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 2804 185 | nsxv3_management_node_storage_use{filesystem="/image",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 53260 186 | nsxv3_management_node_storage_use{filesystem="/os_bak",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 26864 187 | nsxv3_management_node_storage_use{filesystem="/repository",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 5.787448e+06 188 | nsxv3_management_node_storage_use{filesystem="/run",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 6036 189 | nsxv3_management_node_storage_use{filesystem="/run/lock",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 0 190 | nsxv3_management_node_storage_use{filesystem="/sys/fs/cgroup",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 0 191 | nsxv3_management_node_storage_use{filesystem="/tmp",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 12340 192 | nsxv3_management_node_storage_use{filesystem="/var/dump",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 21984 193 | nsxv3_management_node_storage_use{filesystem="/var/log",nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 5.888352e+06 194 | # HELP nsxv3_management_node_swap_total NSX-T management node swap total 195 | # TYPE nsxv3_management_node_swap_total gauge 196 | nsxv3_management_node_swap_total{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 0 197 | # HELP nsxv3_management_node_swap_use NSX-T management node swap use 198 | # TYPE nsxv3_management_node_swap_use gauge 199 | nsxv3_management_node_swap_use{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1"} 0 200 | # HELP nsxv3_management_node_version NSX-T management node version 201 | # TYPE nsxv3_management_node_version counter 202 | nsxv3_management_node_version{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_ip="192.168.50.1",nsxv3_node_version="2.5.1.0.0.15314292"} 1 203 | # HELP nsxv3_transport_node_deployment_state NSX-T transport node deployment state - SUCCESS=1, IN_PROGRESS=0, PENDING=-1, FAILED=-2, PARTIAL_SUCCESS=-3, ORPHANED=-4, UNKNOWN=-5 204 | # TYPE nsxv3_transport_node_deployment_state gauge 205 | nsxv3_transport_node_deployment_state{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_id="1845a490-7aae-4a6b-915f-d587e3c19a72"} 1 206 | nsxv3_transport_node_deployment_state{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_id="b652b0cd-6917-4373-af46-6b4f95b3932c"} 1 207 | # HELP nsxv3_transport_node_state NSX-T transport node state - SUCCESS=1, IN_PROGRESS=0, PENDING=-1, FAILED=-2, PARTIAL_SUCCESS=-3, ORPHANED=-4, UNKNOWN=-5 208 | # TYPE nsxv3_transport_node_state gauge 209 | nsxv3_transport_node_state{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_id="1845a490-7aae-4a6b-915f-d587e3c19a72"} 1 210 | nsxv3_transport_node_state{nsxv3_manager_hostname="nsxm-l-01a.corp.local",nsxv3_node_id="b652b0cd-6917-4373-af46-6b4f95b3932c"} 1 211 | # HELP nsxv3_transport_nodes_degraded NSX-T transport nodes with state degraded 212 | # TYPE nsxv3_transport_nodes_degraded gauge 213 | nsxv3_transport_nodes_degraded{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 2 214 | # HELP nsxv3_transport_nodes_down NSX-T transport nodes with state down 215 | # TYPE nsxv3_transport_nodes_down gauge 216 | nsxv3_transport_nodes_down{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 217 | # HELP nsxv3_transport_nodes_unknown NSX-T transport nodes with state unknown 218 | # TYPE nsxv3_transport_nodes_unknown gauge 219 | nsxv3_transport_nodes_unknown{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 220 | # HELP nsxv3_transport_nodes_up NSX-T transport nodes with state up 221 | # TYPE nsxv3_transport_nodes_up gauge 222 | nsxv3_transport_nodes_up{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 1 223 | # HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served. 224 | # TYPE promhttp_metric_handler_requests_in_flight gauge 225 | promhttp_metric_handler_requests_in_flight 1 226 | # HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code. 227 | # TYPE promhttp_metric_handler_requests_total counter 228 | promhttp_metric_handler_requests_total{code="200"} 0 229 | promhttp_metric_handler_requests_total{code="500"} 0 230 | promhttp_metric_handler_requests_total{code="503"} 0 231 | # HELP nsxv3_scheduler_total_complete NSX-T Scheduler total completed jobs 232 | # TYPE nsxv3_scheduler_total_complete gauge 233 | nsxv3_scheduler_total_complete{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 3 234 | # HELP nsxv3_scheduler_total_executing NSX-T Scheduler total executing jobs 235 | # TYPE nsxv3_scheduler_total_executing gauge 236 | nsxv3_scheduler_total_executing{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 237 | # HELP nsxv3_scheduler_total_queued NSX-T Scheduler total queued jobs 238 | # TYPE nsxv3_scheduler_total_queued gauge 239 | nsxv3_scheduler_total_queued{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 240 | # HELP nsxv3_scheduler_total_scheduled NSX-T Scheduler total scheduled jobs 241 | # TYPE nsxv3_scheduler_total_scheduled gauge 242 | nsxv3_scheduler_total_scheduled{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 243 | # HELP nsxv3_scheduler_total_suspended NSX-T Scheduler total suspended jobs 244 | # TYPE nsxv3_scheduler_total_suspended gauge 245 | nsxv3_scheduler_total_suspended{nsxv3_manager_hostname="nsxm-l-01a.corp.local"} 0 246 | ``` 247 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prometheus NSX-T Management Node Exporter 2 | 3 | Exposes metrics from NSX-T Management Node REST API to a Prometheus compatible endpoint. 4 | 5 | ## Exporter Configuration 6 | 7 | NSX-T Expoerter takes input from environment variables as: 8 | 9 | ### Mandatory Variables 10 | - `NSXV3_LOGIN_HOST` NSX-T Manager Node hostname or IP address. 11 | - `NSXV3_LOGIN_PORT` NSX-T Manager Node port. 12 | - `NSXV3_LOGIN_USER` NSX-T Manager Node login user. 13 | - `NSXV3_LOGIN_PASSWORD` NSX-T Manager Node login password. 14 | 15 | ### Optional Variables 16 | - `NSXV3_REQUESTS_PER_SECOND` (10) NSX-T Manager Node requestes per second [<100]. 17 | - `NSXV3_REQUESTS_PER_SECOND_TIMEOUT` (10) NSX-T Manager Node requestes per second timeout 18 | - `NSXV3_SUPPRESS_SSL_WORNINGS` (false) NSX-T Manager Node disables ssl host validattion. 19 | - `LOG_LEVEL` (debug) NSX-T Exporter logging level. 20 | 21 | ## Build 22 | 23 | ```sh 24 | git clone https://github.com/sapcc/github.com/sapcc/nsx-t-exporter.git 25 | cd nsx-t-exporter 26 | docker build -t . 27 | ``` 28 | 29 | ## Run (Simple) 30 | 31 | Edit docker-compose.yml 32 | ```yaml 33 | version: "2" 34 | 35 | services: 36 | nsxv3-exporter: 37 | tty: true 38 | stdin_open: true 39 | expose: 40 | - 9191 41 | ports: 42 | - 9191:9191 43 | image: 44 | environment: 45 | - NSXV3_LOGIN_HOST= 46 | - NSXV3_LOGIN_PORT= 47 | - NSXV3_LOGIN_USER= 48 | - NSXV3_LOGIN_PASSWORD= 49 | - NSXV3_REQUESTS_PER_SECOND= 50 | - NSXV3_REQUESTS_PER_SECOND_TIMEOUT= 51 | - NSXV3_CONNECTION_POOL_SIZE= 52 | - NSXV3_REQUEST_TIMEOUT_SECONDS= 53 | - NSXV3_SUPPRESS_SSL_WORNINGS= 54 | - SCRAP_PORT= 55 | - SCRAP_SCHEDULE_SECONDS= 56 | - LOG_LEVEL= 57 | 58 | ``` 59 | 60 | ## Metrics 61 | 62 | Metrics will be made available on http://:9191/metrics 63 | Metrics export can be seen at METRICS.md -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "github.com/caarlos0/env/v6" 5 | log "github.com/sirupsen/logrus" 6 | ) 7 | 8 | // NSXv3Configuration holds the configuration of the NSXv3 Manager 9 | type NSXv3Configuration struct { 10 | LoginPort int `env:"NSXV3_LOGIN_PORT" envDefault:"443"` 11 | LoginHost string `env:"NSXV3_LOGIN_HOST,required"` 12 | LoginUser string `env:"NSXV3_LOGIN_USER,required"` 13 | LoginPassword string `env:"NSXV3_LOGIN_PASSWORD,required"` 14 | ScrapPort int `env:"SCRAP_PORT" envDefault:"9999"` 15 | RequestsPerSecond int `env:"NSXV3_REQUESTS_PER_SECOND" envDefault:"10"` 16 | RequestsPerSecondTimeout int `env:"NSXV3_REQUESTS_PER_SECOND_TIMEOUT" envDefault:"10"` 17 | RequestsConnPoolSize int `env:"NSXV3_CONNECTION_POOL_SIZE" envDefault:"0"` 18 | RequestTimeout int `env:"NSXV3_REQUEST_TIMEOUT_SECONDS" envDefault:"0"` 19 | SuppressSslWarnings bool `env:"NSXV3_SUPPRESS_SSL_WARNINGS" envDefault:"false"` 20 | ScrapScheduleSeconds int `env:"SCRAP_SCHEDULE_SECONDS" envDefault:"0"` 21 | } 22 | 23 | // Init Loads NSXv3Configuration value from the OS environment variables and validate them 24 | func Init() NSXv3Configuration { 25 | 26 | nsxv3Config := NSXv3Configuration{} 27 | 28 | if err := env.Parse(&nsxv3Config); err != nil { 29 | log.Fatalf("%+v", err) 30 | } 31 | 32 | // Variables that cannot be empty strings 33 | variablesToCheck := map[string]string{ 34 | "NSXV3_LOGIN_HOST": nsxv3Config.LoginHost, 35 | } 36 | 37 | ensureNotEmpty(variablesToCheck) 38 | return nsxv3Config 39 | } 40 | 41 | func ensureNotEmpty(variablesToCheck map[string]string) { 42 | for key, value := range variablesToCheck { 43 | if value == "" { 44 | log.Fatalf("Variable %v cannot be an empty string.", key) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | nsxv3-exporter: 5 | tty: true 6 | stdin_open: true 7 | expose: 8 | - 9191 9 | ports: 10 | - 9191:9191 11 | image: nsx-exporter:latest 12 | environment: 13 | - NSXV3_LOGIN_HOST=nsx-floatin-ip.corp.local 14 | - NSXV3_LOGIN_PORT=443 15 | - NSXV3_LOGIN_USER=admin 16 | - NSXV3_LOGIN_PASSWORD=VMwarensbu_1 17 | - NSXV3_REQUESTS_PER_SECOND= 18 | - NSXV3_REQUESTS_PER_SECOND_TIMEOUT= 19 | - NSXV3_CONNECTION_POOL_SIZE= 20 | - NSXV3_REQUEST_TIMEOUT_SECONDS= 21 | - NSXV3_SUPPRESS_SSL_WORNINGS=true 22 | - SCRAP_PORT=9191 23 | - SCRAP_SCHEDULE_SECONDS= 24 | - LOG_LEVEL= 25 | 26 | 27 | -------------------------------------------------------------------------------- /exporter/gather.go: -------------------------------------------------------------------------------- 1 | package exporter 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "net/http" 7 | "net/url" 8 | "strings" 9 | "time" 10 | 11 | log "github.com/sirupsen/logrus" 12 | ) 13 | 14 | var managementClusterStates = map[string]float64{ 15 | "STABLE": 1, 16 | "INITIALIZING": 0, 17 | "UNSTABLE": -1, 18 | "DEGRADED": -2, 19 | "UNKNOWN": -3, 20 | } 21 | 22 | var controlClusterStates = map[string]float64{ 23 | "STABLE": 1, 24 | "NO_CONTROLLERS": 0, 25 | "UNSTABLE": -1, 26 | "DEGRADED": -2, 27 | "UNKNOWN": -3, 28 | } 29 | 30 | var nodeConnectivityStates = map[string]float64{ 31 | "CONNECTED": 1, 32 | "DEGRADED": 0, 33 | "UNKNOWN": -1, 34 | } 35 | 36 | var transportNodeStates = map[string]float64{ 37 | "SUCCESS": 1, 38 | "IN_PROGRESS": 0, 39 | "PENDING": -1, 40 | "FAILED": -2, 41 | "PARTIAL_SUCCESS": -3, 42 | "ORPHANED": -4, 43 | "UNKNOWN": -5, 44 | } 45 | 46 | var logicalSwitchStates = map[string]float64{ 47 | "SUCCESS": 1, 48 | "IN_PROGRESS": 0, 49 | "FAILED": -1, 50 | "PARTIAL_SUCCESS": -2, 51 | "ORPHANED": -3, 52 | "UNKNOWN": -4, 53 | } 54 | 55 | var logicalSwitchAdminStates = map[string]float64{ 56 | "UP": 1, 57 | "DOWN": 0, 58 | } 59 | 60 | var logicalPortOperationalStates = map[string]float64{ 61 | "UP": 1, 62 | "DOWN": 0, 63 | "UNKNOWN": -1, 64 | } 65 | 66 | var noCursor = "" 67 | 68 | var ( 69 | endpoints []Nsxv3Resource 70 | ) 71 | 72 | func getNodeIndexByIP(data *Nsxv3Data, ip string) int { 73 | for index, element := range data.ManagementNodes { 74 | if element.IP == ip { 75 | return index 76 | } 77 | } 78 | return -1 79 | } 80 | 81 | func clusterStatusHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 82 | managementClusterInfo := status.state["mgmt_cluster_status"].(map[string]interface{}) 83 | 84 | data.ClusterManagementStatus = managementClusterStates[managementClusterInfo["status"].(string)] 85 | data.ClusterControlStatus = controlClusterStates[managementClusterInfo["status"].(string)] 86 | 87 | if onlineNodes, ok := managementClusterInfo["online_nodes"]; ok { 88 | data.ClusterOnlineNodes = float64(len(onlineNodes.([]interface{}))) 89 | } 90 | if offlineNodes, ok := managementClusterInfo["offline_nodes"]; ok { 91 | data.ClusterOfflineNodes = float64(len(offlineNodes.([]interface{}))) 92 | } 93 | return noCursor, nil 94 | } 95 | 96 | func clusterNodesStatusHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 97 | mgmtNodes := status.state["management_cluster"].([]interface{}) 98 | for _, node := range mgmtNodes { 99 | nodeData := new(Nsxv3ManagementNodeData) 100 | 101 | nodeProperties := node.(map[string]interface{}) 102 | 103 | nodeData.IP = nodeProperties["role_config"].(map[string]interface{})["api_listen_addr"].(map[string]interface{})["ip_address"].(string) 104 | 105 | nodeData.Connectivity = nodeConnectivityStates[nodeProperties["node_status"].(map[string]interface{})["mgmt_cluster_status"].(map[string]interface{})["mgmt_cluster_status"].(string)] 106 | 107 | nodeData.Version = nodeProperties["node_status"].(map[string]interface{})["version"].(string) 108 | 109 | timeSeries := nodeProperties["node_status_properties"].([]interface{}) 110 | 111 | for _, timeSeria := range timeSeries { 112 | prop := timeSeria.(map[string]interface{}) 113 | 114 | load := prop["load_average"].([]interface{}) 115 | 116 | nodeData.CPUCores = prop["cpu_cores"].(float64) 117 | 118 | nodeData.LoadAverage[0] = load[0].(float64) 119 | nodeData.LoadAverage[1] = load[1].(float64) 120 | nodeData.LoadAverage[2] = load[2].(float64) 121 | 122 | nodeData.MemoryCached = prop["mem_cache"].(float64) 123 | nodeData.MemoryUse = prop["mem_used"].(float64) 124 | nodeData.MemoryTotal = prop["mem_total"].(float64) 125 | nodeData.SwapTotal = prop["swap_total"].(float64) 126 | nodeData.SwapUse = prop["swap_used"].(float64) 127 | 128 | filesystems := prop["file_systems"].([]interface{}) 129 | 130 | for _, filesystem := range filesystems { 131 | nodeDataStorage := new(Nsxv3NodeStorageData) 132 | 133 | nodeDataStorage.filesystem = filesystem.(map[string]interface{})["mount"].(string) 134 | nodeDataStorage.totalMetric = float64(filesystem.(map[string]interface{})["total"].(float64)) 135 | nodeDataStorage.usedMetric = float64(filesystem.(map[string]interface{})["used"].(float64)) 136 | 137 | nodeData.Storage = append( 138 | nodeData.Storage, 139 | *nodeDataStorage) 140 | } 141 | // We would like to process only the first of all time serias 142 | break 143 | } 144 | data.ManagementNodes = append(data.ManagementNodes, *nodeData) 145 | } 146 | 147 | controlNodes := status.state["controller_cluster"].([]interface{}) 148 | 149 | for _, node := range controlNodes { 150 | nodeData := new(Nsxv3ControlNodeData) 151 | 152 | nodeProperties := node.(map[string]interface{}) 153 | 154 | nodeData.IP = nodeProperties["role_config"].(map[string]interface{})["control_plane_listen_addr"].(map[string]interface{})["ip_address"].(string) 155 | 156 | controlNodeStatus := nodeProperties["node_status"].(map[string]interface{})["control_cluster_status"].(map[string]interface{}) 157 | 158 | nodeData.Connectivity = nodeConnectivityStates[controlNodeStatus["control_cluster_status"].(string)] 159 | nodeData.ManagementConnectivity = nodeConnectivityStates[controlNodeStatus["mgmt_connection_status"].(map[string]interface{})["connectivity_status"].(string)] 160 | 161 | data.ControlNodes = append(data.ControlNodes, *nodeData) 162 | } 163 | return noCursor, nil 164 | } 165 | 166 | func managerNodeFirewallHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 167 | results := status.state["sections_summary"] 168 | var sectionTypes []interface{} 169 | 170 | if results != nil { 171 | sectionTypes = results.([]interface{}) 172 | } 173 | 174 | for _, section := range sectionTypes { 175 | sectionType := section.(map[string]interface{}) 176 | if sectionType["section_type"].(string) == "L3DFW" { 177 | index := getNodeIndexByIP(data, status.request.URL.Host) 178 | data.ManagementNodes[index].L3DFWSectionCount = sectionType["section_count"].(float64) 179 | data.ManagementNodes[index].L3DFWRuleCount = sectionType["rule_count"].(float64) 180 | } 181 | } 182 | 183 | return noCursor, nil 184 | } 185 | 186 | func managerNodeFirewallSectionsHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 187 | index := getNodeIndexByIP(data, status.request.URL.Host) 188 | data.ManagementNodes[index].TotalSectionCount = status.state["result_count"].(float64) 189 | 190 | return noCursor, nil 191 | } 192 | 193 | func transportNodeStateHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 194 | results := status.state["results"] 195 | var nodes []interface{} 196 | 197 | if results != nil { 198 | nodes = results.([]interface{}) 199 | } 200 | 201 | next := noCursor 202 | cursor := status.state["cursor"] 203 | if cursor != nil { 204 | next = cursor.(string) 205 | } 206 | for _, node := range nodes { 207 | nodeData := new(Nsxv3TransportNodeData) 208 | 209 | nodeProperties := node.(map[string]interface{}) 210 | 211 | nodeData.ID = nodeProperties["transport_node_id"].(string) 212 | nodeData.State = transportNodeStates[strings.ToUpper(nodeProperties["state"].(string))] 213 | nodeData.DeploymentState = transportNodeStates[strings.ToUpper(nodeProperties["node_deployment_state"].(map[string]interface{})["state"].(string))] 214 | 215 | data.TransportNodes = append(data.TransportNodes, *nodeData) 216 | } 217 | return next, nil 218 | } 219 | 220 | func transportNodesStateHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 221 | data.TransportNodesState.UpCount = status.state["up_count"].(float64) 222 | data.TransportNodesState.DegradedCount = status.state["degraded_count"].(float64) 223 | data.TransportNodesState.DownCount = status.state["down_count"].(float64) 224 | data.TransportNodesState.UnknownCount = status.state["unknown_count"].(float64) 225 | return noCursor, nil 226 | } 227 | 228 | func logicalSwitchAdminStateHander(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 229 | lswitches := status.state["results"].([]interface{}) 230 | 231 | next := noCursor 232 | cursor := status.state["cursor"] 233 | if cursor != nil { 234 | next = cursor.(string) 235 | } 236 | 237 | for _, lswitch := range lswitches { 238 | lswitchData := new(Nsxv3LogicalSwitchAdminStateData) 239 | 240 | lswitchProperties := lswitch.(map[string]interface{}) 241 | 242 | lswitchData.id = lswitchProperties["id"].(string) 243 | lswitchData.name = lswitchProperties["display_name"].(string) 244 | lswitchData.adminStateMetric = logicalSwitchAdminStates[lswitchProperties["admin_state"].(string)] 245 | 246 | data.LogicalSwitchesAdminStates = append(data.LogicalSwitchesAdminStates, *lswitchData) 247 | } 248 | return next, nil 249 | } 250 | 251 | func logicalPortsHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 252 | logicalPorts := status.state["results"].([]interface{}) 253 | 254 | next := noCursor 255 | cursor := status.state["cursor"] 256 | if cursor != nil { 257 | next = cursor.(string) 258 | } 259 | 260 | for _, logicalPort := range logicalPorts { 261 | port := logicalPort.(map[string]interface{}) 262 | logicalPortData := new(Nsxv3LogicalPortOperationalStateData) 263 | logicalPortData.id = port["id"].(string) 264 | splittedPortName := strings.Split(port["display_name"].(string), "@") 265 | logicalPortData.hostID = splittedPortName[len(splittedPortName)-1] // Transport node ID is part of the name 266 | logicalPortData.operationalStateMetric = logicalPortOperationalStates[port["status"].(map[string]interface{})["status"].(string)] 267 | data.LogicalPortOperationalStates = append(data.LogicalPortOperationalStates, *logicalPortData) 268 | } 269 | return next, nil 270 | } 271 | 272 | func logicalSwitchStateHander(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 273 | lswitches := status.state["results"].([]interface{}) 274 | 275 | next := noCursor 276 | cursor := status.state["cursor"] 277 | if cursor != nil { 278 | next = cursor.(string) 279 | } 280 | 281 | for _, lswitch := range lswitches { 282 | lswitchData := new(Nsxv3LogicalSwitchStateData) 283 | 284 | lswitchProperties := lswitch.(map[string]interface{}) 285 | 286 | lswitchData.id = lswitchProperties["logical_switch_id"].(string) 287 | lswitchData.stateMetric = logicalSwitchStates[strings.ToUpper(lswitchProperties["state"].(string))] 288 | 289 | data.LogicalSwitchesStates = append(data.LogicalSwitchesStates, *lswitchData) 290 | } 291 | return next, nil 292 | } 293 | 294 | func activityFramworkStatisticsHandler(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 295 | data.Scheduler.TotalQueued = status.state["total_queued"].(float64) 296 | data.Scheduler.TotalScheduled = status.state["total_scheduled"].(float64) 297 | data.Scheduler.TotalExecuting = status.state["total_executing"].(float64) 298 | data.Scheduler.TotalSuspended = status.state["total_suspended"].(float64) 299 | data.Scheduler.TotalComplete = status.state["total_complete"].(float64) 300 | return noCursor, nil 301 | } 302 | 303 | // endpointHost could be Node FQDN, IP or empty string for NSX-T Load Balancer FQDN/IP 304 | func getEndpointStatus(endpointStatusType Nsxv3ResourceKind, endpointHost string) Nsxv3Resource { 305 | switch id := endpointStatusType; id { 306 | case ManagementCluster: 307 | return Nsxv3Resource{ 308 | kind: endpointStatusType, 309 | request: &http.Request{ 310 | Method: "GET", 311 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/cluster/status"}, 312 | }, 313 | } 314 | case ManagementClusterNodes: 315 | return Nsxv3Resource{ 316 | kind: ManagementClusterNodes, 317 | request: &http.Request{ 318 | Method: "GET", 319 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/cluster/nodes/status"}, 320 | }, 321 | } 322 | case ManagerNodeFirewall: 323 | return Nsxv3Resource{ 324 | kind: ManagerNodeFirewall, 325 | request: &http.Request{ 326 | Method: "GET", 327 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/firewall/sections/summary"}, 328 | }, 329 | } 330 | case ManagerNodeFirewallSections: 331 | return Nsxv3Resource{ 332 | kind: ManagerNodeFirewallSections, 333 | request: &http.Request{ 334 | Method: "GET", 335 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/firewall/sections"}, 336 | }, 337 | } 338 | case LogicalSwitch: 339 | return Nsxv3Resource{ 340 | kind: LogicalSwitch, 341 | request: &http.Request{ 342 | Method: "GET", 343 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/logical-switches"}, 344 | }, 345 | } 346 | case LogicalSwitchAdmin: 347 | return Nsxv3Resource{ 348 | kind: LogicalSwitchAdmin, 349 | request: &http.Request{ 350 | Method: "GET", 351 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/logical-switches/state"}, 352 | }, 353 | } 354 | case TransportNode: 355 | return Nsxv3Resource{ 356 | kind: TransportNode, 357 | request: &http.Request{ 358 | Method: "GET", 359 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/transport-nodes/state"}, 360 | }, 361 | } 362 | case TransportNodes: 363 | return Nsxv3Resource{ 364 | kind: TransportNodes, 365 | request: &http.Request{ 366 | Method: "GET", 367 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/transport-nodes/status"}, 368 | }, 369 | } 370 | case LogicalPort: 371 | return Nsxv3Resource{ 372 | kind: LogicalPort, 373 | request: &http.Request{ 374 | Method: "GET", 375 | URL: &url.URL{ 376 | Host: endpointHost, 377 | Path: "/policy/api/v1/search", 378 | RawQuery: url.Values{ 379 | "query": []string{ // odata query 380 | strings.Join([]string{ 381 | "resource_type:LogicalPort", 382 | "_exists_:resource_type", 383 | "!resource_type:GenericPolicyRealizedResourceORDomain", 384 | "!_exists_:nsx_id", 385 | }, " AND ")}, 386 | "page_size": []string{"100"}, 387 | "data_source": []string{"ALL"}, 388 | }.Encode(), 389 | }, 390 | }, 391 | } 392 | case ActivityFrameworkStatistics: 393 | return Nsxv3Resource{ 394 | kind: ActivityFrameworkStatistics, 395 | request: &http.Request{ 396 | Method: "GET", 397 | URL: &url.URL{Host: endpointHost, Path: "/api/v1/operational/activityframework/scheduler/statistics"}, 398 | }, 399 | } 400 | } 401 | return Nsxv3Resource{} 402 | } 403 | 404 | func handle(data *Nsxv3Data, status *Nsxv3Resource) (string, error) { 405 | switch id := status.kind; id { 406 | case ManagementCluster: 407 | return clusterStatusHandler(data, status) 408 | case ManagementClusterNodes: 409 | return clusterNodesStatusHandler(data, status) 410 | case ManagerNodeFirewall: 411 | return managerNodeFirewallHandler(data, status) 412 | case ManagerNodeFirewallSections: 413 | return managerNodeFirewallSectionsHandler(data, status) 414 | case LogicalSwitch: 415 | return logicalSwitchAdminStateHander(data, status) 416 | case LogicalSwitchAdmin: 417 | return logicalSwitchStateHander(data, status) 418 | case TransportNode: 419 | return transportNodeStateHandler(data, status) 420 | case TransportNodes: 421 | return transportNodesStateHandler(data, status) 422 | case LogicalPort: 423 | return logicalPortsHandler(data, status) 424 | case ActivityFrameworkStatistics: 425 | return activityFramworkStatisticsHandler(data, status) 426 | } 427 | return noCursor, fmt.Errorf("Unsupported Endpoint Type %v", status.kind) 428 | } 429 | 430 | func (e *Exporter) gatherWave(data *Nsxv3Data, endpoints []Nsxv3Resource) error { 431 | clients := map[string]Nsxv3Client{ 432 | e.NSXv3Configuration.LoginHost: GetClient(e.NSXv3Configuration), 433 | } 434 | 435 | chSize := len(endpoints) 436 | 437 | ch := make(chan error, chSize) 438 | 439 | for id := range endpoints { 440 | host := endpoints[id].request.URL.Host 441 | if host == "" { 442 | host = e.NSXv3Configuration.LoginHost 443 | } 444 | client, ok := clients[host] 445 | if !ok { 446 | config := e.NSXv3Configuration 447 | config.LoginHost = host 448 | client = GetClient(config) 449 | clients[host] = client 450 | } 451 | go e.updateData(data, &client, &endpoints[id], ch) 452 | } 453 | 454 | var errs []interface{} 455 | 456 | for i := 0; i < chSize; i++ { 457 | select { 458 | case err := <-ch: 459 | if err != nil { 460 | errs = append(errs, err) 461 | } 462 | } 463 | } 464 | 465 | if len(errs) != 0 { 466 | e := errors.New("Data collection completed with errors") 467 | for _, err := range errs { 468 | log.Error(err) 469 | } 470 | return e 471 | } 472 | 473 | return nil 474 | } 475 | 476 | func (e *Exporter) gather(data *Nsxv3Data) error { 477 | log.Info("Data collection started") 478 | data.ClusterHost = e.NSXv3Configuration.LoginHost 479 | 480 | var err error 481 | 482 | err = e.gatherWave( 483 | data, 484 | []Nsxv3Resource{ 485 | getEndpointStatus(ManagementCluster, ""), 486 | getEndpointStatus(ManagementClusterNodes, ""), 487 | getEndpointStatus(LogicalSwitchAdmin, ""), 488 | getEndpointStatus(LogicalSwitch, ""), 489 | getEndpointStatus(TransportNode, ""), 490 | getEndpointStatus(TransportNodes, ""), 491 | getEndpointStatus(LogicalPort, ""), 492 | getEndpointStatus(ActivityFrameworkStatistics, ""), 493 | }) 494 | 495 | if err != nil { 496 | return err 497 | } 498 | 499 | endpoints := []Nsxv3Resource{} 500 | for _, element := range data.ManagementNodes { 501 | endpoints = append(endpoints, 502 | getEndpointStatus(ManagerNodeFirewall, element.IP), 503 | getEndpointStatus(ManagerNodeFirewallSections, element.IP)) 504 | } 505 | 506 | err = e.gatherWave(data, endpoints) 507 | 508 | if err != nil { 509 | return err 510 | } 511 | 512 | data.ExtractedActualValues = true 513 | data.LastSuccessfulDataFetch = float64(time.Now().Unix()) 514 | 515 | log.Info("Data collection completed") 516 | return nil 517 | } 518 | 519 | func (e *Exporter) updateData(data *Nsxv3Data, client *Nsxv3Client, status *Nsxv3Resource, ch chan error) { 520 | client.updateEndpointStatus(status) 521 | 522 | if status.err != nil { 523 | ch <- status.err 524 | return 525 | } 526 | 527 | cursor, err := handle(data, status) 528 | 529 | if err == nil { 530 | if cursor == noCursor { 531 | ch <- nil 532 | return 533 | } 534 | 535 | nextStatus := getEndpointStatus(status.kind, status.request.URL.Host) 536 | 537 | query, _ := url.ParseQuery(nextStatus.request.URL.RawQuery) 538 | query.Add("cursor", cursor) 539 | nextStatus.request.URL.RawQuery = query.Encode() 540 | 541 | e.updateData(data, client, &nextStatus, ch) 542 | } else { 543 | ch <- err 544 | } 545 | } 546 | -------------------------------------------------------------------------------- /exporter/http.go: -------------------------------------------------------------------------------- 1 | package exporter 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "encoding/json" 7 | "fmt" 8 | "io/ioutil" 9 | "net" 10 | "net/http" 11 | "net/url" 12 | "strings" 13 | "time" 14 | 15 | "golang.org/x/time/rate" 16 | 17 | nsxv3config "github.com/sapcc/nsx-t-exporter/config" 18 | log "github.com/sirupsen/logrus" 19 | ) 20 | 21 | const pathCreateSession = "/api/session/create" 22 | const httpHeaderAcceptJSON = "application/json" 23 | const httpHarderContentTypeJSON = "application/json" 24 | 25 | // Nsxv3Client represents connection to NSXc3 Manger 26 | type Nsxv3Client struct { 27 | config nsxv3config.NSXv3Configuration 28 | client http.Client 29 | cookie string 30 | token string 31 | limiter *rate.Limiter 32 | context context.Context 33 | } 34 | 35 | // Nsxv3ResourceKind represents Nsxv3Resource type 36 | type Nsxv3ResourceKind string 37 | 38 | // Nsxv3Resource resource kinds 39 | const ( 40 | ManagementCluster Nsxv3ResourceKind = "ManagementCluster" 41 | ManagementClusterNodes Nsxv3ResourceKind = "ManagementClusterNodes" 42 | ManagerNodeFirewall Nsxv3ResourceKind = "ManagerNodeFirewall" 43 | ManagerNodeFirewallSections Nsxv3ResourceKind = "ManagerNodeFirewallSections" 44 | TransportNode Nsxv3ResourceKind = "TransportNode" 45 | TransportNodes Nsxv3ResourceKind = "TransportNodes" 46 | LogicalSwitchAdmin Nsxv3ResourceKind = "LogicalSwitchAdmin" 47 | LogicalSwitch Nsxv3ResourceKind = "LogicalSwitch" 48 | LogicalPort Nsxv3ResourceKind = "LogicalPort" 49 | ActivityFrameworkStatistics Nsxv3ResourceKind = "ActivityFrameworkStatistics" 50 | ) 51 | 52 | // Nsxv3Resource represents endpoint status snapshot 53 | type Nsxv3Resource struct { 54 | request *http.Request 55 | response *http.Response 56 | kind Nsxv3ResourceKind 57 | state map[string]interface{} // JSON 58 | err error 59 | } 60 | 61 | // GetClient initialize NSXv3 http client 62 | func GetClient(c nsxv3config.NSXv3Configuration) Nsxv3Client { 63 | timeout := time.Duration(c.RequestTimeout) * time.Second 64 | 65 | var netTransport = &http.Transport{ 66 | Dial: (&net.Dialer{ 67 | Timeout: timeout, 68 | KeepAlive: timeout, 69 | }).Dial, 70 | TLSHandshakeTimeout: timeout, 71 | IdleConnTimeout: timeout, 72 | TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SuppressSslWarnings}, 73 | MaxIdleConns: c.RequestsConnPoolSize, 74 | MaxIdleConnsPerHost: c.RequestsConnPoolSize, 75 | } 76 | 77 | return Nsxv3Client{ 78 | config: c, 79 | client: http.Client{ 80 | Timeout: timeout, 81 | Transport: netTransport, 82 | }, 83 | limiter: rate.NewLimiter(rate.Limit(c.RequestsPerSecond), 1), 84 | context: context.Background(), 85 | } 86 | } 87 | 88 | // login to NSXv3 manager 89 | func (c *Nsxv3Client) login(force bool) error { 90 | 91 | if !force && (c.cookie != "" || c.token != "") { 92 | return nil 93 | } 94 | 95 | requestBody := url.Values{} 96 | requestBody.Set("j_username", c.config.LoginUser) 97 | requestBody.Set("j_password", c.config.LoginPassword) 98 | 99 | req, err := http.NewRequest( 100 | "POST", 101 | fmt.Sprintf("https://%s%s", c.config.LoginHost, pathCreateSession), 102 | strings.NewReader(requestBody.Encode())) 103 | 104 | if err != nil { 105 | return err 106 | } 107 | 108 | req.Header.Add("Content-Type", "application/x-www-form-urlencoded") 109 | 110 | resp, err := c.executeRequest(req) 111 | 112 | if err != nil { 113 | return err 114 | } 115 | defer resp.Body.Close() 116 | 117 | c.cookie = resp.Header.Get("Set-Cookie") 118 | c.token = resp.Header.Get("X-XSRF-TOKEN") 119 | return nil 120 | } 121 | 122 | // AsyncGetRequest executes http get requests in an async mode 123 | func (c *Nsxv3Client) updateEndpointStatus(status *Nsxv3Resource) { 124 | c.login(false) 125 | 126 | if status.request.URL.Host == "" { 127 | status.request.URL.Host = c.config.LoginHost 128 | } 129 | status.request.URL.Scheme = "https" 130 | status.request.Header = http.Header{} 131 | status.request.Header.Set("Accept", httpHeaderAcceptJSON) 132 | status.request.Header.Set("Content-Type", httpHarderContentTypeJSON) 133 | status.request.Header.Set("Cookie", c.cookie) 134 | status.request.Header.Set("X-XSRF-TOKEN", c.token) 135 | 136 | status.response, status.err = c.executeRequest(status.request) 137 | 138 | if status.err != nil { 139 | return 140 | } 141 | 142 | if !(status.response.StatusCode >= 200 && status.response.StatusCode <= 299) { 143 | status.err = fmt.Errorf("Request to endpoint %v failed with %d", status.kind, status.response.StatusCode) 144 | return 145 | } 146 | 147 | defer status.response.Body.Close() 148 | 149 | var body []byte 150 | 151 | body, status.err = ioutil.ReadAll(status.response.Body) 152 | 153 | if status.err != nil { 154 | return 155 | } 156 | 157 | status.err = json.Unmarshal(body, &status.state) 158 | } 159 | 160 | func (c *Nsxv3Client) executeRequest(req *http.Request) (*http.Response, error) { 161 | var cancel context.CancelFunc 162 | var childContext context.Context 163 | 164 | if c.limiter.Allow() == false { 165 | childContext, cancel = context.WithTimeout( 166 | c.context, 167 | time.Duration(c.config.RequestsPerSecondTimeout)*time.Second) 168 | 169 | err := c.limiter.Wait(childContext) 170 | if err != nil && cancel != nil { 171 | log.Error(err) 172 | cancel() 173 | return nil, err 174 | } 175 | } 176 | 177 | resp, err := c.client.Do(req) 178 | 179 | if err != nil && cancel != nil { 180 | cancel() 181 | } 182 | return resp, err 183 | } 184 | -------------------------------------------------------------------------------- /exporter/metrics.go: -------------------------------------------------------------------------------- 1 | package exporter 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | log "github.com/sirupsen/logrus" 6 | ) 7 | 8 | // GetMetricsDescription - creates Prometheus metrics description 9 | func GetMetricsDescription() map[string]*prometheus.Desc { 10 | 11 | APIMetrics := make(map[string]*prometheus.Desc) 12 | 13 | APIMetrics["ManagementClusterStatus"] = prometheus.NewDesc( 14 | prometheus.BuildFQName("nsxv3", "cluster_management", "status"), 15 | "NSX-T management cluster status - STABLE=1, INITIALIZING=0, UNSTABLE=-1, DEGRADED=-2, UNKNOWN=-3", 16 | []string{"nsxv3_manager_hostname"}, nil, 17 | ) 18 | 19 | APIMetrics["ManagementClusterLastSuccessfulConnection"] = prometheus.NewDesc( 20 | prometheus.BuildFQName("nsxv3", "cluster_management", "last_successful_data_fetch"), 21 | "NSX-T last successful data fetch in UNIX timestamp converted to float64", 22 | []string{"nsxv3_manager_hostname"}, nil, 23 | ) 24 | 25 | APIMetrics["ControlClusterStatus"] = prometheus.NewDesc( 26 | prometheus.BuildFQName("nsxv3", "cluster_control", "status"), 27 | "NSX-T control cluster status - STABLE=1, NO_CONTROLLERS=0, UNSTABLE=-1, DEGRADED=-2, UNKNOWN=-3", 28 | []string{"nsxv3_manager_hostname"}, nil, 29 | ) 30 | 31 | APIMetrics["ManagementClusterNodesOnline"] = prometheus.NewDesc( 32 | prometheus.BuildFQName("nsxv3", "cluster_management", "online_nodes"), 33 | "NSX-T management cluster online nodes", 34 | []string{"nsxv3_manager_hostname"}, nil, 35 | ) 36 | 37 | APIMetrics["ManagementClusterNodesOffline"] = prometheus.NewDesc( 38 | prometheus.BuildFQName("nsxv3", "cluster_management", "offline_nodes"), 39 | "NSX-T management cluster offline nodes", 40 | []string{"nsxv3_manager_hostname"}, nil, 41 | ) 42 | 43 | APIMetrics["ManagementNodeConnectivity"] = prometheus.NewDesc( 44 | prometheus.BuildFQName("nsxv3", "management_node", "connectivity"), 45 | "NSX-T management node connectivity - CONNECTED > 0, DISCONNECTED = 0, UNKNOWN < 0", 46 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 47 | ) 48 | 49 | APIMetrics["ManagementNodeVersion"] = prometheus.NewDesc( 50 | prometheus.BuildFQName("nsxv3", "management_node", "version"), 51 | "NSX-T management node version", 52 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip", "nsxv3_node_version"}, nil, 53 | ) 54 | 55 | APIMetrics["ManagementNodeCpuCores"] = prometheus.NewDesc( 56 | prometheus.BuildFQName("nsxv3", "management_node", "cpu_cores"), 57 | "NSX-T management node cpu cores", 58 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 59 | ) 60 | 61 | APIMetrics["ManagementNodeLoadAverage"] = prometheus.NewDesc( 62 | prometheus.BuildFQName("nsxv3", "management_node", "load_average"), 63 | "NSX-T management node average load", 64 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip", "minutes"}, nil, 65 | ) 66 | 67 | APIMetrics["ManagementNodeMemoryUse"] = prometheus.NewDesc( 68 | prometheus.BuildFQName("nsxv3", "management_node", "memory_use"), 69 | "NSX-T management node memory use", 70 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 71 | ) 72 | 73 | APIMetrics["ManagementNodeMemoryTotal"] = prometheus.NewDesc( 74 | prometheus.BuildFQName("nsxv3", "management_node", "memory_total"), 75 | "NSX-T management node memory total", 76 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 77 | ) 78 | 79 | APIMetrics["ManagementNodeMemoryCached"] = prometheus.NewDesc( 80 | prometheus.BuildFQName("nsxv3", "management_node", "memory_cached"), 81 | "NSX-T management node cached memory", 82 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 83 | ) 84 | 85 | APIMetrics["ManagementNodeSwapUse"] = prometheus.NewDesc( 86 | prometheus.BuildFQName("nsxv3", "management_node", "swap_use"), 87 | "NSX-T management node swap use", 88 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 89 | ) 90 | 91 | APIMetrics["ManagementNodeSwapTotal"] = prometheus.NewDesc( 92 | prometheus.BuildFQName("nsxv3", "management_node", "swap_total"), 93 | "NSX-T management node swap total", 94 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 95 | ) 96 | 97 | APIMetrics["ManagementNodeStorageUse"] = prometheus.NewDesc( 98 | prometheus.BuildFQName("nsxv3", "management_node", "storage_use"), 99 | "NSX-T management node storage use", 100 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip", "filesystem"}, nil, 101 | ) 102 | 103 | APIMetrics["ManagementNodeStorageTotal"] = prometheus.NewDesc( 104 | prometheus.BuildFQName("nsxv3", "management_node", "storage_total"), 105 | "NSX-T management node storage total", 106 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip", "filesystem"}, nil, 107 | ) 108 | 109 | APIMetrics["ManagerNodeFirewallTotalSectionCount"] = prometheus.NewDesc( 110 | prometheus.BuildFQName("nsxv3", "management_node_firewall", "total_section_count"), 111 | "NSX-T management node firewall all sections type count", 112 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 113 | ) 114 | 115 | APIMetrics["ManagerNodeFirewallSectionCount"] = prometheus.NewDesc( 116 | prometheus.BuildFQName("nsxv3", "management_node_firewall", "section_count"), 117 | "NSX-T management node firewall L3 section count", 118 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 119 | ) 120 | 121 | APIMetrics["ManagerNodeFirewallRuleCount"] = prometheus.NewDesc( 122 | prometheus.BuildFQName("nsxv3", "management_node_firewall", "rule_count"), 123 | "NSX-T management node firewall L3 rule count", 124 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 125 | ) 126 | 127 | APIMetrics["ControlNodeConnectivity"] = prometheus.NewDesc( 128 | prometheus.BuildFQName("nsxv3", "control_node", "connectivity"), 129 | "NSX-T control node connectivity - CONNECTED=1, DISCONNECTED=0, UNKNOWN=-1", 130 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 131 | ) 132 | 133 | APIMetrics["ControlNodeManagementConnectivity"] = prometheus.NewDesc( 134 | prometheus.BuildFQName("nsxv3", "control_node", "management_connectivity"), 135 | "NSX-T control node management connectivity - CONNECTED > 0, DISCONNECTED = 0, UNKNOWN < 0", 136 | []string{"nsxv3_manager_hostname", "nsxv3_node_ip"}, nil, 137 | ) 138 | 139 | APIMetrics["TransportNodesUp"] = prometheus.NewDesc( 140 | prometheus.BuildFQName("nsxv3", "transport_nodes", "up"), 141 | "NSX-T transport nodes with state up", 142 | []string{"nsxv3_manager_hostname"}, nil, 143 | ) 144 | 145 | APIMetrics["TransportNodesDegraded"] = prometheus.NewDesc( 146 | prometheus.BuildFQName("nsxv3", "transport_nodes", "degraded"), 147 | "NSX-T transport nodes with state degraded", 148 | []string{"nsxv3_manager_hostname"}, nil, 149 | ) 150 | 151 | APIMetrics["TransportNodesDown"] = prometheus.NewDesc( 152 | prometheus.BuildFQName("nsxv3", "transport_nodes", "down"), 153 | "NSX-T transport nodes with state down", 154 | []string{"nsxv3_manager_hostname"}, nil, 155 | ) 156 | 157 | APIMetrics["TransportNodesUnknown"] = prometheus.NewDesc( 158 | prometheus.BuildFQName("nsxv3", "transport_nodes", "unknown"), 159 | "NSX-T transport nodes with state unknown", 160 | []string{"nsxv3_manager_hostname"}, nil, 161 | ) 162 | 163 | APIMetrics["TransportNodeState"] = prometheus.NewDesc( 164 | prometheus.BuildFQName("nsxv3", "transport_node", "state"), 165 | "NSX-T transport node state - SUCCESS=1, IN_PROGRESS=0, PENDING=-1, FAILED=-2, PARTIAL_SUCCESS=-3, ORPHANED=-4, UNKNOWN=-5", 166 | []string{"nsxv3_manager_hostname", "nsxv3_node_id"}, nil, 167 | ) 168 | 169 | APIMetrics["TransportNodeDeploymentState"] = prometheus.NewDesc( 170 | prometheus.BuildFQName("nsxv3", "transport_node", "deployment_state"), 171 | "NSX-T transport node deployment state - SUCCESS=1, IN_PROGRESS=0, PENDING=-1, FAILED=-2, PARTIAL_SUCCESS=-3, ORPHANED=-4, UNKNOWN=-5", 172 | []string{"nsxv3_manager_hostname", "nsxv3_node_id"}, nil, 173 | ) 174 | 175 | APIMetrics["LogicalSwitchAdminState"] = prometheus.NewDesc( 176 | prometheus.BuildFQName("nsxv3", "logical_switch", "admin_state"), 177 | "NSX-T logical switch admin state - UP=1, DOWN=0", 178 | []string{"nsxv3_manager_hostname", "name", "id"}, nil, 179 | ) 180 | 181 | APIMetrics["LogicalPortOperationalState"] = prometheus.NewDesc( 182 | prometheus.BuildFQName("nsxv3", "logical_port", "operational_state"), 183 | "NSX-T logical port operational state - UP=1, DOWN=0, UNKNOWN=-1", 184 | []string{"nsxv3_manager_hostname", "id", "transport_node_id"}, nil, 185 | ) 186 | 187 | APIMetrics["LogicalSwitchState"] = prometheus.NewDesc( 188 | prometheus.BuildFQName("nsxv3", "logical_switch", "state"), 189 | "NSX-T logical switch overall state - SUCCESS=1, IN_PROGRESS=0, FAILED=-1, PARTIAL_SUCCESS=-2, ORPHANED=-3, UNKNOWN=-4", 190 | []string{"nsxv3_manager_hostname", "id"}, nil, 191 | ) 192 | 193 | APIMetrics["SchedulerTotalComplete"] = prometheus.NewDesc( 194 | prometheus.BuildFQName("nsxv3", "scheduler", "total_complete"), 195 | "NSX-T Scheduler total completed jobs", 196 | []string{"nsxv3_manager_hostname"}, nil, 197 | ) 198 | 199 | APIMetrics["SchedulerTotalExecuting"] = prometheus.NewDesc( 200 | prometheus.BuildFQName("nsxv3", "scheduler", "total_executing"), 201 | "NSX-T Scheduler total executing jobs", 202 | []string{"nsxv3_manager_hostname"}, nil, 203 | ) 204 | 205 | APIMetrics["SchedulerTotalQueued"] = prometheus.NewDesc( 206 | prometheus.BuildFQName("nsxv3", "scheduler", "total_queued"), 207 | "NSX-T Scheduler total queued jobs", 208 | []string{"nsxv3_manager_hostname"}, nil, 209 | ) 210 | 211 | APIMetrics["SchedulerTotalScheduled"] = prometheus.NewDesc( 212 | prometheus.BuildFQName("nsxv3", "scheduler", "total_scheduled"), 213 | "NSX-T Scheduler total scheduled jobs", 214 | []string{"nsxv3_manager_hostname"}, nil, 215 | ) 216 | 217 | APIMetrics["SchedulerTotalSuspended"] = prometheus.NewDesc( 218 | prometheus.BuildFQName("nsxv3", "scheduler", "total_suspended"), 219 | "NSX-T Scheduler total suspended jobs", 220 | []string{"nsxv3_manager_hostname"}, nil, 221 | ) 222 | 223 | return APIMetrics 224 | } 225 | 226 | // processMetrics - processes the response data and sets the metrics using it as a source 227 | func (e *Exporter) processMetrics(data *Nsxv3Data, ch chan<- prometheus.Metric) error { 228 | if !data.ExtractedActualValues { 229 | log.Warn("Metrics processing completed with error, will not report any metrics.") 230 | return nil 231 | } 232 | 233 | // Prometheus scrape metric callback (concurrent) 234 | ch <- prometheus.MustNewConstMetric( 235 | e.APIMetrics["ManagementClusterStatus"], 236 | prometheus.GaugeValue, 237 | data.ClusterManagementStatus, 238 | data.ClusterHost) 239 | ch <- prometheus.MustNewConstMetric( 240 | e.APIMetrics["ControlClusterStatus"], 241 | prometheus.GaugeValue, 242 | data.ClusterControlStatus, 243 | data.ClusterHost) 244 | ch <- prometheus.MustNewConstMetric( 245 | e.APIMetrics["ManagementClusterNodesOnline"], 246 | prometheus.GaugeValue, 247 | data.ClusterOnlineNodes, 248 | data.ClusterHost) 249 | ch <- prometheus.MustNewConstMetric( 250 | e.APIMetrics["ManagementClusterNodesOffline"], 251 | prometheus.GaugeValue, 252 | data.ClusterOfflineNodes, 253 | data.ClusterHost) 254 | ch <- prometheus.MustNewConstMetric( 255 | e.APIMetrics["ManagementClusterLastSuccessfulConnection"], 256 | prometheus.GaugeValue, 257 | data.LastSuccessfulDataFetch, 258 | data.ClusterHost) 259 | ch <- prometheus.MustNewConstMetric( 260 | e.APIMetrics["TransportNodesUp"], 261 | prometheus.GaugeValue, 262 | data.TransportNodesState.UpCount, 263 | data.ClusterHost) 264 | ch <- prometheus.MustNewConstMetric( 265 | e.APIMetrics["TransportNodesDegraded"], 266 | prometheus.GaugeValue, 267 | data.TransportNodesState.DegradedCount, 268 | data.ClusterHost) 269 | ch <- prometheus.MustNewConstMetric( 270 | e.APIMetrics["TransportNodesDown"], 271 | prometheus.GaugeValue, 272 | data.TransportNodesState.DownCount, 273 | data.ClusterHost) 274 | ch <- prometheus.MustNewConstMetric( 275 | e.APIMetrics["TransportNodesUnknown"], 276 | prometheus.GaugeValue, 277 | data.TransportNodesState.UnknownCount, 278 | data.ClusterHost) 279 | ch <- prometheus.MustNewConstMetric( 280 | e.APIMetrics["SchedulerTotalComplete"], 281 | prometheus.GaugeValue, 282 | data.Scheduler.TotalComplete, 283 | data.ClusterHost) 284 | ch <- prometheus.MustNewConstMetric( 285 | e.APIMetrics["SchedulerTotalExecuting"], 286 | prometheus.GaugeValue, 287 | data.Scheduler.TotalExecuting, 288 | data.ClusterHost) 289 | ch <- prometheus.MustNewConstMetric( 290 | e.APIMetrics["SchedulerTotalQueued"], 291 | prometheus.GaugeValue, 292 | data.Scheduler.TotalQueued, 293 | data.ClusterHost) 294 | ch <- prometheus.MustNewConstMetric( 295 | e.APIMetrics["SchedulerTotalScheduled"], 296 | prometheus.GaugeValue, 297 | data.Scheduler.TotalScheduled, 298 | data.ClusterHost) 299 | ch <- prometheus.MustNewConstMetric( 300 | e.APIMetrics["SchedulerTotalSuspended"], 301 | prometheus.GaugeValue, 302 | data.Scheduler.TotalSuspended, 303 | data.ClusterHost) 304 | 305 | for _, element := range data.ManagementNodes { 306 | e.processManagementNodeMetrics(data.ClusterHost, &element, ch) 307 | } 308 | 309 | for _, element := range data.ControlNodes { 310 | e.processControlNodeMetrics(data.ClusterHost, &element, ch) 311 | } 312 | 313 | for _, element := range data.TransportNodes { 314 | e.processTransportNodeMetrics(data.ClusterHost, &element, ch) 315 | } 316 | 317 | for _, element := range data.LogicalSwitchesAdminStates { 318 | e.processLogicalSwitchAdminStateMetrics(data.ClusterHost, &element, ch) 319 | } 320 | 321 | for _, element := range data.LogicalSwitchesStates { 322 | e.processLogicalSwitchStateMetrics(data.ClusterHost, &element, ch) 323 | } 324 | 325 | for _, element := range data.LogicalPortOperationalStates { 326 | e.processLogicalPortOperationalStateMetrics(data.ClusterHost, &element, ch) 327 | } 328 | 329 | return nil 330 | 331 | } 332 | 333 | func (e *Exporter) processManagementNodeMetrics(host string, data *Nsxv3ManagementNodeData, ch chan<- prometheus.Metric) error { 334 | ch <- prometheus.MustNewConstMetric( 335 | e.APIMetrics["ManagementNodeConnectivity"], 336 | prometheus.GaugeValue, 337 | data.Connectivity, 338 | host, data.IP) 339 | ch <- prometheus.MustNewConstMetric( 340 | e.APIMetrics["ManagementNodeVersion"], 341 | prometheus.CounterValue, 342 | 1, 343 | host, data.IP, data.Version) 344 | ch <- prometheus.MustNewConstMetric( 345 | e.APIMetrics["ManagementNodeCpuCores"], 346 | prometheus.GaugeValue, 347 | data.CPUCores, 348 | host, data.IP) 349 | ch <- prometheus.MustNewConstMetric( 350 | e.APIMetrics["ManagementNodeLoadAverage"], 351 | prometheus.GaugeValue, 352 | data.LoadAverage[0], 353 | host, data.IP, "1") // 1 minute 354 | ch <- prometheus.MustNewConstMetric( 355 | e.APIMetrics["ManagementNodeLoadAverage"], 356 | prometheus.GaugeValue, 357 | data.LoadAverage[1], 358 | host, data.IP, "5") // 5 minutes 359 | ch <- prometheus.MustNewConstMetric( 360 | e.APIMetrics["ManagementNodeLoadAverage"], 361 | prometheus.GaugeValue, 362 | data.LoadAverage[2], 363 | host, data.IP, "15") // 15 minutes 364 | 365 | ch <- prometheus.MustNewConstMetric( 366 | e.APIMetrics["ManagementNodeMemoryUse"], 367 | prometheus.GaugeValue, 368 | data.MemoryUse, 369 | host, data.IP) 370 | ch <- prometheus.MustNewConstMetric( 371 | e.APIMetrics["ManagementNodeMemoryTotal"], 372 | prometheus.GaugeValue, 373 | data.MemoryTotal, 374 | host, data.IP) 375 | ch <- prometheus.MustNewConstMetric( 376 | e.APIMetrics["ManagementNodeMemoryCached"], 377 | prometheus.GaugeValue, 378 | data.MemoryCached, 379 | host, data.IP) 380 | ch <- prometheus.MustNewConstMetric( 381 | e.APIMetrics["ManagementNodeSwapUse"], 382 | prometheus.GaugeValue, 383 | data.SwapUse, 384 | host, data.IP) 385 | ch <- prometheus.MustNewConstMetric( 386 | e.APIMetrics["ManagementNodeSwapTotal"], 387 | prometheus.GaugeValue, 388 | data.SwapTotal, 389 | host, data.IP) 390 | ch <- prometheus.MustNewConstMetric( 391 | e.APIMetrics["ManagerNodeFirewallTotalSectionCount"], 392 | prometheus.GaugeValue, 393 | data.TotalSectionCount, 394 | host, data.IP) 395 | ch <- prometheus.MustNewConstMetric( 396 | e.APIMetrics["ManagerNodeFirewallSectionCount"], 397 | prometheus.GaugeValue, 398 | data.L3DFWSectionCount, 399 | host, data.IP) 400 | ch <- prometheus.MustNewConstMetric( 401 | e.APIMetrics["ManagerNodeFirewallRuleCount"], 402 | prometheus.GaugeValue, 403 | data.L3DFWRuleCount, 404 | host, data.IP) 405 | 406 | for _, element := range data.Storage { 407 | ch <- prometheus.MustNewConstMetric( 408 | e.APIMetrics["ManagementNodeStorageTotal"], 409 | prometheus.GaugeValue, 410 | element.totalMetric, 411 | host, data.IP, element.filesystem) 412 | ch <- prometheus.MustNewConstMetric( 413 | e.APIMetrics["ManagementNodeStorageUse"], 414 | prometheus.GaugeValue, 415 | element.usedMetric, 416 | host, data.IP, element.filesystem) 417 | } 418 | 419 | return nil 420 | } 421 | 422 | func (e *Exporter) processControlNodeMetrics(host string, data *Nsxv3ControlNodeData, ch chan<- prometheus.Metric) error { 423 | 424 | ch <- prometheus.MustNewConstMetric( 425 | e.APIMetrics["ControlNodeConnectivity"], 426 | prometheus.GaugeValue, 427 | data.Connectivity, 428 | host, data.IP) 429 | 430 | ch <- prometheus.MustNewConstMetric( 431 | e.APIMetrics["ControlNodeManagementConnectivity"], 432 | prometheus.GaugeValue, 433 | data.ManagementConnectivity, 434 | host, data.IP) 435 | 436 | return nil 437 | } 438 | 439 | func (e *Exporter) processTransportNodeMetrics(host string, data *Nsxv3TransportNodeData, ch chan<- prometheus.Metric) error { 440 | 441 | ch <- prometheus.MustNewConstMetric( 442 | e.APIMetrics["TransportNodeState"], 443 | prometheus.GaugeValue, 444 | data.State, 445 | host, data.ID) 446 | 447 | ch <- prometheus.MustNewConstMetric( 448 | e.APIMetrics["TransportNodeDeploymentState"], 449 | prometheus.GaugeValue, 450 | data.DeploymentState, 451 | host, data.ID) 452 | 453 | return nil 454 | } 455 | 456 | func (e *Exporter) processLogicalSwitchAdminStateMetrics(host string, data *Nsxv3LogicalSwitchAdminStateData, ch chan<- prometheus.Metric) error { 457 | 458 | ch <- prometheus.MustNewConstMetric( 459 | e.APIMetrics["LogicalSwitchAdminState"], 460 | prometheus.GaugeValue, 461 | data.adminStateMetric, 462 | host, data.name, data.id) 463 | 464 | return nil 465 | } 466 | 467 | func (e *Exporter) processLogicalPortOperationalStateMetrics(host string, data *Nsxv3LogicalPortOperationalStateData, ch chan<- prometheus.Metric) error { 468 | ch <- prometheus.MustNewConstMetric( 469 | e.APIMetrics["LogicalPortOperationalState"], 470 | prometheus.GaugeValue, 471 | data.operationalStateMetric, 472 | host, data.id, data.hostID) 473 | 474 | return nil 475 | } 476 | 477 | func (e *Exporter) processLogicalSwitchStateMetrics(host string, data *Nsxv3LogicalSwitchStateData, ch chan<- prometheus.Metric) error { 478 | 479 | ch <- prometheus.MustNewConstMetric( 480 | e.APIMetrics["LogicalSwitchState"], 481 | prometheus.GaugeValue, 482 | data.stateMetric, 483 | host, data.id) 484 | 485 | return nil 486 | } 487 | -------------------------------------------------------------------------------- /exporter/prometheus.go: -------------------------------------------------------------------------------- 1 | package exporter 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | log "github.com/sirupsen/logrus" 6 | ) 7 | 8 | // Describe the API metrics in Prometheus 9 | func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { 10 | 11 | for _, m := range e.APIMetrics { 12 | ch <- m 13 | } 14 | 15 | } 16 | 17 | // CollectAsync - Asynchronously scraps the API and stores into struct 18 | func (e *Exporter) CollectAsync() { 19 | 20 | data := Nsxv3Data{} 21 | err := e.gather(&data) 22 | 23 | // in case of error, keep the previously acquired data (cache) 24 | // otherwise update the existing cache 25 | if err != nil { 26 | log.Errorf("Error gathering Data from remote API: %v", err) 27 | return 28 | } 29 | e.Cache = data 30 | } 31 | 32 | // Collect is a Prometheus callback for scrape operations (/metrics page) 33 | func (e *Exporter) Collect(ch chan<- prometheus.Metric) { 34 | 35 | // Set Prometheus gauge metrics using the e.Cache 36 | err := e.processMetrics(&e.Cache, ch) 37 | 38 | if err != nil { 39 | log.Error("Error Processing Metrics", err) 40 | return 41 | } 42 | 43 | log.Info("All Metrics successfully collected") 44 | 45 | } 46 | -------------------------------------------------------------------------------- /exporter/structs.go: -------------------------------------------------------------------------------- 1 | package exporter 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | "github.com/sapcc/nsx-t-exporter/config" 6 | ) 7 | 8 | // Exporter is used to store Metrics data and embeds the config struct. 9 | // This is done so that the relevant functions have easy access to the 10 | // user defined runtime configuration when the Collect method is called. 11 | type Exporter struct { 12 | Cache Nsxv3Data 13 | APIMetrics map[string]*prometheus.Desc 14 | config.NSXv3Configuration 15 | } 16 | 17 | // Nsxv3LogicalSwitchAdminStateData represent the current snapshot of metrics 18 | // for a logical switch admin state 19 | type Nsxv3LogicalSwitchAdminStateData struct { 20 | adminStateMetric float64 21 | name string 22 | id string 23 | } 24 | 25 | // Nsxv3LogicalPortOperationalStateData represent the current snapshot of metrics 26 | // for a logical port operational state 27 | type Nsxv3LogicalPortOperationalStateData struct { 28 | operationalStateMetric float64 29 | id string 30 | hostID string // Transport Node ID 31 | } 32 | 33 | // Nsxv3LogicalSwitchStateData represent the current snapshot of metrics 34 | // for a logical switch state 35 | type Nsxv3LogicalSwitchStateData struct { 36 | stateMetric float64 37 | id string 38 | } 39 | 40 | // Nsxv3NodeStorageData represent the current snapshot of metrics 41 | // for a single node filesystem 42 | type Nsxv3NodeStorageData struct { 43 | usedMetric float64 44 | totalMetric float64 45 | filesystem string 46 | } 47 | 48 | // Nsxv3ManagementNodeData represent the current snapshot of metrics for a single management node 49 | type Nsxv3ManagementNodeData struct { 50 | IP string 51 | Connectivity float64 52 | CPUCores float64 53 | // Average load index [0] := 1min, [1] := 5min, [2] := 15min 54 | LoadAverage [3]float64 55 | MemoryUse float64 56 | MemoryTotal float64 57 | MemoryCached float64 58 | SwapUse float64 59 | SwapTotal float64 60 | Storage []Nsxv3NodeStorageData 61 | Version string 62 | TotalSectionCount float64 63 | L3DFWSectionCount float64 64 | L3DFWRuleCount float64 65 | } 66 | 67 | // Nsxv3ControlNodeData represent the current snapshot of metrics for a single control node 68 | type Nsxv3ControlNodeData struct { 69 | IP string 70 | Connectivity float64 71 | ManagementConnectivity float64 72 | } 73 | 74 | // Nsxv3TransportNodeData represent the current snapshot of metrics for a single transport node 75 | type Nsxv3TransportNodeData struct { 76 | ID string 77 | State float64 78 | DeploymentState float64 79 | } 80 | 81 | // Nsxv3TransportNodesStateData represent the current snapshot of the transport nodes state 82 | type Nsxv3TransportNodesStateData struct { 83 | UpCount float64 84 | DegradedCount float64 85 | DownCount float64 86 | UnknownCount float64 87 | } 88 | 89 | type Nsxv3ActivityFrameworkSchedulerData struct { 90 | TotalQueued float64 91 | TotalScheduled float64 92 | TotalExecuting float64 93 | TotalSuspended float64 94 | TotalComplete float64 95 | } 96 | 97 | // Nsxv3Data represent the current snapshot of metrics 98 | type Nsxv3Data struct { 99 | ClusterHost string 100 | ClusterManagementStatus float64 101 | ClusterControlStatus float64 102 | ClusterOnlineNodes float64 103 | ClusterOfflineNodes float64 104 | DatabaseStatus float64 105 | ManagementNodes []Nsxv3ManagementNodeData 106 | ControlNodes []Nsxv3ControlNodeData 107 | TransportNodes []Nsxv3TransportNodeData 108 | TransportNodesState Nsxv3TransportNodesStateData 109 | LogicalSwitchesAdminStates []Nsxv3LogicalSwitchAdminStateData 110 | LogicalSwitchesStates []Nsxv3LogicalSwitchStateData 111 | ExtractedActualValues bool 112 | LastSuccessfulDataFetch float64 113 | LogicalPortOperationalStates []Nsxv3LogicalPortOperationalStateData 114 | Scheduler Nsxv3ActivityFrameworkSchedulerData 115 | } 116 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/sapcc/nsx-t-exporter 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/caarlos0/env/v6 v6.9.3 7 | github.com/fatih/structs v1.1.0 8 | github.com/prometheus/client_golang v1.20.3 9 | github.com/sirupsen/logrus v1.8.1 10 | golang.org/x/time v0.6.0 11 | ) 12 | 13 | require ( 14 | github.com/beorn7/perks v1.0.1 // indirect 15 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 16 | github.com/klauspost/compress v1.17.9 // indirect 17 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 18 | github.com/prometheus/client_model v0.6.1 // indirect 19 | github.com/prometheus/common v0.55.0 // indirect 20 | github.com/prometheus/procfs v0.15.1 // indirect 21 | golang.org/x/sys v0.22.0 // indirect 22 | google.golang.org/protobuf v1.34.2 // indirect 23 | ) 24 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "time" 8 | 9 | "github.com/sapcc/nsx-t-exporter/config" 10 | "github.com/sapcc/nsx-t-exporter/exporter" 11 | 12 | "github.com/fatih/structs" 13 | "github.com/prometheus/client_golang/prometheus" 14 | "github.com/prometheus/client_golang/prometheus/promhttp" 15 | log "github.com/sirupsen/logrus" 16 | ) 17 | 18 | var ( 19 | indexPage = ` 20 | NSX-T Exporter 21 | 22 |

NSX-T Prometheus Metrics Exporter

23 |

For more information, visit GitHub

24 |

Metrics

25 | 26 | ` 27 | ) 28 | 29 | var ( 30 | exporterConfig config.NSXv3Configuration 31 | metrics map[string]*prometheus.Desc 32 | ) 33 | 34 | func init() { 35 | // Log as JSON instead of the default ASCII formatter. 36 | log.SetFormatter(&log.JSONFormatter{}) 37 | 38 | // Output to stdout instead of the default stderr 39 | log.SetOutput(os.Stdout) 40 | 41 | exporterConfig = config.Init() 42 | 43 | metrics = exporter.GetMetricsDescription() 44 | } 45 | 46 | func main() { 47 | 48 | // Only log the warning severity or above. 49 | log.SetLevel(log.DebugLevel) 50 | 51 | // A common pattern is to re-use fields between logging statements 52 | loggingContext := exporterConfig 53 | loggingContext.LoginPassword = "*******" 54 | contextLogger := log.WithFields(structs.Map(loggingContext)) 55 | 56 | contextLogger.Info("Starting Exporter") 57 | 58 | exporter := exporter.Exporter{ 59 | APIMetrics: metrics, 60 | NSXv3Configuration: exporterConfig, 61 | } 62 | 63 | // Async scrap, required to reduce response time of /metrics API 64 | go func() { 65 | for { 66 | start := time.Now() 67 | exporter.CollectAsync() 68 | elapsed := time.Now().Sub(start) 69 | schedule := time.Duration(exporterConfig.ScrapScheduleSeconds) * time.Second 70 | time.Sleep(schedule - elapsed) 71 | } 72 | }() 73 | 74 | // Register Metrics from each of the endpoints 75 | // This invokes the Collect method through the prometheus client libraries. 76 | prometheus.MustRegister(&exporter) 77 | 78 | // Setup HTTP handler 79 | http.Handle("/metrics", promhttp.Handler()) 80 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 81 | w.Write([]byte(indexPage)) 82 | }) 83 | 84 | log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", exporterConfig.ScrapPort), nil)) 85 | } 86 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | --------------------------------------------------------------------------------