cmd

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "maia",
	Short: "OpenStack controlled access to Prometheus metrics",
	Long: `Maia provides multi-tenancy access to Prometheus metrics through an OpenStack service. The maia command
	can be used both as server and as a client to access a Maia service running elsewhere.`,
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func LabelValues

func LabelValues(cmd *cobra.Command, args []string) (ret error)

LabelValues is just public because unit testing frameworks complains otherwise

Example (Json)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

labelName := "component"
outputFormat = "jSon"

expectAuth(keystoneMock)
storageMock.EXPECT().LabelValues(labelName, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/label_values.json"), nil)

labelValuesCmd.RunE(labelValuesCmd, []string{labelName})
Output:

{
  "Status": "success",
  "data": [
    "objectstore"
  ]
}
Example (Values)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

labelName := "component"
outputFormat = "VaLue"

expectAuth(keystoneMock)
storageMock.EXPECT().LabelValues(labelName, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/label_values.json"), nil)

labelValuesCmd.RunE(labelValuesCmd, []string{labelName})
Output:

objectstore

func MetricNames

func MetricNames(cmd *cobra.Command, args []string) (ret error)

MetricNames is just public because unit testing frameworks complains otherwise

Example (Values)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

outputFormat = "valuE"

expectAuth(keystoneMock)
storageMock.EXPECT().LabelValues("__name__", storage.JSON).Return(test.HTTPResponseFromFile("fixtures/metric_names.json"), nil)

metricNamesCmd.RunE(metricNamesCmd, []string{})
Output:

vcenter_cpu_costop_summation
vcenter_cpu_demand_average
vcenter_cpu_idle_summation
vcenter_cpu_latency_average

func Query

func Query(cmd *cobra.Command, args []string) (ret error)

Query is just public because unit testing frameworks complains otherwise

Example (Json)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

timestamp = "2017-07-01T20:10:30.781Z"
timeoutStr := "1440s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "sum(blackbox_api_status_gauge{check=~\"keystone\"})"
outputFormat = "jsoN"

expectAuth(keystoneMock)
storageMock.EXPECT().Query(query, timestamp, timeoutStr, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/query.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {},
        "value": [
          1499066783.997,
          "0"
        ]
      }
    ]
  }
}
Example (RangeJSON)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

starttime = "2017-07-13T20:10:30.781Z"
endtime = "2017-07-13T20:15:00.781Z"
stepsizeStr := "300s"
stepsize, _ = time.ParseDuration(stepsizeStr)
timeoutStr := "90s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "sum(blackbox_api_status_gauge{check=~\"keystone\"})"
outputFormat = "jsoN"

expectAuth(keystoneMock)
storageMock.EXPECT().QueryRange(query, starttime, endtime, stepsizeStr, timeoutStr, "application/json").Return(test.HTTPResponseFromFile("fixtures/query_range_values.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

{
  "status": "success",
  "data": {
    "resultType": "matrix",
    "result": [
      {
        "metric": {},
        "values": [
          [
            1499976630.781,
            "0"
          ],
          [
            1499976930.781,
            "1"
          ]
        ]
      }
    ]
  }
}
Example (RangeSeriesTable)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

starttime = "2017-07-22T20:10:00.000Z"
endtime = "2017-07-22T20:20:00.000Z"
stepsizeStr := "300s"
stepsize, _ = time.ParseDuration(stepsizeStr)
timeoutStr := "90s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "blackbox_api_status_gauge{check=~\"keystone\"})"
outputFormat = "tablE"
columns = "region,check,instance"

expectAuth(keystoneMock)
storageMock.EXPECT().QueryRange(query, starttime, endtime, stepsizeStr, timeoutStr, "application/json").Return(test.HTTPResponseFromFile("fixtures/query_range_series.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

region check instance 2017-07-22T20:10:00Z 2017-07-22T20:15:00Z 2017-07-22T20:20:00Z
staging keystone 100.64.0.102:9102 0 1 0
Example (RangeValuesTable)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

starttime = "2017-07-13T20:10:30.000Z"
endtime = "2017-07-13T20:15:00.000Z"
stepsizeStr := "300s"
stepsize, _ = time.ParseDuration(stepsizeStr)
timeoutStr := "90s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "sum(blackbox_api_status_gauge{check=~\"keystone\"})"
outputFormat = "tablE"

expectAuth(keystoneMock)
storageMock.EXPECT().QueryRange(query, starttime, endtime, stepsizeStr, timeoutStr, "application/json").Return(test.HTTPResponseFromFile("fixtures/query_range_values.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

2017-07-13T20:10:00Z 2017-07-13T20:15:00Z
0 1
Example (Table)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

timestamp = "2017-07-03T07:26:23.997Z"
timeoutStr := "1440s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "sum(blackbox_api_status_gauge{check=~\"keystone\"})"
outputFormat = "TaBle"

expectAuth(keystoneMock)
storageMock.EXPECT().Query(query, timestamp, timeoutStr, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/query.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

__timestamp__ __value__
2017-07-03T07:26:23.997Z 0
Example (TableColumns)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

timestamp = "2019-05-09T12:00:10.724Z"
timeoutStr := "1440s"
timeout, _ = time.ParseDuration(timeoutStr)
query := "limes_domain_quota"
outputFormat = "TaBle"
columns = "domain"

expectAuth(keystoneMock)
storageMock.EXPECT().Query(query, timestamp, timeoutStr, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/query2.json"), nil)

queryCmd.RunE(queryCmd, []string{query})
Output:

domain __timestamp__ __value__
monsoon3 2019-05-09T12:00:10.724Z 54975581388800
monsoon3 2019-05-09T12:00:10.724Z 11240

func Series

func Series(cmd *cobra.Command, args []string) (ret error)

Series is just public because unit testing frameworks complains otherwise

Example (Json)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

selector = "component!=\"\""
starttime = "2017-07-01T20:10:30.781Z"
endtime = "2017-07-02T04:00:00.000Z"
outputFormat = "jsoN"

expectAuth(keystoneMock)
storageMock.EXPECT().Series([]string{"{" + selector + "}"}, starttime, endtime, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/series.json"), nil)

seriesCmd.RunE(seriesCmd, []string{})
Output:

{
  "status": "success",
  "data": [
    {
      "__name__": "up",
      "component": "objectstore",
      "instance": "100.64.1.159:9102",
      "job": "endpoints",
      "kubernetes_name": "swift-proxy-cluster-3",
      "kubernetes_namespace": "swift",
      "os_cluster": "cluster-3",
      "region": "staging",
      "system": "openstack"
    }
  ]
}
Example (Table)
t := testReporter{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

selector = "component!=\"\""
starttime = "2017-07-01T20:10:30.781Z"
endtime = "2017-07-02T04:00:00.000Z"
outputFormat = "table"

expectAuth(keystoneMock)
storageMock.EXPECT().Series([]string{"{" + selector + "}"}, starttime, endtime, storage.JSON).Return(test.HTTPResponseFromFile("fixtures/series.json"), nil)

seriesCmd.RunE(seriesCmd, []string{})
Output:

__name__ component instance job kubernetes_name kubernetes_namespace os_cluster region system
up objectstore 100.64.1.159:9102 endpoints swift-proxy-cluster-3 swift cluster-3 staging openstack

func Snapshot

func Snapshot(cmd *cobra.Command, args []string) (ret error)

Snapshot is just public because unit testing frameworks complains otherwise

Example
t := testReporter{}
ctrl := gomock.NewController(&t)
defer ctrl.Finish()

keystoneMock, storageMock := setupTest(ctrl)

outputFormat = "vAlue"
selector = "vmware_name=\"win_cifs_13\""

expectAuth(keystoneMock)
storageMock.EXPECT().Federate([]string{"{" + selector + "}"}, storage.PlainText).Return(test.HTTPResponseFromFile("fixtures/federate.txt"), nil)

snapshotCmd.RunE(snapshotCmd, []string{})
Output:

# TYPE vcenter_cpu_costop_summation untyped
vcenter_cpu_costop_summation{component="vcenter-exporter-vc-a-0",instance="100.65.0.252:9102",instance_uuid="3b32f415-c953-40b9-883d-51321611a7d4",job="endpoints",kubernetes_name="vcenter-exporter-vc-a-0",kubernetes_namespace="maia",metric_detail="3",project_id="12345",region="staging",service="metrics",system="openstack",vcenter_name="STAGINGA",vcenter_node="10.44.2.40",vmware_name="win_cifs_13"} 0 1500291187275

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL