Skip to content

Instantly share code, notes, and snippets.

@tschuy
Last active March 14, 2019 23:24
Show Gist options
  • Save tschuy/d0c1399751e6386e7a5b7c567daa5298 to your computer and use it in GitHub Desktop.
Save tschuy/d0c1399751e6386e7a5b7c567daa5298 to your computer and use it in GitHub Desktop.
nodes by type and role
(metering:metering-tschuy) operator-metering/telemeter/new (master) → curl "http://127.0.0.1:8001/api/v1/namespaces/metering-tschuy/services/https:reporting-operator:http/proxy/api/v1/reports/get?name=compute-nodes-by-type-five-min&namespace=metering-tschuy&format=json" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 257 100 257 0 0 924 0 --:--:-- --:--:-- --:--:-- 927
[
{
"instance_type": "n1-standard-8",
"node_seconds": 1800,
"period_end": "2019-03-11T22:05:00Z",
"period_start": "2019-03-11T22:00:00Z"
},
{
"instance_type": "n1-standard-8",
"node_seconds": 1800,
"period_end": "2019-03-11T22:10:00Z",
"period_start": "2019-03-11T22:05:00Z"
}
]
(metering:metering-tschuy) operator-metering/telemeter/new (master) → curl "http://127.0.0.1:8001/api/v1/namespaces/metering-tschuy/services/https:reporting-operator:http/proxy/api/v1/reports/get?name=master-nodes-by-type-five-min&namespace=metering-tschuy&format=json" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 255 100 255 0 0 1128 0 --:--:-- --:--:-- --:--:-- 1128
[
{
"instance_type": "n1-standard-4",
"node_seconds": 300,
"period_end": "2019-03-11T22:05:00Z",
"period_start": "2019-03-11T22:00:00Z"
},
{
"instance_type": "n1-standard-4",
"node_seconds": 300,
"period_end": "2019-03-11T22:10:00Z",
"period_start": "2019-03-11T22:05:00Z"
}
]
apiVersion: metering.openshift.io/v1alpha1
kind: ReportDataSource
metadata:
name: nodes-by-type
spec:
promsum:
query: nodes-by-type
apiVersion: metering.openshift.io/v1alpha1
kind: ReportGenerationQuery
metadata:
name: "nodes-by-type-raw"
spec:
reportDataSources:
- "nodes-by-type"
columns:
- name: node_count
type: double
unit: nodes
- name: node_seconds
type: double
unit: node_seconds
# - name: cluster_uuid
# type: string
# unit: uuid
- name: timestamp
type: timestamp
unit: date
- name: timeprecision
type: double
unit: seconds
- name: instance_type
type: string
- name: compute
type: boolean
- name: master
type: boolean
- name: dt
type: string
query: |
SELECT amount as node_count,
amount * timeprecision as node_seconds,
element_at(labels, 'label_beta_kubernetes_io_instance_type') as instance_type,
CAST(element_at(labels, 'label_node_role_kubernetes_io_compute') AS BOOLEAN) as compute,
CAST(element_at(labels, 'label_node_role_kubernetes_io_master') AS BOOLEAN) as master,
timestamp,
timeprecision,
dt
FROM {| dataSourceTableName "nodes-by-type" |}
---
apiVersion: metering.openshift.io/v1alpha1
kind: ReportGenerationQuery
metadata:
name: "compute-nodes-by-type"
spec:
reportQueries:
- "nodes-by-type-raw"
view:
disabled: true
columns:
- name: period_start
type: timestamp
unit: date
- name: period_end
type: timestamp
unit: date
# - name: cluster_uuid
# type: string
# unit: uuid
- name: node_seconds
type: double
unit: node_seconds
- name: instance_type
type: string
inputs:
- name: ReportingStart
- name: ReportingEnd
query: |
SELECT
timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart| prestoTimestamp |}' AS period_start,
timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}' AS period_end,
sum(node_seconds) as node_seconds,
instance_type as instance_type
FROM {| generationQueryViewName "nodes-by-type-raw" |}
WHERE compute
AND "timestamp" >= timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prestoTimestamp |}'
AND "timestamp" < timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}'
AND dt >= '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prometheusMetricPartitionFormat |}'
AND dt <= '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prometheusMetricPartitionFormat |}'
GROUP BY instance_type
ORDER BY node_seconds DESC
---
apiVersion: metering.openshift.io/v1alpha1
kind: ReportGenerationQuery
metadata:
name: "master-nodes-by-type"
spec:
reportQueries:
- "nodes-by-type-raw"
view:
disabled: true
columns:
- name: period_start
type: timestamp
unit: date
- name: period_end
type: timestamp
unit: date
# - name: cluster_uuid
# type: string
# unit: uuid
- name: node_seconds
type: double
unit: node_seconds
- name: instance_type
type: string
inputs:
- name: ReportingStart
- name: ReportingEnd
query: |
SELECT
timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart| prestoTimestamp |}' AS period_start,
timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}' AS period_end,
sum(node_seconds) as node_seconds,
instance_type as instance_type
FROM {| generationQueryViewName "nodes-by-type-raw" |}
WHERE master
AND "timestamp" >= timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prestoTimestamp |}'
AND "timestamp" < timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}'
AND dt >= '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prometheusMetricPartitionFormat |}'
AND dt <= '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prometheusMetricPartitionFormat |}'
GROUP BY instance_type
ORDER BY node_seconds DESC
apiVersion: metering.openshift.io/v1alpha1
kind: ReportPrometheusQuery
metadata:
name: nodes-by-type
spec:
query: |
count(kube_node_labels) BY (label_beta_kubernetes_io_instance_type, label_node_role_kubernetes_io_compute, label_node_role_kubernetes_io_master)
apiVersion: metering.openshift.io/v1alpha1
kind: Report
metadata:
name: compute-nodes-by-type-five-min
spec:
generationQuery: "compute-nodes-by-type"
gracePeriod: "1m"
schedule:
period: "cron"
cron:
expression: "*/5 * * * *"
---
apiVersion: metering.openshift.io/v1alpha1
kind: Report
metadata:
name: master-nodes-by-type-five-min
spec:
generationQuery: "master-nodes-by-type"
gracePeriod: "1m"
schedule:
period: "cron"
cron:
expression: "*/5 * * * *"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment