Skip to content

Commit

Permalink
goreleaser experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
mxssl committed Feb 10, 2024
1 parent 9a42379 commit 0e55b14
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
7 changes: 3 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
archives:
- name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
format: tar.gz
dockers:
- goos: linux
goarch: amd64
Expand Down
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# syntax=docker/dockerfile:1
FROM golang:1.21.6-alpine3.18 as builder

ENV GO111MODULE=on

WORKDIR /go/src/github.com/mxssl/selectel-billing-exporter
COPY . .

RUN apk add --no-cache \
ca-certificates \
curl \
git

RUN CGO_ENABLED=0 \
RUN <<EOF
apk add --no-cache \
ca-certificates \
curl \
git
EOF
RUN <<EOF
CGO_ENABLED=0 \
go build -v -o app
EOF

FROM alpine:3.19.1
WORKDIR /
RUN apk add --no-cache \
ca-certificates
RUN apk add --no-cache ca-certificates
COPY --from=builder /go/src/github.com/mxssl/selectel-billing-exporter .
RUN chmod +x app
CMD ["./app"]
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@ Prometheus exporter для получения информации по билл

```yaml
version: '3'

services:
selectel_exporter:
image: mxssl/selectel-billing-exporter:1.1.1
image: mxssl/selectel-billing-exporter:1.1.3
ports:
- "6789:80"
restart: always
environment:
TOKEN: тут_указываем_токен
TOKEN: <тут_указываем_токен>
```
Запускаем экспортер:
```sh
docker-compose up -d
docker compose up -d
```

Проверить работу экспортера:

```sh
docker-compose ps
docker-compose logs
docker compose ps
docker compose logs
```

Метрики доступны по url `your_ip:6789/metrics`
Expand Down Expand Up @@ -68,7 +67,7 @@ spec:
spec:
containers:
- name: exporter
image: mxssl/selectel-billing-exporter:1.1.1
image: mxssl/selectel-billing-exporter:1.1.3
command: ["./app"]
ports:
- containerPort: 80
Expand All @@ -95,15 +94,15 @@ spec:
kubectl apply -n exporters -f your-file.yaml
```

Для namespace exporters метрики будут доступны по адресу `selectel-billing.exporters:6789/metrics`
Внутри кластера метрики будут доступны по адресу `selectel-billing.exporters.svc.cluster.local:6789/metrics`

## Настройка для prometheus

```yaml
- job_name: 'selectel_billing'
scrape_interval: 60m
static_configs:
- targets: ['exporter_ip:6789']
- targets: ['exporter_address:6789']
```
## Пример алерта для alertmanager
Expand All @@ -115,8 +114,8 @@ kubectl apply -n exporters -f your-file.yaml
labels:
severity: warning
annotations:
summary: "{{ $labels.instance }}: В облаке Selectel на счете меньше 30 тыс рублей"
description: "Необходимо пополнить счет облака Selectel"
summary: "{{ $labels.instance }}: В хостинге Selectel на счете меньше 30 000 рублей"
description: "Необходимо пополнить счет в хостинге Selectel"
```
## Дашборд для графаны
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: '3'

services:
selectel-billing-exporter:
container_name: selectel-billing-exporter
build: .
image: mxssl/selectel-billing-exporter:1.0.2
image: mxssl/selectel-billing-exporter:1.0.3
ports:
- "6789:80"
restart: always
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// TOKEN for selectel API
// TOKEN для Selectel API
var TOKEN string

type selectelBillingResponse struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ func main() {
log.Fatal(srv.ListenAndServe())
}()

log.Println("Экспортер готов принимать запросы от прометеуса на /metrics")
log.Println("Экспортер готов принимать запросы от Prometheus на /metrics")

c := make(chan os.Signal, 1)

Expand Down

0 comments on commit 0e55b14

Please sign in to comment.