Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lauchpad monitor #4469

Closed
wants to merge 14 commits into from
Closed
4 changes: 2 additions & 2 deletions .github/workflows/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio]
module: [database, pay, account, minio, launchpad]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio]
module: [database, pay, account, minio, launchpad]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
58 changes: 44 additions & 14 deletions controllers/go.work.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ replace (
github.com/labring/sealos/service => ../service
github.com/labring/sealos/service/account => ../service/account
github.com/labring/sealos/service/database => ../service/database
github.com/labring/sealos/service/launchpad => ../service/launchpad
github.com/labring/sealos/service/pkg => ../pkg
)

Expand Down
2 changes: 1 addition & 1 deletion service/go.work
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use (
./database
./pay
./account
.
./launchpad
)

replace (
Expand Down
9 changes: 9 additions & 0 deletions service/launchpad/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FROM scratch
FROM gcr.io/distroless/static:nonroot
# FROM gengweifeng/gcr-io-distroless-static-nonroot
ARG TARGETARCH
COPY bin/service-launchpad-$TARGETARCH /manager
EXPOSE 9090
USER 65532:65532

ENTRYPOINT ["/manager"]
55 changes: 55 additions & 0 deletions service/launchpad/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
IMG ?= ghcr.io/labring/sealos-launchpad-service:latest

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# only support linux, non cgo
PLATFORMS ?= linux_arm64 linux_amd64
GOOS=linux
CGO_ENABLED=0
GOARCH=$(shell go env GOARCH)

GO_BUILD_FLAGS=-trimpath -ldflags "-s -w"

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

.PHONY: clean
clean:
rm -f $(SERVICE_NAME)

.PHONY: build
build: clean ## Build service-hub binary.
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go build $(GO_BUILD_FLAGS) -o bin/manager main.go

.PHONY: docker-build
docker-build: build
mv bin/manager bin/service-launchpad-${TARGETARCH}
docker build -t $(IMG) .

.PHONY: docker-push
docker-push:
docker push $(IMG)
54 changes: 54 additions & 0 deletions service/launchpad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# RESTServer

## Description

restserver for launchpad monitoring

## Getting Started

### Running on the cluster

1. Build and push your image to the location specified by `IMG`:

```sh
make docker-build docker-push IMG=<some-registry>/sealos-cloud-launchpad-monitor:tag
```

2. Deploy the restserver:

```sh
kubectl apply -f deploy/manifests/
```

### How it works

To enable the launchpad frontend application to retrieve monitoring data, you need to modify the environment variable `MONITOR_URL` of the frontend deployment to the corresponding address of the restserver.

Additionally, to configure the data source, you need to set the environment variable `VM_SERVICE_HOST` of the restserver deployment to the correct address.

```
e.g.
http://prometheus.sealos.svc.cluster.local
```

## License

Copyright 2023.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.
55 changes: 55 additions & 0 deletions service/launchpad/api/req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package api

import "errors"

type VMRequest struct {
User string
Pwd string
NS string
Type string
LaunchPadName string
Range VMRange
}

type VMRange struct {
Start string `mapstructure:"start"`
End string `mapstructure:"end"`
Step string `mapstructure:"step"`
Time string `mapstructure:"time"`
}

type QueryResult struct {
Status string `json:"status"`
IsPartial bool `json:"isPartial"`
Data Data `json:"data"`
Stats Stats `json:"stats"`
}

type Data struct {
ResultType string `json:"resultType"`
Result []Result `json:"result"`
}

type Result struct {
Metric map[string]string `json:"metric"`
Value [2]interface{} `json:"value"`
}

type Stats struct {
SeriesFetched string `json:"seriesFetched"`
ExecutionTimeMsec int `json:"executionTimeMsec"`
}

var (
ErrNoVMHost = errors.New("unable to get the victoria-metrics host")
ErrUncompleteParam = errors.New("at least provide both namespace and query")
ErrEmptyKubeconfig = errors.New("empty kubeconfig")
ErrNilNs = errors.New("namespace not found")
)

var (
LaunchpadMonitor = map[string]string{
"cpu": "sum(container_cpu_usage_seconds_total{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\", namespace=\"ns-hkfnwdfz\",pod=~\"$pod.*\"}) by (pod)",
"memory": "sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\", namespace=\"ns-hkfnwdfz\",pod=~\"$pod.*\"}) by (pod)",
}
)
2 changes: 2 additions & 0 deletions service/launchpad/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
addr: ":8428"
5 changes: 5 additions & 0 deletions service/launchpad/deploy/Kubefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
COPY registry registry
COPY manifests manifests

CMD ["kubectl apply -f manifests/deploy.yaml"]
16 changes: 16 additions & 0 deletions service/launchpad/deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### docker image build and deploy
```bash
make docker-build IMG=$(YourImageName)
# edit deploy/manifests/depoly.yaml and deploy
kubectl apply -f deploy/manifests/depoly.yaml
```

### cluster image build and deploy
```bash
```

### Victoria Metrics

In order to prevent performance degradation or abnormal behavior caused by excessive data size in Prometheus, VictoriaMetrics is utilized for data collection.

> By default, we use kb-prometheus-server for the data collection service.
83 changes: 83 additions & 0 deletions service/launchpad/deploy/manifests/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor-config
namespace: monitor-system
data:
config.yml: |
server:
addr: ":8428"
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor-deployment
namespace: monitor-system
spec:
replicas: 1
selector:
matchLabels:
app: launchpad-monitor
strategy:
type: Recreate
template:
metadata:
labels:
app: launchpad-monitor
spec:
containers:
- args:
- /config/config.yml
command:
- /manager
env:
- name: VM_SERVICE_HOST
value: http://vmselect-cluster.vm.svc:8481/select/0/prometheus
image: wallykk/launchpad-monitor:2.0
imagePullPolicy: Always
name: launchpad-monitor
ports:
- containerPort: 8428
protocol: TCP
resources:
requests:
cpu: 1m
memory: 500M
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
runAsNonRoot: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /config
name: config-vol
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
name: launchpad-monitor-config
name: config-vol
---
apiVersion: v1
kind: Service
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor
namespace: monitor-system
spec:
ports:
- name: http
port: 8428
protocol: TCP
targetPort: 8428
selector:
app: launchpad-monitor
8 changes: 8 additions & 0 deletions service/launchpad/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/labring/sealos/service/launchpad

go 1.20

require (
github.com/labring/sealos/service v0.0.0-00010101000000-000000000000
gopkg.in/yaml.v2 v2.4.0
)
Loading
Loading