Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DB_URI = fmt.Sprintf("port=%d host=%s user=%s "+"password=%s dbname=%s sslmode=disable", PORT, HOSTNAME, DB_USER, DB_PASSWORD, DB_NAME) DB_DRIVER = "postgres" DB_USER = "postgres" DB_PASSWORD = "tmax" DB_NAME = "postgres" HOSTNAME = "postgres-service.hypercloud5-system.svc" PORT = 5432 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" PROMETHEUS_URI = "http://prometheus-k8s.monitoring:9090/api/v1/query" // use this when running on pod //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(istio_request_bytes_sum)by(destination_service, namespace)" PROMETHEUS_GET_TRAFFIC_OUT_QUERY = "sum(istio_response_bytes_sum)by(destination_service, namespace)" )
Variables ¶
View Source
var DB_URI string
Functions ¶
func MeteringJob ¶
func MeteringJob()
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.