本文整理匯總了Golang中github.com/emicklei/go-restful.WebService.QueryParameter方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebService.QueryParameter方法的具體用法?Golang WebService.QueryParameter怎麽用?Golang WebService.QueryParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/emicklei/go-restful.WebService
的用法示例。
在下文中一共展示了WebService.QueryParameter方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Register
func (a *Api) Register(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/apis/metrics/v1alpha1").
Doc("Root endpoint of metrics API").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/nodes/").
To(a.nodeMetricsList).
Doc("Get a list of metrics for all available nodes.").
Operation("nodeMetricsList"))
ws.Route(ws.GET("/nodes/{node-name}/").
To(a.nodeMetrics).
Doc("Get a list of all available metrics for the specified node.").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/").
To(a.podMetricsList).
Doc("Get a list of metrics for all available pods in the specified namespace.").
Operation("podMetricsList").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))).
Param(ws.QueryParameter("labelSelector", "A selector to restrict the list of returned objects by their labels. Defaults to everything.").DataType("string"))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/").
To(a.podMetrics).
Doc("Get metrics for the specified pod in the specified namespace.").
Operation("podMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")))
container.Add(ws)
}
示例2: main
func main() {
ws := new(restful.WebService)
ws.Path("/itrain").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
ws.Route(ws.GET("/version").
To(report_version).
Doc("get itrain version number").
Operation("version"))
ws.Route(ws.GET("/report_inverter").
To(report_inverter).
Doc("get inverter report data").
Operation("report_inverter").
Param(ws.QueryParameter("sd", "startdate")))
restful.Add(ws)
config := swagger.Config{
WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible
WebServicesUrl: "/",
ApiPath: "/apidocs.json",
// specifiy where the UI is located
SwaggerPath: "/apidocs/",
SwaggerFilePath: "./swaggerui"}
swagger.RegisterSwaggerService(config, restful.DefaultContainer)
var (
hostname string = "127.0.0.1"
port int = 8080
)
// Listen on hostname:port
fmt.Printf("Listening on %s:%d...\n", hostname, port)
err := http.ListenAndServe(fmt.Sprintf("%s:%d", hostname, port), nil)
if err != nil {
log.Fatal("Error: ", err)
}
}
示例3: addClusterMetricsRoutes
// addClusterMetricsRoutes adds all the standard model routes to a WebService.
// It should already have a base path registered.
func addClusterMetricsRoutes(a clusterMetricsFetcher, ws *restful.WebService) {
// The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/").
To(metrics.InstrumentRouteFunc("availableClusterMetrics", a.availableClusterMetrics)).
Doc("Get a list of all available metrics for the Cluster entity").
Operation("availableClusterMetrics"))
// The /metrics/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("clusterMetrics", a.clusterMetrics)).
Doc("Export an aggregated cluster-level metric").
Operation("clusterMetrics").
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricResult{}))
// The /nodes/{node-name}/metrics endpoint returns a list of all nodes with some metrics.
ws.Route(ws.GET("/nodes/").
To(metrics.InstrumentRouteFunc("nodeList", a.nodeList)).
Doc("Get a list of all nodes that have some current metrics").
Operation("nodeList"))
// The /nodes/{node-name}/metrics endpoint returns a list of all available metrics for a Node entity.
ws.Route(ws.GET("/nodes/{node-name}/metrics/").
To(metrics.InstrumentRouteFunc("availableNodeMetrics", a.availableNodeMetrics)).
Doc("Get a list of all available metrics for a Node entity").
Operation("availableNodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
// The /nodes/{node-name}/metrics/{metric-name} endpoint exposes a metric for a Node entity of the model.
// The {node-name} parameter is the hostname of a specific node.
ws.Route(ws.GET("/nodes/{node-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("nodeMetrics", a.nodeMetrics)).
Doc("Export a node-level metric").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricResult{}))
if a.isRunningInKubernetes() {
ws.Route(ws.GET("/namespaces/").
To(metrics.InstrumentRouteFunc("namespaceList", a.namespaceList)).
Doc("Get a list of all namespaces that have some current metrics").
Operation("namespaceList"))
// The /namespaces/{namespace-name}/metrics endpoint returns a list of all available metrics for a Namespace entity.
ws.Route(ws.GET("/namespaces/{namespace-name}/metrics").
To(metrics.InstrumentRouteFunc("availableNamespaceMetrics", a.availableNamespaceMetrics)).
Doc("Get a list of all available metrics for a Namespace entity").
Operation("availableNamespaceMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")))
// The /namespaces/{namespace-name}/metrics/{metric-name} endpoint exposes an aggregated metrics
// for a Namespace entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("namespaceMetrics", a.namespaceMetrics)).
Doc("Export an aggregated namespace-level metric").
Operation("namespaceMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricResult{}))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/").
To(metrics.InstrumentRouteFunc("namespacePodList", a.namespacePodList)).
Doc("Get a list of pods from the given namespace that have some metrics").
Operation("namespacePodList").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")))
// The /namespaces/{namespace-name}/pods/{pod-name}/metrics endpoint returns a list of all available metrics for a Pod entity.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics").
To(metrics.InstrumentRouteFunc("availablePodMetrics", a.availablePodMetrics)).
Doc("Get a list of all available metrics for a Pod entity").
Operation("availablePodMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")))
// The /namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name} endpoint exposes
// an aggregated metric for a Pod entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)).
Doc("Export an aggregated pod-level metric").
Operation("podMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricResult{}))
//.........這裏部分代碼省略.........
示例4: addAggregationRoutes
// addAggregationRoutes adds routes to a webservice which point to a metricsAggregationFetcher's methods
func addAggregationRoutes(a metricsAggregationFetcher, ws *restful.WebService) {
// The /metrics-aggregated/{aggregations}/{metric-name} endpoint exposes some aggregations for the Cluster entity of the historical API.
ws.Route(ws.GET("/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("clusterMetrics", a.clusterAggregations)).
Doc("Export some cluster-level metric aggregations").
Operation("clusterAggregations").
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
// The /nodes/{node-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes some aggregations for a Node entity of the historical API.
// The {node-name} parameter is the hostname of a specific node.
ws.Route(ws.GET("/nodes/{node-name}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("nodeMetrics", a.nodeAggregations)).
Doc("Export a node-level metric").
Operation("nodeAggregations").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
if a.isRunningInKubernetes() {
// The /namespaces/{namespace-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes some aggregations
// for a Namespace entity of the historical API.
ws.Route(ws.GET("/namespaces/{namespace-name}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("namespaceMetrics", a.namespaceAggregations)).
Doc("Export some namespace-level metric aggregations").
Operation("namespaceAggregations").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
// The /namespaces/{namespace-name}/pods/{pod-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Pod entity of the historical API.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podAggregations)).
Doc("Export some pod-level metric aggregations").
Operation("podAggregations").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
// The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Container entity of the historical API.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerAggregations)).
Doc("Export some aggregations for a Pod Container").
Operation("podContainerAggregations").
Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")).
Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
// The /pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Pod entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podAggregations)).
Doc("Export some pod-level metric aggregations").
Operation("podAggregations").
Param(ws.PathParameter("pod-id", "The UID of the pod to lookup").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Param(ws.QueryParameter("labels", "A comma-separated list of key:values pairs to use to search for a labeled metric").DataType("string")).
Writes(types.MetricAggregationResult{}))
// The /pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Container entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerAggregations)).
Doc("Export some aggregations for a Pod Container").
Operation("podContainerAggregations").
Param(ws.PathParameter("pod-id", "The name of the pod to use").DataType("string")).
Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("aggregations", "A comma-separated list of requested aggregations").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
//.........這裏部分代碼省略.........
示例5: RegisterHistorical
// RegisterHistorical registers the Historical API endpoints. It will register the same endpoints
// as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod
// metrics by using the pod id.
func (normalApi *Api) RegisterHistorical(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/api/v1/historical").
Doc("Root endpoint of the historical access API").
Consumes("*/*").
Produces(restful.MIME_JSON)
a := &HistoricalApi{normalApi}
addClusterMetricsRoutes(a, ws)
addAggregationRoutes(a, ws)
// register the endpoint for fetching raw metrics based on pod id
if a.isRunningInKubernetes() {
// The /pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Pod entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)).
Doc("Export some pod-level metric aggregations").
Operation("podAggregations").
Param(ws.PathParameter("pod-id", "The UID of the pod to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Container entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/containers/{container-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerMetrics)).
Doc("Export some aggregations for a Pod Container").
Operation("podContainerAggregations").
Param(ws.PathParameter("pod-id", "The uid of the pod to use").DataType("string")).
Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /pod-id-list/{pod-id-list}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// metrics for a list of pod ids of the historical API.
ws.Route(ws.GET("/pod-id-list/{pod-id-list}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podListAggregations", a.podListMetrics)).
Doc("Export an aggregation for all pods from the given list").
Operation("podListAggregations").
Param(ws.PathParameter("pod-id-list", "Comma separated list of pod UIDs to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResultList{}))
}
container.Add(ws)
}
示例6: RegisterModel
// RegisterModel registers the Model API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/api/v1/model").
Doc("Root endpoint of the stats model").
Consumes("*/*").
Produces(restful.MIME_JSON)
// The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/").
To(metrics.InstrumentRouteFunc("availableClusterMetrics", a.availableClusterMetrics)).
Doc("Get a list of all available metrics for the Cluster entity").
Operation("availableClusterMetrics"))
// The /metrics/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("clusterMetrics", a.clusterMetrics)).
Doc("Export an aggregated cluster-level metric").
Operation("clusterMetrics").
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /nodes/{node-name}/metrics endpoint returns a list of all nodes with some metrics.
ws.Route(ws.GET("/nodes/").
To(metrics.InstrumentRouteFunc("nodeList", a.nodeList)).
Doc("Get a list of all nodes that have some current metrics").
Operation("nodeList"))
// The /nodes/{node-name}/metrics endpoint returns a list of all available metrics for a Node entity.
ws.Route(ws.GET("/nodes/{node-name}/metrics/").
To(metrics.InstrumentRouteFunc("availableNodeMetrics", a.availableNodeMetrics)).
Doc("Get a list of all available metrics for a Node entity").
Operation("availableNodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
// The /nodes/{node-name}/metrics/{metric-name} endpoint exposes a metric for a Node entity of the model.
// The {node-name} parameter is the hostname of a specific node.
ws.Route(ws.GET("/nodes/{node-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("nodeMetrics", a.nodeMetrics)).
Doc("Export a node-level metric").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
if a.runningInKubernetes {
ws.Route(ws.GET("/namespaces/").
To(metrics.InstrumentRouteFunc("namespaceList", a.namespaceList)).
Doc("Get a list of all namespaces that have some current metrics").
Operation("namespaceList"))
// The /namespaces/{namespace-name}/metrics endpoint returns a list of all available metrics for a Namespace entity.
ws.Route(ws.GET("/namespaces/{namespace-name}/metrics").
To(metrics.InstrumentRouteFunc("availableNamespaceMetrics", a.availableNamespaceMetrics)).
Doc("Get a list of all available metrics for a Namespace entity").
Operation("availableNamespaceMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")))
// The /namespaces/{namespace-name}/metrics/{metric-name} endpoint exposes an aggregated metrics
// for a Namespace entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("namespaceMetrics", a.namespaceMetrics)).
Doc("Export an aggregated namespace-level metric").
Operation("namespaceMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/").
To(metrics.InstrumentRouteFunc("namespacePodList", a.namespacePodList)).
Doc("Get a list of pods from the given namespace that have some metrics").
Operation("namespacePodList").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")))
// The /namespaces/{namespace-name}/pods/{pod-name}/metrics endpoint returns a list of all available metrics for a Pod entity.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics").
To(metrics.InstrumentRouteFunc("availablePodMetrics", a.availablePodMetrics)).
Doc("Get a list of all available metrics for a Pod entity").
Operation("availablePodMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")))
// The /namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name} endpoint exposes
// an aggregated metric for a Pod entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)).
Doc("Export an aggregated pod-level metric").
Operation("podMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
//.........這裏部分代碼省略.........
示例7: RegisterModel
// RegisterModel registers the Model API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container) {
ws := new(restful.WebService)
ws.
Path("/api/v1/model").
Doc("Root endpoint of the stats model").
Consumes("*/*").
Produces(restful.MIME_JSON)
// The / endpoint returns a list of all the entities that are available in the model
ws.Route(ws.GET("/").
To(a.allEntities).
Filter(compressionFilter).
Doc("Get a list of all entities available in the model").
Operation("allEntities"))
// The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/").
To(a.availableMetrics).
Filter(compressionFilter).
Doc("Get a list of all available metrics for the Cluster entity").
Operation("availableMetrics"))
// The /stats/ endpoint returns a list of all available stats for the Cluster entity of the model.
ws.Route(ws.GET("/stats/").
To(a.clusterStats).
Filter(compressionFilter).
Doc("Get all available stats for the Cluster entity").
Operation("clusterStats"))
// The /metrics/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model.
ws.Route(ws.GET("/metrics/{metric-name}").
To(a.clusterMetrics).
Filter(compressionFilter).
Doc("Export an aggregated cluster-level metric").
Operation("clusterMetrics").
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /nodes/ endpoint returns a list of all Node entities in the cluster.
ws.Route(ws.GET("/nodes/").
To(a.allNodes).
Filter(compressionFilter).
Doc("Get a list of all Nodes in the model").
Operation("allNodes").
Writes(types.MetricResult{}))
// The /nodes/{node-name} endpoint returns a list of all available API paths for a Node entity.
ws.Route(ws.GET("/nodes/{node-name}").
To(a.nodePaths).
Filter(compressionFilter).
Doc("Get a list of all available API paths for a Node entity").
Operation("nodePaths").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
// The /nodes/{node-name}/stats endpoint returns all available derived stats for a Node entity.
ws.Route(ws.GET("/nodes/{node-name}/stats/").
To(a.nodeStats).
Filter(compressionFilter).
Doc("Get all available stats for a Node entity.").
Operation("nodeStats").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
// The /nodes/{node-name}/metrics endpoint returns a list of all available metrics for a Node entity.
ws.Route(ws.GET("/nodes/{node-name}/metrics/").
To(a.availableMetrics).
Filter(compressionFilter).
Doc("Get a list of all available metrics for a Node entity").
Operation("availableMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
// The /nodes/{node-name}/metrics/{metric-name} endpoint exposes a metric for a Node entity of the model.
// The {node-name} parameter is the hostname of a specific node.
ws.Route(ws.GET("/nodes/{node-name}/metrics/{metric-name}").
To(a.nodeMetrics).
Filter(compressionFilter).
Doc("Export a node-level metric").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
if a.runningInKubernetes {
// The /namespaces/ endpoint returns a list of all Namespace entities in the model.
ws.Route(ws.GET("/namespaces/").
To(a.allNamespaces).
Filter(compressionFilter).
Doc("Get a list of all Namespaces in the model").
Operation("allNamespaces"))
// The /namespaces/{namespace-name} endpoint returns a list of all available API Paths for a Namespace entity.
ws.Route(ws.GET("/namespaces/{namespace-name}").
To(a.namespacePaths).
Filter(compressionFilter).
//.........這裏部分代碼省略.........
示例8: RegisterModel
// RegisterModel registers the Model API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start time should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container) {
ws := new(restful.WebService)
ws.
Path("/api/v1/model").
Doc("Root endpoint of the stats model").
Consumes("*/*").
Produces(restful.MIME_JSON)
// The / endpoint returns a list of all the metrics that are available in the model
ws.Route(ws.GET("/").
To(a.availableMetrics).
Filter(compressionFilter).
Doc("Show which metrics are available").
Operation("clusterMetrics"))
// The /cluster/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model.
ws.Route(ws.GET("/cluster/{metric-name}").
To(a.clusterMetrics).
Filter(compressionFilter).
Doc("Export an aggregated cluster-level metric").
Operation("clusterMetrics").
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Writes(MetricResult{}))
// The /nodes/{node-name}/{metric-name} endpoint exposes a metric for a Node entity of the model.
// The {node-name} parameter is the hostname of a specific node.
ws.Route(ws.GET("/nodes/{node-name}/{metric-name}").
To(a.nodeMetrics).
Filter(compressionFilter).
Doc("Export a node-level metric").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")).
Writes(MetricResult{}))
// The /namespaces/{namespace-name}/{metric-name} endpoint exposes an aggregated metrics
// for a Namespace entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/{metric-name}").
To(a.namespaceMetrics).
Filter(compressionFilter).
Doc("Export an aggregated namespace-level metric").
Operation("namespaceMetrics").
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Writes(MetricResult{}))
// The /namespaces/{namespace-name}/pods/{pod-name}/{metric-name} endpoint exposes
// an aggregated metric for a Pod entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/{metric-name}").
To(a.podMetrics).
Filter(compressionFilter).
Doc("Export an aggregated pod-level metric").
Operation("podMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Writes(MetricResult{}))
// The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/{metric-name} endpoint exposes
// a metric for a Container entity of the model.
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/{metric-name}").
To(a.podContainerMetrics).
Filter(compressionFilter).
Doc("Export an aggregated metric for a pod container").
Operation("podContainerMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Writes(MetricResult{}))
// The /nodes/{node-name}/freecontainers/{container-name}/{metric-name} endpoint exposes
// a metric for a free Container entity of the model.
ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/{metric-name}").
To(a.freeContainerMetrics).
Filter(compressionFilter).
Doc("Export a container-level metric for a free container").
Operation("freeContainerMetrics").
Param(ws.PathParameter("node-name", "The name of the node to use").DataType("string")).
Param(ws.PathParameter("container-name", "The name of the container to use").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Writes(MetricResult{}))
container.Add(ws)
}