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 261 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/sql
  32. github.com/YuleiXiao/cockroach/storage
  33. github.com/abhi11/cockroach/server
  34. github.com/abhi11/cockroach/sql
  35. github.com/abhinavdahiya/cockroach/kv
  36. github.com/abhinavdahiya/cockroach/rpc
  37. github.com/abhinavdahiya/cockroach/server
  38. github.com/abhinavdahiya/cockroach/server/status
  39. github.com/abhinavdahiya/cockroach/sql
  40. github.com/abhinavdahiya/cockroach/sql/pgwire
  41. github.com/abhinavdahiya/cockroach/storage
  42. github.com/andreweduffy/cockroach/gossip
  43. github.com/andreweduffy/cockroach/gossip/simulation
  44. github.com/andreweduffy/cockroach/kv
  45. github.com/andreweduffy/cockroach/rpc
  46. github.com/andreweduffy/cockroach/server
  47. github.com/andreweduffy/cockroach/server/status
  48. github.com/andreweduffy/cockroach/sql
  49. github.com/andreweduffy/cockroach/sql/pgwire
  50. github.com/andreweduffy/cockroach/storage
  51. github.com/andreweduffy/cockroach/storage/simulation
  52. github.com/andreweduffy/cockroach/testutils/localtestcluster
  53. github.com/asubiotto/cockroach/gossip
  54. github.com/asubiotto/cockroach/kv
  55. github.com/asubiotto/cockroach/rpc
  56. github.com/asubiotto/cockroach/server
  57. github.com/asubiotto/cockroach/sql
  58. github.com/asubiotto/cockroach/storage
  59. github.com/bdarnell/cockroach/gossip
  60. github.com/bdarnell/cockroach/gossip/simulation
  61. github.com/bdarnell/cockroach/kv
  62. github.com/bdarnell/cockroach/rpc
  63. github.com/bdarnell/cockroach/server
  64. github.com/bdarnell/cockroach/server/status
  65. github.com/bdarnell/cockroach/sql
  66. github.com/bdarnell/cockroach/sql/pgwire
  67. github.com/bdarnell/cockroach/storage
  68. github.com/bdarnell/cockroach/storage/simulation
  69. github.com/bdarnell/cockroach/testutils/localtestcluster
  70. github.com/bg451/cockroach/kv
  71. github.com/bg451/cockroach/rpc
  72. github.com/bg451/cockroach/server
  73. github.com/bg451/cockroach/sql
  74. github.com/bg451/cockroach/storage
  75. github.com/chzyer-dev/cockroach/kv
  76. github.com/chzyer-dev/cockroach/rpc
  77. github.com/chzyer-dev/cockroach/server
  78. github.com/chzyer-dev/cockroach/sql
  79. github.com/chzyer-dev/cockroach/storage
  80. github.com/cockroachdb/cockroach/gossip
  81. github.com/cockroachdb/cockroach/gossip/simulation
  82. github.com/cockroachdb/cockroach/kv
  83. github.com/cockroachdb/cockroach/rpc
  84. github.com/cockroachdb/cockroach/server
  85. github.com/cockroachdb/cockroach/server/status
  86. github.com/cockroachdb/cockroach/sql
  87. github.com/cockroachdb/cockroach/sql/pgwire
  88. github.com/cockroachdb/cockroach/storage
  89. github.com/cockroachdb/cockroach/storage/simulation
  90. github.com/cockroachdb/cockroach/testutils/localtestcluster
  91. github.com/codepope/cockroach/kv
  92. github.com/codepope/cockroach/rpc
  93. github.com/codepope/cockroach/server
  94. github.com/codepope/cockroach/server/status
  95. github.com/codepope/cockroach/sql
  96. github.com/codepope/cockroach/sql/pgwire
  97. github.com/codepope/cockroach/storage
  98. github.com/d4l3k/cockroach/gossip
  99. github.com/d4l3k/cockroach/kv
  100. github.com/d4l3k/cockroach/rpc
  101. github.com/d4l3k/cockroach/server
  102. github.com/d4l3k/cockroach/sql
  103. github.com/d4l3k/cockroach/storage
  104. github.com/danielhan/cockroach/kv
  105. github.com/danielhan/cockroach/rpc
  106. github.com/danielhan/cockroach/server
  107. github.com/danielhan/cockroach/server/status
  108. github.com/danielhan/cockroach/sql
  109. github.com/danielhan/cockroach/sql/pgwire
  110. github.com/danielhan/cockroach/storage
  111. github.com/dlsniper/cockroach/gossip
  112. github.com/dlsniper/cockroach/gossip/simulation
  113. github.com/dlsniper/cockroach/kv
  114. github.com/dlsniper/cockroach/rpc
  115. github.com/dlsniper/cockroach/server
  116. github.com/dlsniper/cockroach/server/status
  117. github.com/dlsniper/cockroach/sql
  118. github.com/dlsniper/cockroach/sql/pgwire
  119. github.com/dlsniper/cockroach/storage
  120. github.com/dlsniper/cockroach/storage/simulation
  121. github.com/dlsniper/cockroach/testutils/localtestcluster
  122. github.com/dt/cockroach/server
  123. github.com/dt/cockroach/sql
  124. github.com/eddyzhou/cockroach/server
  125. github.com/eddyzhou/cockroach/sql
  126. github.com/guanqun/cockroach/server
  127. github.com/guanqun/cockroach/sql
  128. github.com/kardianos/cockroach/server/status
  129. github.com/kardianos/cockroach/sql
  130. github.com/kardianos/cockroach/sql/pgwire
  131. github.com/kardianos/cockroach/storage
  132. github.com/kardianos/cockroach/storage/simulation
  133. github.com/kardianos/cockroach/testutils/localtestcluster
  134. github.com/kimh/cockroach/server
  135. github.com/kimh/cockroach/sql
  136. github.com/kokizzu/cockroach/kv
  137. github.com/kokizzu/cockroach/server
  138. github.com/kokizzu/cockroach/server/status
  139. github.com/kokizzu/cockroach/sql
  140. github.com/kokizzu/cockroach/sql/pgwire
  141. github.com/kokizzu/cockroach/storage
  142. github.com/l2x/cockroach/server
  143. github.com/l2x/cockroach/sql
  144. github.com/lparis/cockroach/kv
  145. github.com/lparis/cockroach/rpc
  146. github.com/lparis/cockroach/server
  147. github.com/lparis/cockroach/sql
  148. github.com/lparis/cockroach/storage
  149. github.com/marcuswestin/cockroach/server
  150. github.com/marcuswestin/cockroach/sql
  151. github.com/maximecaron/cockroach/server
  152. github.com/maximecaron/cockroach/sql
  153. github.com/mjibson/cockroach/kv
  154. github.com/mjibson/cockroach/rpc
  155. github.com/mjibson/cockroach/server
  156. github.com/mjibson/cockroach/sql
  157. github.com/mjibson/cockroach/storage
  158. github.com/nak3/cockroach/kv
  159. github.com/nak3/cockroach/rpc
  160. github.com/nak3/cockroach/server
  161. github.com/nak3/cockroach/sql
  162. github.com/nak3/cockroach/storage
  163. github.com/objectundefined/cockroach/kv
  164. github.com/objectundefined/cockroach/rpc
  165. github.com/objectundefined/cockroach/server
  166. github.com/objectundefined/cockroach/server/status
  167. github.com/objectundefined/cockroach/sql
  168. github.com/objectundefined/cockroach/sql/pgwire
  169. github.com/objectundefined/cockroach/storage
  170. github.com/panyingyun/cockroach/gossip
  171. github.com/panyingyun/cockroach/gossip/simulation
  172. github.com/panyingyun/cockroach/kv
  173. github.com/panyingyun/cockroach/rpc
  174. github.com/panyingyun/cockroach/server
  175. github.com/panyingyun/cockroach/server/status
  176. github.com/panyingyun/cockroach/sql
  177. github.com/panyingyun/cockroach/sql/pgwire
  178. github.com/panyingyun/cockroach/storage
  179. github.com/panyingyun/cockroach/storage/simulation
  180. github.com/panyingyun/cockroach/testutils/localtestcluster
  181. github.com/paperstreet/cockroach/kv
  182. github.com/paperstreet/cockroach/rpc
  183. github.com/paperstreet/cockroach/server
  184. github.com/paperstreet/cockroach/sql
  185. github.com/paperstreet/cockroach/storage
  186. github.com/petermattis/cockroach/kv
  187. github.com/petermattis/cockroach/rpc
  188. github.com/petermattis/cockroach/server
  189. github.com/petermattis/cockroach/sql
  190. github.com/petermattis/cockroach/storage
  191. github.com/phobos182/cockroach/kv
  192. github.com/phobos182/cockroach/rpc
  193. github.com/phobos182/cockroach/server
  194. github.com/phobos182/cockroach/server/status
  195. github.com/phobos182/cockroach/sql
  196. github.com/phobos182/cockroach/sql/pgwire
  197. github.com/phobos182/cockroach/storage
  198. github.com/phynalle/cockroach/kv
  199. github.com/phynalle/cockroach/rpc
  200. github.com/phynalle/cockroach/server
  201. github.com/phynalle/cockroach/sql
  202. github.com/phynalle/cockroach/storage
  203. github.com/rushiagr/cockroach/kv
  204. github.com/rushiagr/cockroach/rpc
  205. github.com/rushiagr/cockroach/server
  206. github.com/rushiagr/cockroach/server/status
  207. github.com/rushiagr/cockroach/sql
  208. github.com/rushiagr/cockroach/sql/pgwire
  209. github.com/rushiagr/cockroach/storage
  210. github.com/sacheendra/cockroach/server
  211. github.com/sacheendra/cockroach/sql
  212. github.com/seiflotfy/cockroach/kv
  213. github.com/seiflotfy/cockroach/rpc
  214. github.com/seiflotfy/cockroach/server
  215. github.com/seiflotfy/cockroach/server/status
  216. github.com/seiflotfy/cockroach/sql
  217. github.com/seiflotfy/cockroach/sql/pgwire
  218. github.com/seiflotfy/cockroach/storage
  219. github.com/soniabhishek/cockroach/server
  220. github.com/soniabhishek/cockroach/sql
  221. github.com/spencerkimball/cockroach/kv
  222. github.com/spencerkimball/cockroach/rpc
  223. github.com/spencerkimball/cockroach/server
  224. github.com/spencerkimball/cockroach/sql
  225. github.com/spencerkimball/cockroach/storage
  226. github.com/sunya123/cockroach/gossip
  227. github.com/sunya123/cockroach/kv
  228. github.com/sunya123/cockroach/rpc
  229. github.com/sunya123/cockroach/server
  230. github.com/sunya123/cockroach/sql
  231. github.com/sunya123/cockroach/storage
  232. github.com/tamird/cockroach/gossip
  233. github.com/tamird/cockroach/kv
  234. github.com/tamird/cockroach/rpc
  235. github.com/tamird/cockroach/server
  236. github.com/tamird/cockroach/sql
  237. github.com/tamird/cockroach/storage
  238. github.com/the872/cockroach/kv
  239. github.com/the872/cockroach/rpc
  240. github.com/the872/cockroach/server
  241. github.com/the872/cockroach/server/status
  242. github.com/the872/cockroach/sql
  243. github.com/the872/cockroach/sql/pgwire
  244. github.com/the872/cockroach/storage
  245. github.com/tschottdorf/cockroach/kv
  246. github.com/tschottdorf/cockroach/rpc
  247. github.com/tschottdorf/cockroach/server
  248. github.com/tschottdorf/cockroach/sql
  249. github.com/tschottdorf/cockroach/storage
  250. github.com/upton/cockroach/kv
  251. github.com/upton/cockroach/server
  252. github.com/upton/cockroach/sql
  253. github.com/vnadgir-ef/cockroach/server
  254. github.com/vnadgir-ef/cockroach/sql
  255. github.com/yydzero/cockroach/kv
  256. github.com/yydzero/cockroach/rpc
  257. github.com/yydzero/cockroach/server
  258. github.com/yydzero/cockroach/server/status
  259. github.com/yydzero/cockroach/sql
  260. github.com/yydzero/cockroach/sql/pgwire
  261. 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