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