From 7905f1b6b374dbfaec7f118c5878f10c54a616eb Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 4 Apr 2014 14:55:23 -0700 Subject: [PATCH 1/2] website: Mention that telemetry can be streamed --- website/source/docs/agent/telemetry.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/source/docs/agent/telemetry.html.markdown b/website/source/docs/agent/telemetry.html.markdown index fff8b6c250..b54427ccca 100644 --- a/website/source/docs/agent/telemetry.html.markdown +++ b/website/source/docs/agent/telemetry.html.markdown @@ -18,6 +18,10 @@ information to the stderr of the agent. In general, the telemetry information is used for debugging or otherwise getting a better view into what Consul is doing. +Additionally, if the `-statsite` [option](/docs/agent/options.html) is provided, +then the telemetry information will be streamed to a [statsite](github.com/armon/statsite) +server where it can be aggregate and flushed to Graphite or any other metrics store. + Below is an example output: ``` From ebf98fcea07f979192f2a0ed0f8e6bc491e3e753 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 4 Apr 2014 14:55:44 -0700 Subject: [PATCH 2/2] consul: Export some telemetry on service queries --- consul/catalog_endpoint.go | 14 +++++++++++++- consul/health_endpoint.go | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/consul/catalog_endpoint.go b/consul/catalog_endpoint.go index effd55b42c..e288229937 100644 --- a/consul/catalog_endpoint.go +++ b/consul/catalog_endpoint.go @@ -134,7 +134,7 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru // Get the nodes state := c.srv.fsm.State() - return c.srv.blockingRPC(&args.BlockingQuery, + err := c.srv.blockingRPC(&args.BlockingQuery, state.QueryTables("ServiceNodes"), func() (uint64, error) { if args.TagFilter { @@ -144,6 +144,18 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru } return reply.Index, nil }) + + // Provide some metrics + if err == nil { + metrics.IncrCounter([]string{"consul", "catalog", "service", "query", args.ServiceName}, 1) + if args.ServiceTag != "" { + metrics.IncrCounter([]string{"consul", "catalog", "service", "query-tag", args.ServiceName, args.ServiceTag}, 1) + } + if len(reply.ServiceNodes) == 0 { + metrics.IncrCounter([]string{"consul", "catalog", "service", "not-found", args.ServiceName}, 1) + } + } + return err } // NodeServices returns all the services registered as part of a node diff --git a/consul/health_endpoint.go b/consul/health_endpoint.go index eb568b96d1..f1428c43f7 100644 --- a/consul/health_endpoint.go +++ b/consul/health_endpoint.go @@ -2,6 +2,7 @@ package consul import ( "fmt" + "github.com/armon/go-metrics" "github.com/hashicorp/consul/consul/structs" ) @@ -80,7 +81,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc // Get the nodes state := h.srv.fsm.State() - return h.srv.blockingRPC(&args.BlockingQuery, + err := h.srv.blockingRPC(&args.BlockingQuery, state.QueryTables("CheckServiceNodes"), func() (uint64, error) { if args.TagFilter { @@ -90,4 +91,16 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc } return reply.Index, nil }) + + // Provide some metrics + if err == nil { + metrics.IncrCounter([]string{"consul", "health", "service", "query", args.ServiceName}, 1) + if args.ServiceTag != "" { + metrics.IncrCounter([]string{"consul", "health", "service", "query-tag", args.ServiceName, args.ServiceTag}, 1) + } + if len(reply.Nodes) == 0 { + metrics.IncrCounter([]string{"consul", "health", "service", "not-found", args.ServiceName}, 1) + } + } + return err }