-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 232a390
Showing
626 changed files
with
249,276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: [ '*' ] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}{% raw %} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
push: true | ||
tags: { % raw % }${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.16-alpine as builder | ||
|
||
WORKDIR $GOPATH/src/kts/push | ||
COPY . . | ||
RUN go build pkg/main.go | ||
RUN cp main / | ||
|
||
FROM alpine:3.14 | ||
|
||
COPY --from=builder /main /app/ | ||
WORKDIR /app | ||
CMD ./main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Selectel Exporter | ||
|
||
Prometheus exporter для получения информации по аккаунту облака [Selectel](https://selectel.ru). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module kts/selectel-exporter | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/prometheus/client_golang v1.11.0 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
type ExporterConfig struct { | ||
Token string | ||
Region string | ||
} | ||
|
||
func Parse() (*ExporterConfig, error) { | ||
conf := &ExporterConfig{} | ||
|
||
token, ok := os.LookupEnv("SELECTEL_TOKEN") | ||
if !ok { | ||
return nil, errors.New("env variable SELECTEL_TOKEN is required") | ||
} | ||
conf.Token = token | ||
|
||
region, ok := os.LookupEnv("SELECTEL_REGION") | ||
if !ok { | ||
return nil, errors.New("env variable SELECTEL_REGION is required") | ||
} | ||
conf.Region = region | ||
|
||
return conf, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package exporter | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"kts/selectel-exporter/pkg/selapi" | ||
"log" | ||
) | ||
|
||
type primaryMetrics struct { | ||
main prometheus.Gauge | ||
bonus prometheus.Gauge | ||
vkRub prometheus.Gauge | ||
ref prometheus.Gauge | ||
holdMain prometheus.Gauge | ||
holdBonus prometheus.Gauge | ||
holdVkRub prometheus.Gauge | ||
} | ||
|
||
type storageMetrics struct { | ||
main prometheus.Gauge | ||
bonus prometheus.Gauge | ||
vkRub prometheus.Gauge | ||
debt prometheus.Gauge | ||
sum prometheus.Gauge | ||
} | ||
|
||
type vpcMetrics storageMetrics | ||
type vmwareMetrics storageMetrics | ||
|
||
type balanceCollector struct { | ||
primary primaryMetrics | ||
storage storageMetrics | ||
vpc vpcMetrics | ||
vmware vmwareMetrics | ||
} | ||
|
||
func registerGauge(name string, project selapi.Project) prometheus.Gauge { | ||
g := prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Name: name, | ||
ConstLabels: prometheus.Labels{"project": project.Name}, | ||
}) | ||
prometheus.MustRegister(g) | ||
return g | ||
} | ||
|
||
func NewBalanceCollector(project selapi.Project) *balanceCollector { | ||
c := &balanceCollector{} | ||
|
||
c.primary.main = registerGauge("selectel_billing_primary_main", project) | ||
c.primary.bonus = registerGauge("selectel_billing_primary_bonus", project) | ||
c.primary.vkRub = registerGauge("selectel_billing_primary_vk_rub", project) | ||
c.primary.ref = registerGauge("selectel_billing_primary_ref", project) | ||
c.primary.holdMain = registerGauge("selectel_billing_primary_hold_main", project) | ||
c.primary.holdBonus = registerGauge("selectel_billing_primary_hold_bonus", project) | ||
c.primary.holdVkRub = registerGauge("selectel_billing_primary_hold_vk_rub", project) | ||
|
||
c.storage.main = registerGauge("selectel_billing_storage_main", project) | ||
c.storage.bonus = registerGauge("selectel_billing_storage_bonus", project) | ||
c.storage.vkRub = registerGauge("selectel_billing_storage_vk_rub", project) | ||
c.storage.debt = registerGauge("selectel_billing_storage_debt", project) | ||
c.storage.sum = registerGauge("selectel_billing_storage_sum", project) | ||
|
||
c.vpc.main = registerGauge("selectel_billing_vpc_main", project) | ||
c.vpc.bonus = registerGauge("selectel_billing_vpc_bonus", project) | ||
c.vpc.vkRub = registerGauge("selectel_billing_vpc_vk_rub", project) | ||
c.vpc.debt = registerGauge("selectel_billing_vpc_debt", project) | ||
c.vpc.sum = registerGauge("selectel_billing_vpc_sum", project) | ||
|
||
c.vmware.main = registerGauge("selectel_billing_vmware_main", project) | ||
c.vmware.bonus = registerGauge("selectel_billing_vmware_bonus", project) | ||
c.vmware.vkRub = registerGauge("selectel_billing_vmware_vk_rub", project) | ||
c.vmware.debt = registerGauge("selectel_billing_vmware_debt", project) | ||
c.vmware.sum = registerGauge("selectel_billing_vmware_sum", project) | ||
|
||
return c | ||
} | ||
|
||
func (c *balanceCollector) Collect(e *exporter) error { | ||
log.Println("collect balance metrics") | ||
|
||
res, err := selapi.FetchBalance(e.token) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.primary.main.Set(float64(res.Data.Primary.Main)) | ||
c.primary.bonus.Set(float64(res.Data.Primary.Bonus)) | ||
c.primary.vkRub.Set(float64(res.Data.Primary.VkRub)) | ||
c.primary.ref.Set(float64(res.Data.Primary.Ref)) | ||
c.primary.holdMain.Set(float64(res.Data.Primary.Hold.Main)) | ||
c.primary.holdBonus.Set(float64(res.Data.Primary.Hold.Bonus)) | ||
c.primary.holdVkRub.Set(float64(res.Data.Primary.Hold.VkRub)) | ||
|
||
c.storage.main.Set(float64(res.Data.Storage.Main)) | ||
c.storage.bonus.Set(float64(res.Data.Storage.Bonus)) | ||
c.storage.vkRub.Set(float64(res.Data.Storage.VkRub)) | ||
c.storage.debt.Set(float64(res.Data.Storage.Debt)) | ||
c.storage.sum.Set(float64(res.Data.Storage.Sum)) | ||
|
||
c.vpc.main.Set(float64(res.Data.Vpc.Main)) | ||
c.vpc.bonus.Set(float64(res.Data.Vpc.Bonus)) | ||
c.vpc.vkRub.Set(float64(res.Data.Vpc.VkRub)) | ||
c.vpc.debt.Set(float64(res.Data.Vpc.Debt)) | ||
c.vpc.sum.Set(float64(res.Data.Vpc.Sum)) | ||
|
||
c.vmware.main.Set(float64(res.Data.Vmware.Main)) | ||
c.vmware.bonus.Set(float64(res.Data.Vmware.Bonus)) | ||
c.vmware.vkRub.Set(float64(res.Data.Vmware.VkRub)) | ||
c.vmware.debt.Set(float64(res.Data.Vmware.Debt)) | ||
c.vmware.sum.Set(float64(res.Data.Vmware.Sum)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package exporter | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"kts/selectel-exporter/pkg/selapi" | ||
"log" | ||
"time" | ||
) | ||
|
||
type datastoreMetrics struct { | ||
memoryPercent prometheus.Gauge | ||
memoryBytes prometheus.Gauge | ||
cpu prometheus.Gauge | ||
diskPercent prometheus.Gauge | ||
diskBytes prometheus.Gauge | ||
} | ||
|
||
type datastoreCollector struct { | ||
project selapi.Project | ||
datastore selapi.Datastore | ||
metrics map[string]*datastoreMetrics | ||
} | ||
|
||
func NewDatastoreCollector(project selapi.Project, datastore selapi.Datastore) *datastoreCollector { | ||
return &datastoreCollector{ | ||
project: project, | ||
datastore: datastore, | ||
metrics: make(map[string]*datastoreMetrics), | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) registerGauge(name string, g prometheus.Gauge, ip string, value float64) prometheus.Gauge { | ||
if g == nil { | ||
g = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Name: name, | ||
ConstLabels: prometheus.Labels{"project": col.project.Name, "datastore": col.datastore.Name, "ip": ip}, | ||
}) | ||
prometheus.MustRegister(g) | ||
} | ||
g.Set(value) | ||
return g | ||
} | ||
|
||
func (col *datastoreCollector) initMetric(ip string) *datastoreMetrics { | ||
if _, ok := col.metrics[ip]; !ok { | ||
col.metrics[ip] = &datastoreMetrics{} | ||
} | ||
return col.metrics[ip] | ||
} | ||
|
||
func (col *datastoreCollector) loadMemoryPercent(data *selapi.DatastoreMetricsResponses) { | ||
for _, item := range data.Metrics.MemoryPercent { | ||
m := col.initMetric(item.Ip) | ||
m.memoryPercent = col.registerGauge( | ||
"selectel_datastore_memory_percent", m.memoryPercent, item.Ip, item.Last) | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) loadMemoryBytes(data *selapi.DatastoreMetricsResponses) { | ||
for _, item := range data.Metrics.MemoryBytes { | ||
m := col.initMetric(item.Ip) | ||
m.memoryBytes = col.registerGauge( | ||
"selectel_datastore_memory_bytes", m.memoryBytes, item.Ip, item.Last) | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) loadCpu(data *selapi.DatastoreMetricsResponses) { | ||
for _, item := range data.Metrics.Cpu { | ||
m := col.initMetric(item.Ip) | ||
m.cpu = col.registerGauge("selectel_datastore_cpu", m.cpu, item.Ip, item.Last) | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) loadDiskPercent(data *selapi.DatastoreMetricsResponses) { | ||
for _, item := range data.Metrics.DiskPercent { | ||
m := col.initMetric(item.Ip) | ||
m.diskPercent = col.registerGauge( | ||
"selectel_datastore_disk_percent", m.diskPercent, item.Ip, item.Last) | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) loadDiskBytes(data *selapi.DatastoreMetricsResponses) { | ||
for _, item := range data.Metrics.DiskBytes { | ||
m := col.initMetric(item.Ip) | ||
m.diskBytes = col.registerGauge( | ||
"selectel_datastore_disk_bytes", m.diskBytes, item.Ip, item.Last) | ||
} | ||
} | ||
|
||
func (col *datastoreCollector) Collect(e *exporter) error { | ||
log.Printf("collect datastore metrics") | ||
start := time.Now().Add(-1 * time.Minute).Unix() | ||
end := time.Now().Unix() | ||
res, err := selapi.FetchDatastoreMetrics(e.openstackAccountToken, e.region, col.datastore.Id, start, end) | ||
if err != nil { | ||
return err | ||
} | ||
col.loadMemoryPercent(res) | ||
col.loadMemoryBytes(res) | ||
col.loadCpu(res) | ||
col.loadDiskPercent(res) | ||
col.loadDiskBytes(res) | ||
return nil | ||
} |
Oops, something went wrong.