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 322 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/kv
  81. github.com/arkan/cockroach/rpc
  82. github.com/arkan/cockroach/server
  83. github.com/arkan/cockroach/sql
  84. github.com/arkan/cockroach/storage
  85. github.com/asubiotto/cockroach/gossip
  86. github.com/asubiotto/cockroach/kv
  87. github.com/asubiotto/cockroach/rpc
  88. github.com/asubiotto/cockroach/server
  89. github.com/asubiotto/cockroach/sql
  90. github.com/asubiotto/cockroach/storage
  91. github.com/bdarnell/cockroach/gossip
  92. github.com/bdarnell/cockroach/gossip/simulation
  93. github.com/bdarnell/cockroach/kv
  94. github.com/bdarnell/cockroach/rpc
  95. github.com/bdarnell/cockroach/server
  96. github.com/bdarnell/cockroach/server/status
  97. github.com/bdarnell/cockroach/sql
  98. github.com/bdarnell/cockroach/sql/pgwire
  99. github.com/bdarnell/cockroach/storage
  100. github.com/bdarnell/cockroach/storage/simulation
  101. github.com/bdarnell/cockroach/testutils/localtestcluster
  102. github.com/bg451/cockroach/kv
  103. github.com/bg451/cockroach/rpc
  104. github.com/bg451/cockroach/server
  105. github.com/bg451/cockroach/server/status
  106. github.com/bg451/cockroach/sql
  107. github.com/bg451/cockroach/sql/pgwire
  108. github.com/bg451/cockroach/storage
  109. github.com/chzyer-dev/cockroach/kv
  110. github.com/chzyer-dev/cockroach/rpc
  111. github.com/chzyer-dev/cockroach/server
  112. github.com/chzyer-dev/cockroach/server/status
  113. github.com/chzyer-dev/cockroach/sql
  114. github.com/chzyer-dev/cockroach/sql/pgwire
  115. github.com/chzyer-dev/cockroach/storage
  116. github.com/cockroachdb/cockroach/gossip
  117. github.com/cockroachdb/cockroach/gossip/simulation
  118. github.com/cockroachdb/cockroach/kv
  119. github.com/cockroachdb/cockroach/rpc
  120. github.com/cockroachdb/cockroach/server
  121. github.com/cockroachdb/cockroach/server/status
  122. github.com/cockroachdb/cockroach/sql
  123. github.com/cockroachdb/cockroach/sql/pgwire
  124. github.com/cockroachdb/cockroach/storage
  125. github.com/cockroachdb/cockroach/storage/simulation
  126. github.com/cockroachdb/cockroach/testutils/localtestcluster
  127. github.com/codepope/cockroach/kv
  128. github.com/codepope/cockroach/rpc
  129. github.com/codepope/cockroach/server
  130. github.com/codepope/cockroach/server/status
  131. github.com/codepope/cockroach/sql
  132. github.com/codepope/cockroach/sql/pgwire
  133. github.com/codepope/cockroach/storage
  134. github.com/d4l3k/cockroach/gossip
  135. github.com/d4l3k/cockroach/kv
  136. github.com/d4l3k/cockroach/rpc
  137. github.com/d4l3k/cockroach/server
  138. github.com/d4l3k/cockroach/sql
  139. github.com/d4l3k/cockroach/storage
  140. github.com/danielhan/cockroach/kv
  141. github.com/danielhan/cockroach/rpc
  142. github.com/danielhan/cockroach/server
  143. github.com/danielhan/cockroach/server/status
  144. github.com/danielhan/cockroach/sql
  145. github.com/danielhan/cockroach/sql/pgwire
  146. github.com/danielhan/cockroach/storage
  147. github.com/dlsniper/cockroach/gossip
  148. github.com/dlsniper/cockroach/gossip/simulation
  149. github.com/dlsniper/cockroach/kv
  150. github.com/dlsniper/cockroach/rpc
  151. github.com/dlsniper/cockroach/server
  152. github.com/dlsniper/cockroach/server/status
  153. github.com/dlsniper/cockroach/sql
  154. github.com/dlsniper/cockroach/sql/pgwire
  155. github.com/dlsniper/cockroach/storage
  156. github.com/dlsniper/cockroach/storage/simulation
  157. github.com/dlsniper/cockroach/testutils/localtestcluster
  158. github.com/dt/cockroach/server
  159. github.com/dt/cockroach/server/status
  160. github.com/dt/cockroach/sql
  161. github.com/eddyzhou/cockroach/server
  162. github.com/eddyzhou/cockroach/sql
  163. github.com/guanqun/cockroach/server
  164. github.com/guanqun/cockroach/server/status
  165. github.com/guanqun/cockroach/sql
  166. github.com/guanqun/cockroach/sql/pgwire
  167. github.com/kardianos/cockroach/server/status
  168. github.com/kardianos/cockroach/sql
  169. github.com/kardianos/cockroach/sql/pgwire
  170. github.com/kardianos/cockroach/storage
  171. github.com/kardianos/cockroach/storage/simulation
  172. github.com/kardianos/cockroach/testutils/localtestcluster
  173. github.com/kimh/cockroach/server
  174. github.com/kimh/cockroach/server/status
  175. github.com/kimh/cockroach/sql
  176. github.com/kokizzu/cockroach/kv
  177. github.com/kokizzu/cockroach/server
  178. github.com/kokizzu/cockroach/server/status
  179. github.com/kokizzu/cockroach/sql
  180. github.com/kokizzu/cockroach/sql/pgwire
  181. github.com/kokizzu/cockroach/storage
  182. github.com/l2x/cockroach/server
  183. github.com/l2x/cockroach/server/status
  184. github.com/l2x/cockroach/sql
  185. github.com/lparis/cockroach/kv
  186. github.com/lparis/cockroach/rpc
  187. github.com/lparis/cockroach/server
  188. github.com/lparis/cockroach/server/status
  189. github.com/lparis/cockroach/sql
  190. github.com/lparis/cockroach/sql/pgwire
  191. github.com/lparis/cockroach/storage
  192. github.com/marcuswestin/cockroach/server
  193. github.com/marcuswestin/cockroach/server/status
  194. github.com/marcuswestin/cockroach/sql
  195. github.com/maximecaron/cockroach/server
  196. github.com/maximecaron/cockroach/server/status
  197. github.com/maximecaron/cockroach/sql
  198. github.com/mjibson/cockroach/kv
  199. github.com/mjibson/cockroach/rpc
  200. github.com/mjibson/cockroach/server
  201. github.com/mjibson/cockroach/sql
  202. github.com/mjibson/cockroach/storage
  203. github.com/nak3/cockroach/kv
  204. github.com/nak3/cockroach/rpc
  205. github.com/nak3/cockroach/server
  206. github.com/nak3/cockroach/sql
  207. github.com/nak3/cockroach/storage
  208. github.com/objectundefined/cockroach/kv
  209. github.com/objectundefined/cockroach/rpc
  210. github.com/objectundefined/cockroach/server
  211. github.com/objectundefined/cockroach/server/status
  212. github.com/objectundefined/cockroach/sql
  213. github.com/objectundefined/cockroach/sql/pgwire
  214. github.com/objectundefined/cockroach/storage
  215. github.com/panyingyun/cockroach/gossip
  216. github.com/panyingyun/cockroach/gossip/simulation
  217. github.com/panyingyun/cockroach/kv
  218. github.com/panyingyun/cockroach/rpc
  219. github.com/panyingyun/cockroach/server
  220. github.com/panyingyun/cockroach/server/status
  221. github.com/panyingyun/cockroach/sql
  222. github.com/panyingyun/cockroach/sql/pgwire
  223. github.com/panyingyun/cockroach/storage
  224. github.com/panyingyun/cockroach/storage/simulation
  225. github.com/panyingyun/cockroach/testutils/localtestcluster
  226. github.com/paperstreet/cockroach/kv
  227. github.com/paperstreet/cockroach/rpc
  228. github.com/paperstreet/cockroach/server
  229. github.com/paperstreet/cockroach/sql
  230. github.com/paperstreet/cockroach/storage
  231. github.com/petermattis/cockroach/kv
  232. github.com/petermattis/cockroach/rpc
  233. github.com/petermattis/cockroach/server
  234. github.com/petermattis/cockroach/sql
  235. github.com/petermattis/cockroach/storage
  236. github.com/phobos182/cockroach/kv
  237. github.com/phobos182/cockroach/rpc
  238. github.com/phobos182/cockroach/server
  239. github.com/phobos182/cockroach/server/status
  240. github.com/phobos182/cockroach/sql
  241. github.com/phobos182/cockroach/sql/pgwire
  242. github.com/phobos182/cockroach/storage
  243. github.com/phynalle/cockroach/kv
  244. github.com/phynalle/cockroach/rpc
  245. github.com/phynalle/cockroach/server
  246. github.com/phynalle/cockroach/server/status
  247. github.com/phynalle/cockroach/sql
  248. github.com/phynalle/cockroach/sql/pgwire
  249. github.com/phynalle/cockroach/storage
  250. github.com/rushiagr/cockroach/kv
  251. github.com/rushiagr/cockroach/rpc
  252. github.com/rushiagr/cockroach/server
  253. github.com/rushiagr/cockroach/server/status
  254. github.com/rushiagr/cockroach/sql
  255. github.com/rushiagr/cockroach/sql/pgwire
  256. github.com/rushiagr/cockroach/storage
  257. github.com/sacheendra/cockroach/server
  258. github.com/sacheendra/cockroach/server/status
  259. github.com/sacheendra/cockroach/sql
  260. github.com/seiflotfy/cockroach/kv
  261. github.com/seiflotfy/cockroach/rpc
  262. github.com/seiflotfy/cockroach/server
  263. github.com/seiflotfy/cockroach/server/status
  264. github.com/seiflotfy/cockroach/sql
  265. github.com/seiflotfy/cockroach/sql/pgwire
  266. github.com/seiflotfy/cockroach/storage
  267. github.com/soniabhishek/cockroach/server
  268. github.com/soniabhishek/cockroach/sql
  269. github.com/spencerkimball/cockroach/kv
  270. github.com/spencerkimball/cockroach/rpc
  271. github.com/spencerkimball/cockroach/server
  272. github.com/spencerkimball/cockroach/sql
  273. github.com/spencerkimball/cockroach/storage
  274. github.com/sunya123/cockroach/gossip
  275. github.com/sunya123/cockroach/gossip/simulation
  276. github.com/sunya123/cockroach/kv
  277. github.com/sunya123/cockroach/rpc
  278. github.com/sunya123/cockroach/server
  279. github.com/sunya123/cockroach/server/status
  280. github.com/sunya123/cockroach/sql
  281. github.com/sunya123/cockroach/sql/pgwire
  282. github.com/sunya123/cockroach/storage
  283. github.com/sunya123/cockroach/storage/simulation
  284. github.com/sunya123/cockroach/testutils/localtestcluster
  285. github.com/tamird/cockroach/gossip
  286. github.com/tamird/cockroach/kv
  287. github.com/tamird/cockroach/rpc
  288. github.com/tamird/cockroach/server
  289. github.com/tamird/cockroach/sql
  290. github.com/tamird/cockroach/storage
  291. github.com/tescherm/cockroach/kv
  292. github.com/tescherm/cockroach/rpc
  293. github.com/tescherm/cockroach/server
  294. github.com/tescherm/cockroach/sql
  295. github.com/tescherm/cockroach/storage
  296. github.com/the872/cockroach/kv
  297. github.com/the872/cockroach/rpc
  298. github.com/the872/cockroach/server
  299. github.com/the872/cockroach/server/status
  300. github.com/the872/cockroach/sql
  301. github.com/the872/cockroach/sql/pgwire
  302. github.com/the872/cockroach/storage
  303. github.com/tschottdorf/cockroach/kv
  304. github.com/tschottdorf/cockroach/rpc
  305. github.com/tschottdorf/cockroach/server
  306. github.com/tschottdorf/cockroach/sql
  307. github.com/tschottdorf/cockroach/storage
  308. github.com/upton/cockroach/kv
  309. github.com/upton/cockroach/server
  310. github.com/upton/cockroach/server/status
  311. github.com/upton/cockroach/sql
  312. github.com/upton/cockroach/sql/pgwire
  313. github.com/vnadgir-ef/cockroach/server
  314. github.com/vnadgir-ef/cockroach/server/status
  315. github.com/vnadgir-ef/cockroach/sql
  316. github.com/yydzero/cockroach/kv
  317. github.com/yydzero/cockroach/rpc
  318. github.com/yydzero/cockroach/server
  319. github.com/yydzero/cockroach/server/status
  320. github.com/yydzero/cockroach/sql
  321. github.com/yydzero/cockroach/sql/pgwire
  322. 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