metering

package
v0.0.0-...-0137e5c Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	METERING_INSERT_QUERY = "insert into metering (id,namespace,cpu,memory,storage,gpu,public_ip,private_ip, traffic_in, traffic_out, metering_time, status) " +
		"values ($1,$2,trunc($3,2),$4, $5,trunc($6,2),$7,$8,$9,$10,$11,$12)"
	METERING_DELETE_QUERY = "truncate metering"

	METERING_HOUR_INSERT_QUERY = "insert into metering_hour values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"
	METERING_HOUR_SELECT_QUERY = "SELECT namespace, TRUNC(CAST(SUM(cpu)/COUNT(*) as numeric) ,2) as cpu, " +
		"TRUNC(CAST(SUM(memory)/COUNT(*) as numeric) ,0) as memory, TRUNC(CAST(SUM(storage)/COUNT(*) as numeric) ,0) as storage, " +
		"TRUNC(CAST(SUM(gpu)/COUNT(*) as numeric) ,2) as gpu, SUM(public_ip)/COUNT(*) as public_ip, SUM(private_ip)/COUNT(*) as private_ip, " +
		"TRUNC(CAST(SUM(traffic_in)/COUNT(*) as numeric) ,0) as traffic_in, TRUNC(CAST(SUM(traffic_out)/COUNT(*) as numeric) ,0) as traffic_out, " +
		"DATE_TRUNC('hour', metering_time) as metering_time, status FROM metering GROUP BY DATE_TRUNC('hour', metering_time), namespace, status"
	METERING_HOUR_UPDATE_QUERY = "update metering_hour set status = 'Merged' where status = 'Success'"
	METERING_HOUR_DELETE_QUERY = "delete from metering_hour where status = 'Merged'"

	METERING_DAY_INSERT_QUERY = "insert into metering_day values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"
	METERING_DAY_SELECT_QUERY = "SELECT namespace, TRUNC(CAST(SUM(cpu)/COUNT(*) as numeric) ,2) as cpu, " +
		"TRUNC(CAST(SUM(memory)/COUNT(*) as numeric) ,0) as memory, TRUNC(CAST(SUM(storage)/COUNT(*) as numeric) ,0) as storage, " +
		"TRUNC(CAST(SUM(gpu)/COUNT(*) as numeric) ,2) as gpu, SUM(public_ip)/COUNT(*) as public_ip, SUM(private_ip)/COUNT(*) as private_ip, " +
		"TRUNC(CAST(SUM(traffic_in)/COUNT(*) as numeric) ,0) as traffic_in, TRUNC(CAST(SUM(traffic_out)/COUNT(*) as numeric) ,0) as traffic_out, " +
		"DATE_TRUNC('day', metering_time) as metering_time, status FROM metering_hour WHERE status='Success' GROUP BY DATE_TRUNC('day', metering_time), namespace, status"
	METERING_DAY_UPDATE_QUERY = "update metering_day set status = 'Merged' where status = 'Success'"
	METERING_DAY_DELETE_QUERY = "delete from metering_day where status = 'Merged'"

	METERING_MONTH_INSERT_QUERY = "insert into metering_month values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"
	METERING_MONTH_SELECT_QUERY = "SELECT namespace, TRUNC(CAST(SUM(cpu)/COUNT(*) as numeric) ,2) as cpu, " +
		"TRUNC(CAST(SUM(memory)/COUNT(*) as numeric) ,0) as memory, TRUNC(CAST(SUM(storage)/COUNT(*) as numeric) ,0) as storage, " +
		"TRUNC(CAST(SUM(gpu)/COUNT(*) as numeric) ,2) as gpu, SUM(public_ip)/COUNT(*) as public_ip, SUM(private_ip)/COUNT(*) as private_ip, " +
		"TRUNC(CAST(SUM(traffic_in)/COUNT(*) as numeric) ,0) as traffic_in, TRUNC(CAST(SUM(traffic_out)/COUNT(*) as numeric) ,0) as traffic_out, " +
		"DATE_TRUNC('month', metering_time) as metering_time, status FROM metering_day WHERE status='Success' GROUP BY DATE_TRUNC('month', metering_time), namespace, status"
	METERING_MONTH_UPDATE_QUERY = "update metering_month set status = 'Merged' where status = 'Success'"
	METERING_MONTH_DELETE_QUERY = "delete from metering_month where status = 'Merged'"

	METERING_YEAR_INSERT_QUERY = "insert into metering_year values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"
	METERING_YEAR_SELECT_QUERY = "SELECT namespace, TRUNC(CAST(SUM(cpu)/COUNT(*) as numeric) ,2) as cpu, " +
		"TRUNC(CAST(SUM(memory)/COUNT(*) as numeric) ,0) as memory, TRUNC(CAST(SUM(storage)/COUNT(*) as numeric) ,0) as storage, " +
		"TRUNC(CAST(SUM(gpu)/COUNT(*) as numeric) ,2) as gpu, SUM(public_ip)/COUNT(*) as public_ip, SUM(private_ip)/COUNT(*) as private_ip, " +
		"TRUNC(CAST(SUM(traffic_in)/COUNT(*) as numeric) ,0) as traffic_in, TRUNC(CAST(SUM(traffic_out)/COUNT(*) as numeric) ,0) as traffic_out, " +
		"DATE_TRUNC('year', metering_time) as metering_time, status FROM metering_month WHERE status='Success' GROUP BY DATE_TRUNC('year', metering_time), namespace, status"

	FORCE_DELETE_HOUR_QUERY  = "DELETE FROM metering WHERE namespace=$1 and metering_time between $2 and $3"
	FORCE_UPDATE_DAY_QUERY   = "UPDATE metering_hour SET status = 'Merged' WHERE namespace=$1 and status = 'Success' and metering_time between $2 and $3"
	FORCE_UPDATE_MONTH_QUERY = "UPDATE metering_day SET status = 'Merged' WHERE namespace=$1 and status = 'Success' and metering_time between $2 and $3"
	FORCE_UPDATE_YEAR_QUERY  = "UPDATE metering_month SET status = 'Merged' WHERE namespace=$1 and status = 'Success' and metering_time between $2 and $3"

	PROMETHEUS_URI = "http://prometheus-k8s.monitoring:9090/api/v1/query"
	//PROMETHEUS_GET_CPU_QUERY         = "namespace:container_cpu_usage_seconds_total:sum_rate"
	//PROMETHEUS_GET_MEMORY_QUERY      = "namespace:container_memory_usage_bytes:sum"
	PROMETHEUS_GET_CPU_QUERY         = "sum(kube_pod_container_resource_requests{resource=\"cpu\"})by(namespace)"
	PROMETHEUS_GET_MEMORY_QUERY      = "sum(kube_pod_container_resource_requests{resource=\"memory\"})by(namespace)"
	PROMETHEUS_GET_STORAGE_QUERY     = "sum(kube_persistentvolumeclaim_resource_requests_storage_bytes)by(namespace)"
	PROMETHEUS_GET_PUBLIC_IP_QUERY   = "count(kube_service_spec_type{type=\"LoadBalancer\"})by(namespace)"
	PROMETHEUS_GET_TRAFFIC_IN_QUERY  = "sum(rate(container_network_receive_bytes_total[1m]))by(namespace)"
	PROMETHEUS_GET_TRAFFIC_OUT_QUERY = "sum(rate(container_network_transmit_bytes_total[1m]))by(namespace)"
)

Variables

This section is empty.

Functions

func Get

func Get(res http.ResponseWriter, req *http.Request)

func HandleDuplicateError

func HandleDuplicateError(table string, m meteringModel.Metering) error

HandleDuplicateError handles error of duplicate key

func MeteringJob

func MeteringJob()

func Options

func Options(res http.ResponseWriter, req *http.Request)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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