top

Package metric provides server metrics (a.k.a. transient stats) for a CockroachDB server. These metrics are persisted to the time-series database and are viewable through the web interface and the /_status/metrics/<NODEID> HTTP endpoint.

Adding a new metric

First, add the metric to a Registry.

Next, call methods such as Counter() and Rate() on the Registry to register the metric. For example:

exec := &Executor{
	...
	selectCount: sqlRegistry.Counter("sql.select.count"),
	...
}

This code block registers the metric "sql.select.count" in sql.Registry. The metric can then be accessed through the "selectCount" variable, which can be updated as follows:

func (e *Executor) doSelect() {
	// do the SELECT
	e.selectCount.Inc(1)
}

To add the metric to the web UI, modify the appropriate file in "ui/ts/pages/*.ts". Someone more qualified than me can elaborate, like @maxlang.

Sub-registries

It's common for a Registry to become part of another Registry through the "Add" and "MustAdd" methods.

func NewNodeStatusMonitor(serverRegistry *registry) {
	nodeRegistry := metric.NewRegistry()

	// Add the registry for this node to the root-level server Registry. When
	// accessed from through the serverRegistry, all metrics from the
	// nodeRegistry will have the prefix "cr.node.".
	serverRegistry.MustAdd("cr.node.%s", nodeRegistry)
}

Node-level sub-registries are added by calling:

(*metric.MetricRecorder).AddNodeRegistry(YOUR_NODE_SUBREGISTRY)

Testing

After your test does something to trigger your new metric update, you'll probably want to call methods in TestServer such as MustGetSQLCounter() to verify that the metric was updated correctly. See "sql/metric_test.go" for an example.

Additionally, you can manually verify that your metric is updating by using the metrics endpoint. For example, if you're running the Cockroach DB server with the "--insecure" flag, you can use access the endpoint as follows:

$ curl http://localhost:8080/_status/nodes/1

(some other output)
"cr.node.sql.select.count.1": 5,
(some other output)

Note that a prefix and suffix have been added. The prefix "cr.node." denotes that this metric is node-level. The suffix ".1" specifies that this metric is for node 1.

