| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package couchdb |
| 4 | |
| 5 | // https://docs.couchdb.org/en/stable/api/index.html |
| 6 | |
| 7 | type cdbMetrics struct { |
| 8 | // https://docs.couchdb.org/en/stable/api/server/common.html#active-tasks |
| 9 | ActiveTasks []cdbActiveTask |
| 10 | // https://docs.couchdb.org/en/stable/api/server/common.html#node-node-name-stats |
| 11 | NodeStats *cdbNodeStats |
| 12 | // https://docs.couchdb.org/en/stable/api/server/common.html#node-node-name-system |
| 13 | NodeSystem *cdbNodeSystem |
| 14 | // https://docs.couchdb.org/en/stable/api/database/common.html |
| 15 | DBStats []cdbDBStats |
| 16 | } |
| 17 | |
| 18 | func (m cdbMetrics) empty() bool { |
| 19 | switch { |
| 20 | case m.hasActiveTasks(), m.hasNodeStats(), m.hasNodeSystem(), m.hasDBStats(): |
| 21 | return false |
| 22 | } |
| 23 | return true |
| 24 | } |
| 25 | |
| 26 | func (m cdbMetrics) hasActiveTasks() bool { return m.ActiveTasks != nil } |
| 27 | func (m cdbMetrics) hasNodeStats() bool { return m.NodeStats != nil } |
| 28 | func (m cdbMetrics) hasNodeSystem() bool { return m.NodeSystem != nil } |
| 29 | func (m cdbMetrics) hasDBStats() bool { return m.DBStats != nil } |
| 30 | |
| 31 | type cdbActiveTask struct { |
| 32 | Type string `json:"type"` |
| 33 | } |
| 34 | |
| 35 | type cdbNodeStats struct { |
| 36 | CouchDB struct { |
| 37 | DatabaseReads struct { |
| 38 | Value float64 `stm:"" json:"value"` |
| 39 | } `stm:"database_reads" json:"database_reads"` |
| 40 | DatabaseWrites struct { |
| 41 | Value float64 `stm:"" json:"value"` |
| 42 | } `stm:"database_writes" json:"database_writes"` |
| 43 | HTTPd struct { |
| 44 | ViewReads struct { |
| 45 | Value float64 `stm:"" json:"value"` |
| 46 | } `stm:"view_reads" json:"view_reads"` |
| 47 | } `stm:"httpd" json:"httpd"` |
| 48 | HTTPdRequestMethods struct { |
| 49 | Copy struct { |
| 50 | Value float64 `stm:"" json:"value"` |
| 51 | } `stm:"COPY" json:"COPY"` |
| 52 | Delete struct { |
| 53 | Value float64 `stm:"" json:"value"` |
| 54 | } `stm:"DELETE" json:"DELETE"` |
| 55 | Get struct { |
| 56 | Value float64 `stm:"" json:"value"` |
| 57 | } `stm:"GET" json:"GET"` |
| 58 | Head struct { |
| 59 | Value float64 `stm:"" json:"value"` |
| 60 | } `stm:"HEAD" json:"HEAD"` |
| 61 | Options struct { |
| 62 | Value float64 `stm:"" json:"value"` |
| 63 | } `stm:"OPTIONS" json:"OPTIONS"` |
| 64 | Post struct { |
| 65 | Value float64 `stm:"" json:"value"` |
| 66 | } `stm:"POST" json:"POST"` |
| 67 | Put struct { |
| 68 | Value float64 `stm:"" json:"value"` |
| 69 | } `stm:"PUT" json:"PUT"` |
| 70 | } `stm:"httpd_request_methods" json:"httpd_request_methods"` |
| 71 | HTTPdStatusCodes struct { |
| 72 | Code200 struct { |
| 73 | Value float64 `stm:"" json:"value"` |
| 74 | } `stm:"200" json:"200"` |
| 75 | Code201 struct { |
| 76 | Value float64 `stm:"" json:"value"` |
| 77 | } `stm:"201" json:"201"` |
| 78 | Code202 struct { |
| 79 | Value float64 `stm:"" json:"value"` |
| 80 | } `stm:"202" json:"202"` |
| 81 | Code204 struct { |
| 82 | Value float64 `stm:"" json:"value"` |
| 83 | } `stm:"204" json:"204"` |
| 84 | Code206 struct { |
| 85 | Value float64 `stm:"" json:"value"` |
| 86 | } `stm:"206" json:"206"` |
| 87 | Code301 struct { |
| 88 | Value float64 `stm:"" json:"value"` |
| 89 | } `stm:"301" json:"301"` |
| 90 | Code302 struct { |
| 91 | Value float64 `stm:"" json:"value"` |
| 92 | } `stm:"302" json:"302"` |
| 93 | Code304 struct { |
| 94 | Value float64 `stm:"" json:"value"` |
| 95 | } `stm:"304" json:"304"` |
| 96 | Code400 struct { |
| 97 | Value float64 `stm:"" json:"value"` |
| 98 | } `stm:"400" json:"400"` |
| 99 | Code401 struct { |
| 100 | Value float64 `stm:"" json:"value"` |
| 101 | } `stm:"401" json:"401"` |
| 102 | Code403 struct { |
| 103 | Value float64 `stm:"" json:"value"` |
| 104 | } `stm:"403" json:"403"` |
| 105 | Code404 struct { |
| 106 | Value float64 `stm:"" json:"value"` |
| 107 | } `stm:"404" json:"404"` |
| 108 | Code405 struct { |
| 109 | Value float64 `stm:"" json:"value"` |
| 110 | } `stm:"405" json:"405"` |
| 111 | Code406 struct { |
| 112 | Value float64 `stm:"" json:"value"` |
| 113 | } `stm:"406" json:"406"` |
| 114 | Code409 struct { |
| 115 | Value float64 `stm:"" json:"value"` |
| 116 | } `stm:"409" json:"409"` |
| 117 | Code412 struct { |
| 118 | Value float64 `stm:"" json:"value"` |
| 119 | } `stm:"412" json:"412"` |
| 120 | Code413 struct { |
| 121 | Value float64 `stm:"" json:"value"` |
| 122 | } `stm:"413" json:"413"` |
| 123 | Code414 struct { |
| 124 | Value float64 `stm:"" json:"value"` |
| 125 | } `stm:"414" json:"414"` |
| 126 | Code415 struct { |
| 127 | Value float64 `stm:"" json:"value"` |
| 128 | } `stm:"415" json:"415"` |
| 129 | Code416 struct { |
| 130 | Value float64 `stm:"" json:"value"` |
| 131 | } `stm:"416" json:"416"` |
| 132 | Code417 struct { |
| 133 | Value float64 `stm:"" json:"value"` |
| 134 | } `stm:"417" json:"417"` |
| 135 | Code500 struct { |
| 136 | Value float64 `stm:"" json:"value"` |
| 137 | } `stm:"500" json:"500"` |
| 138 | Code501 struct { |
| 139 | Value float64 `stm:"" json:"value"` |
| 140 | } `stm:"501" json:"501"` |
| 141 | Code503 struct { |
| 142 | Value float64 `stm:"" json:"value"` |
| 143 | } `stm:"503" json:"503"` |
| 144 | } `stm:"httpd_status_codes" json:"httpd_status_codes"` |
| 145 | OpenOSFiles struct { |
| 146 | Value float64 `stm:"" json:"value"` |
| 147 | } `stm:"open_os_files" json:"open_os_files"` |
| 148 | } `stm:"couchdb" json:"couchdb"` |
| 149 | CouchReplicator struct { |
| 150 | Jobs struct { |
| 151 | Running struct { |
| 152 | Value float64 `stm:"" json:"value"` |
| 153 | } `stm:"running" json:"running"` |
| 154 | Pending struct { |
| 155 | Value float64 `stm:"" json:"value"` |
| 156 | } `stm:"pending" json:"pending"` |
| 157 | Crashed struct { |
| 158 | Value float64 `stm:"" json:"value"` |
| 159 | } `stm:"crashed" json:"crashed"` |
| 160 | } `stm:"jobs" json:"jobs"` |
| 161 | } `stm:"couch_replicator" json:"couch_replicator"` |
| 162 | } |
| 163 | |
| 164 | type cdbNodeSystem struct { |
| 165 | Memory struct { |
| 166 | Other float64 `stm:"other" json:"other"` |
| 167 | Atom float64 `stm:"atom" json:"atom"` |
| 168 | AtomUsed float64 `stm:"atom_used" json:"atom_used"` |
| 169 | Processes float64 `stm:"processes" json:"processes"` |
| 170 | Binary float64 `stm:"binary" json:"binary"` |
| 171 | Code float64 `stm:"code" json:"code"` |
| 172 | Ets float64 `stm:"ets" json:"ets"` |
| 173 | } `stm:"memory" json:"memory"` |
| 174 | |
| 175 | RunQueue float64 `stm:"run_queue" json:"run_queue"` |
| 176 | EtsTableCount float64 `stm:"ets_table_count" json:"ets_table_count"` |
| 177 | ContextSwitches float64 `stm:"context_switches" json:"context_switches"` |
| 178 | Reductions float64 `stm:"reductions" json:"reductions"` |
| 179 | IOInput float64 `stm:"io_input" json:"io_input"` |
| 180 | IOOutput float64 `stm:"io_output" json:"io_output"` |
| 181 | OSProcCount float64 `stm:"os_proc_count" json:"os_proc_count"` |
| 182 | ProcessCount float64 `stm:"process_count" json:"process_count"` |
| 183 | InternalReplicationJobs float64 `stm:"internal_replication_jobs" json:"internal_replication_jobs"` |
| 184 | |
| 185 | MessageQueues map[string]any `json:"message_queues"` |
| 186 | } |
| 187 | |
| 188 | type cdbDBStats struct { |
| 189 | Key string |
| 190 | Error string |
| 191 | Info struct { |
| 192 | Sizes struct { |
| 193 | File float64 `stm:"file" json:"file"` |
| 194 | External float64 `stm:"external" json:"external"` |
| 195 | Active float64 `stm:"active" json:"active"` |
| 196 | } `stm:"db_sizes" json:"sizes"` |
| 197 | DocDelCount float64 `stm:"db_doc_del_counts" json:"doc_del_count"` |
| 198 | DocCount float64 `stm:"db_doc_counts" json:"doc_count"` |
| 199 | } |
| 200 | } |