Imported by 327 package(s)

  1. github.com/756445638/cockroach/gossip
  2. github.com/756445638/cockroach/gossip/simulation
  3. github.com/756445638/cockroach/kv
  4. github.com/756445638/cockroach/rpc
  5. github.com/756445638/cockroach/server
  6. github.com/756445638/cockroach/server/status
  7. github.com/756445638/cockroach/sql
  8. github.com/756445638/cockroach/sql/pgwire
  9. github.com/756445638/cockroach/storage
  10. github.com/756445638/cockroach/storage/simulation
  11. github.com/756445638/cockroach/testutils/localtestcluster
  12. github.com/Aishraj/cockroach/gossip
  13. github.com/Aishraj/cockroach/gossip/simulation
  14. github.com/Aishraj/cockroach/kv
  15. github.com/Aishraj/cockroach/rpc
  16. github.com/Aishraj/cockroach/server
  17. github.com/Aishraj/cockroach/server/status
  18. github.com/Aishraj/cockroach/sql
  19. github.com/Aishraj/cockroach/sql/pgwire
  20. github.com/Aishraj/cockroach/storage
  21. github.com/Aishraj/cockroach/storage/simulation
  22. github.com/Aishraj/cockroach/testutils/localtestcluster
  23. github.com/JKhawaja/cockroach/kv
  24. github.com/JKhawaja/cockroach/rpc
  25. github.com/JKhawaja/cockroach/server
  26. github.com/JKhawaja/cockroach/sql
  27. github.com/JKhawaja/cockroach/storage
  28. github.com/YuleiXiao/cockroach/kv
  29. github.com/YuleiXiao/cockroach/rpc
  30. github.com/YuleiXiao/cockroach/server
  31. github.com/YuleiXiao/cockroach/server/status
  32. github.com/YuleiXiao/cockroach/sql
  33. github.com/YuleiXiao/cockroach/sql/pgwire
  34. github.com/YuleiXiao/cockroach/storage
  35. github.com/a10y/cockroach/gossip
  36. github.com/a10y/cockroach/gossip/simulation
  37. github.com/a10y/cockroach/kv
  38. github.com/a10y/cockroach/rpc
  39. github.com/a10y/cockroach/server
  40. github.com/a10y/cockroach/server/status
  41. github.com/a10y/cockroach/sql
  42. github.com/a10y/cockroach/sql/pgwire
  43. github.com/a10y/cockroach/storage
  44. github.com/a10y/cockroach/storage/simulation
  45. github.com/a10y/cockroach/testutils/localtestcluster
  46. github.com/abhi11/cockroach/server
  47. github.com/abhi11/cockroach/server/status
  48. github.com/abhi11/cockroach/sql
  49. github.com/abhi11/cockroach/sql/pgwire
  50. github.com/abhinavdahiya/cockroach/kv
  51. github.com/abhinavdahiya/cockroach/rpc
  52. github.com/abhinavdahiya/cockroach/server
  53. github.com/abhinavdahiya/cockroach/server/status
  54. github.com/abhinavdahiya/cockroach/sql
  55. github.com/abhinavdahiya/cockroach/sql/pgwire
  56. github.com/abhinavdahiya/cockroach/storage
  57. github.com/aishraj/cockroach/gossip
  58. github.com/aishraj/cockroach/gossip/simulation
  59. github.com/aishraj/cockroach/kv
  60. github.com/aishraj/cockroach/rpc
  61. github.com/aishraj/cockroach/server
  62. github.com/aishraj/cockroach/server/status
  63. github.com/aishraj/cockroach/sql
  64. github.com/aishraj/cockroach/sql/pgwire
  65. github.com/aishraj/cockroach/storage
  66. github.com/aishraj/cockroach/storage/simulation
  67. github.com/aishraj/cockroach/testutils/localtestcluster
  68. github.com/andreweduffy/cockroach/gossip
  69. github.com/andreweduffy/cockroach/gossip/simulation
  70. github.com/andreweduffy/cockroach/kv
  71. github.com/andreweduffy/cockroach/rpc
  72. github.com/andreweduffy/cockroach/server
  73. github.com/andreweduffy/cockroach/server/status
  74. github.com/andreweduffy/cockroach/sql
  75. github.com/andreweduffy/cockroach/sql/pgwire
  76. github.com/andreweduffy/cockroach/storage
  77. github.com/andreweduffy/cockroach/storage/simulation
  78. github.com/andreweduffy/cockroach/testutils/localtestcluster
  79. github.com/arkan/cockroach/gossip
  80. github.com/arkan/cockroach/gossip/simulation
  81. github.com/arkan/cockroach/kv
  82. github.com/arkan/cockroach/rpc
  83. github.com/arkan/cockroach/server
  84. github.com/arkan/cockroach/server/status
  85. github.com/arkan/cockroach/sql
  86. github.com/arkan/cockroach/sql/pgwire
  87. github.com/arkan/cockroach/storage
  88. github.com/arkan/cockroach/storage/simulation
  89. github.com/arkan/cockroach/testutils/localtestcluster
  90. github.com/asubiotto/cockroach/gossip
  91. github.com/asubiotto/cockroach/kv
  92. github.com/asubiotto/cockroach/rpc
  93. github.com/asubiotto/cockroach/server
  94. github.com/asubiotto/cockroach/sql
  95. github.com/asubiotto/cockroach/storage
  96. github.com/bdarnell/cockroach/gossip
  97. github.com/bdarnell/cockroach/gossip/simulation
  98. github.com/bdarnell/cockroach/kv
  99. github.com/bdarnell/cockroach/rpc
  100. github.com/bdarnell/cockroach/server
  101. github.com/bdarnell/cockroach/server/status
  102. github.com/bdarnell/cockroach/sql
  103. github.com/bdarnell/cockroach/sql/pgwire
  104. github.com/bdarnell/cockroach/storage
  105. github.com/bdarnell/cockroach/storage/simulation
  106. github.com/bdarnell/cockroach/testutils/localtestcluster
  107. github.com/bg451/cockroach/kv
  108. github.com/bg451/cockroach/rpc
  109. github.com/bg451/cockroach/server
  110. github.com/bg451/cockroach/server/status
  111. github.com/bg451/cockroach/sql
  112. github.com/bg451/cockroach/sql/pgwire
  113. github.com/bg451/cockroach/storage
  114. github.com/chzyer-dev/cockroach/kv
  115. github.com/chzyer-dev/cockroach/rpc
  116. github.com/chzyer-dev/cockroach/server
  117. github.com/chzyer-dev/cockroach/server/status
  118. github.com/chzyer-dev/cockroach/sql
  119. github.com/chzyer-dev/cockroach/sql/pgwire
  120. github.com/chzyer-dev/cockroach/storage
  121. github.com/cockroachdb/cockroach/gossip
  122. github.com/cockroachdb/cockroach/gossip/simulation
  123. github.com/cockroachdb/cockroach/kv
  124. github.com/cockroachdb/cockroach/rpc
  125. github.com/cockroachdb/cockroach/server
  126. github.com/cockroachdb/cockroach/server/status
  127. github.com/cockroachdb/cockroach/sql
  128. github.com/cockroachdb/cockroach/sql/pgwire
  129. github.com/cockroachdb/cockroach/storage
  130. github.com/cockroachdb/cockroach/storage/simulation
  131. github.com/cockroachdb/cockroach/testutils/localtestcluster
  132. github.com/codepope/cockroach/kv
  133. github.com/codepope/cockroach/rpc
  134. github.com/codepope/cockroach/server
  135. github.com/codepope/cockroach/server/status
  136. github.com/codepope/cockroach/sql
  137. github.com/codepope/cockroach/sql/pgwire
  138. github.com/codepope/cockroach/storage
  139. github.com/d4l3k/cockroach/gossip
  140. github.com/d4l3k/cockroach/kv
  141. github.com/d4l3k/cockroach/rpc
  142. github.com/d4l3k/cockroach/server
  143. github.com/d4l3k/cockroach/sql
  144. github.com/d4l3k/cockroach/storage
  145. github.com/danielhan/cockroach/kv
  146. github.com/danielhan/cockroach/rpc
  147. github.com/danielhan/cockroach/server
  148. github.com/danielhan/cockroach/server/status
  149. github.com/danielhan/cockroach/sql
  150. github.com/danielhan/cockroach/sql/pgwire
  151. github.com/danielhan/cockroach/storage
  152. github.com/dlsniper/cockroach/gossip
  153. github.com/dlsniper/cockroach/gossip/simulation
  154. github.com/dlsniper/cockroach/kv
  155. github.com/dlsniper/cockroach/rpc
  156. github.com/dlsniper/cockroach/server
  157. github.com/dlsniper/cockroach/server/status
  158. github.com/dlsniper/cockroach/sql
  159. github.com/dlsniper/cockroach/sql/pgwire
  160. github.com/dlsniper/cockroach/storage
  161. github.com/dlsniper/cockroach/storage/simulation
  162. github.com/dlsniper/cockroach/testutils/localtestcluster
  163. github.com/dt/cockroach/server
  164. github.com/dt/cockroach/server/status
  165. github.com/dt/cockroach/sql
  166. github.com/eddyzhou/cockroach/server
  167. github.com/eddyzhou/cockroach/sql
  168. github.com/guanqun/cockroach/server
  169. github.com/guanqun/cockroach/server/status
  170. github.com/guanqun/cockroach/sql
  171. github.com/guanqun/cockroach/sql/pgwire
  172. github.com/kardianos/cockroach/server/status
  173. github.com/kardianos/cockroach/sql
  174. github.com/kardianos/cockroach/sql/pgwire
  175. github.com/kardianos/cockroach/storage
  176. github.com/kardianos/cockroach/storage/simulation
  177. github.com/kardianos/cockroach/testutils/localtestcluster
  178. github.com/kimh/cockroach/server
  179. github.com/kimh/cockroach/server/status
  180. github.com/kimh/cockroach/sql
  181. github.com/kokizzu/cockroach/kv
  182. github.com/kokizzu/cockroach/server
  183. github.com/kokizzu/cockroach/server/status
  184. github.com/kokizzu/cockroach/sql
  185. github.com/kokizzu/cockroach/sql/pgwire
  186. github.com/kokizzu/cockroach/storage
  187. github.com/l2x/cockroach/server
  188. github.com/l2x/cockroach/server/status
  189. github.com/l2x/cockroach/sql
  190. github.com/lparis/cockroach/kv
  191. github.com/lparis/cockroach/rpc
  192. github.com/lparis/cockroach/server
  193. github.com/lparis/cockroach/server/status
  194. github.com/lparis/cockroach/sql
  195. github.com/lparis/cockroach/sql/pgwire
  196. github.com/lparis/cockroach/storage
  197. github.com/marcuswestin/cockroach/server
  198. github.com/marcuswestin/cockroach/server/status
  199. github.com/marcuswestin/cockroach/sql
  200. github.com/maximecaron/cockroach/server
  201. github.com/maximecaron/cockroach/server/status
  202. github.com/maximecaron/cockroach/sql
  203. github.com/mjibson/cockroach/kv
  204. github.com/mjibson/cockroach/rpc
  205. github.com/mjibson/cockroach/server
  206. github.com/mjibson/cockroach/sql
  207. github.com/mjibson/cockroach/storage
  208. github.com/nak3/cockroach/kv
  209. github.com/nak3/cockroach/rpc
  210. github.com/nak3/cockroach/server
  211. github.com/nak3/cockroach/sql
  212. github.com/nak3/cockroach/storage
  213. github.com/objectundefined/cockroach/kv
  214. github.com/objectundefined/cockroach/rpc
  215. github.com/objectundefined/cockroach/server
  216. github.com/objectundefined/cockroach/server/status
  217. github.com/objectundefined/cockroach/sql
  218. github.com/objectundefined/cockroach/sql/pgwire
  219. github.com/objectundefined/cockroach/storage
  220. github.com/panyingyun/cockroach/gossip
  221. github.com/panyingyun/cockroach/gossip/simulation
  222. github.com/panyingyun/cockroach/kv
  223. github.com/panyingyun/cockroach/rpc
  224. github.com/panyingyun/cockroach/server
  225. github.com/panyingyun/cockroach/server/status
  226. github.com/panyingyun/cockroach/sql
  227. github.com/panyingyun/cockroach/sql/pgwire
  228. github.com/panyingyun/cockroach/storage
  229. github.com/panyingyun/cockroach/storage/simulation
  230. github.com/panyingyun/cockroach/testutils/localtestcluster
  231. github.com/paperstreet/cockroach/kv
  232. github.com/paperstreet/cockroach/rpc
  233. github.com/paperstreet/cockroach/server
  234. github.com/paperstreet/cockroach/sql
  235. github.com/paperstreet/cockroach/storage
  236. github.com/petermattis/cockroach/kv
  237. github.com/petermattis/cockroach/rpc
  238. github.com/petermattis/cockroach/server
  239. github.com/petermattis/cockroach/sql
  240. github.com/petermattis/cockroach/storage
  241. github.com/phobos182/cockroach/kv
  242. github.com/phobos182/cockroach/rpc
  243. github.com/phobos182/cockroach/server
  244. github.com/phobos182/cockroach/server/status
  245. github.com/phobos182/cockroach/sql
  246. github.com/phobos182/cockroach/sql/pgwire
  247. github.com/phobos182/cockroach/storage
  248. github.com/phynalle/cockroach/kv
  249. github.com/phynalle/cockroach/rpc
  250. github.com/phynalle/cockroach/server
  251. github.com/phynalle/cockroach/server/status
  252. github.com/phynalle/cockroach/sql
  253. github.com/phynalle/cockroach/sql/pgwire
  254. github.com/phynalle/cockroach/storage
  255. github.com/rushiagr/cockroach/kv
  256. github.com/rushiagr/cockroach/rpc
  257. github.com/rushiagr/cockroach/server
  258. github.com/rushiagr/cockroach/server/status
  259. github.com/rushiagr/cockroach/sql
  260. github.com/rushiagr/cockroach/sql/pgwire
  261. github.com/rushiagr/cockroach/storage
  262. github.com/sacheendra/cockroach/server
  263. github.com/sacheendra/cockroach/server/status
  264. github.com/sacheendra/cockroach/sql
  265. github.com/seiflotfy/cockroach/kv
  266. github.com/seiflotfy/cockroach/rpc
  267. github.com/seiflotfy/cockroach/server
  268. github.com/seiflotfy/cockroach/server/status
  269. github.com/seiflotfy/cockroach/sql
  270. github.com/seiflotfy/cockroach/sql/pgwire
  271. github.com/seiflotfy/cockroach/storage
  272. github.com/soniabhishek/cockroach/server
  273. github.com/soniabhishek/cockroach/sql
  274. github.com/spencerkimball/cockroach/kv
  275. github.com/spencerkimball/cockroach/rpc
  276. github.com/spencerkimball/cockroach/server
  277. github.com/spencerkimball/cockroach/sql
  278. github.com/spencerkimball/cockroach/storage
  279. github.com/sunya123/cockroach/gossip
  280. github.com/sunya123/cockroach/gossip/simulation
  281. github.com/sunya123/cockroach/kv
  282. github.com/sunya123/cockroach/rpc
  283. github.com/sunya123/cockroach/server
  284. github.com/sunya123/cockroach/server/status
  285. github.com/sunya123/cockroach/sql
  286. github.com/sunya123/cockroach/sql/pgwire
  287. github.com/sunya123/cockroach/storage
  288. github.com/sunya123/cockroach/storage/simulation
  289. github.com/sunya123/cockroach/testutils/localtestcluster
  290. github.com/tamird/cockroach/gossip
  291. github.com/tamird/cockroach/kv
  292. github.com/tamird/cockroach/rpc
  293. github.com/tamird/cockroach/server
  294. github.com/tamird/cockroach/sql
  295. github.com/tamird/cockroach/storage
  296. github.com/tescherm/cockroach/kv
  297. github.com/tescherm/cockroach/rpc
  298. github.com/tescherm/cockroach/server
  299. github.com/tescherm/cockroach/sql
  300. github.com/tescherm/cockroach/storage
  301. github.com/the872/cockroach/kv
  302. github.com/the872/cockroach/rpc
  303. github.com/the872/cockroach/server
  304. github.com/the872/cockroach/server/status
  305. github.com/the872/cockroach/sql
  306. github.com/the872/cockroach/sql/pgwire
  307. github.com/the872/cockroach/storage
  308. github.com/tschottdorf/cockroach/kv
  309. github.com/tschottdorf/cockroach/rpc
  310. github.com/tschottdorf/cockroach/server
  311. github.com/tschottdorf/cockroach/sql
  312. github.com/tschottdorf/cockroach/storage
  313. github.com/upton/cockroach/kv
  314. github.com/upton/cockroach/server
  315. github.com/upton/cockroach/server/status
  316. github.com/upton/cockroach/sql
  317. github.com/upton/cockroach/sql/pgwire
  318. github.com/vnadgir-ef/cockroach/server
  319. github.com/vnadgir-ef/cockroach/server/status
  320. github.com/vnadgir-ef/cockroach/sql
  321. github.com/yydzero/cockroach/kv
  322. github.com/yydzero/cockroach/rpc
  323. github.com/yydzero/cockroach/server
  324. github.com/yydzero/cockroach/server/status
  325. github.com/yydzero/cockroach/sql
  326. github.com/yydzero/cockroach/sql/pgwire
  327. github.com/yydzero/cockroach/storage

Imported only in test by 1 package(s)

  1. github.com/upton/cockroach/storage

Imports 10 package(s)

  1. github.com/codahale/hdrhistogram
  2. github.com/cockroachdb/cockroach/util/timeutil
  3. github.com/prometheus/common/expfmt
  4. github.com/cockroachdb/cockroach/util/log
  5. github.com/gogo/protobuf/proto
  6. golang.org/x/net/context
  7. github.com/rcrowley/go-metrics
  8. github.com/prometheus/client_model/go
  9. github.com/cockroachdb/cockroach/util/syncutil
  10. github.com/VividCortex/ewma

Test imports 1 package(s)

  1. github.com/kr/pretty