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

Feature timeformat #332

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
conf/app.conf
conf/alertgroup.conf
PrometheusAlert
PrometheusAlert.exe
logo
.idea
logs/
example/linux
example/windows
vendor
old_delete/
vendor/
old_delete/
build/*
.vscode/
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM golang:1.16-alpine3.12 as builder
FROM golang:1.20.6-alpine3.18 as builder

WORKDIR $GOPATH/src/github.com/feiyu563/PrometheusAlert

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && apk upgrade && \
RUN apk update && \
apk add --no-cache gcc g++ sqlite-libs make git

ENV GO111MODULE on
Expand All @@ -15,17 +14,17 @@ COPY . $GOPATH/src/github.com/feiyu563/PrometheusAlert
RUN make build

# -----------------------------------------------------------------------------
FROM alpine:3.12
FROM alpine:3.18

LABEL maintainer="jikun.zhang"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add tzdata && \
RUN apk update && \
apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apk del tzdata && \
mkdir -p /app/logs && \
apk update && apk upgrade && apk add --no-cache sqlite-libs curl sqlite
apk add --no-cache sqlite-libs curl sqlite

HEALTHCHECK --start-period=10s --interval=20s --timeout=3s --retries=3 \
CMD curl -fs http://localhost:8080/health || exit 1
Expand Down
42 changes: 27 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
SHELL:=/bin/sh
.PHONY: all format vet test build clean docker docker-push docker-test

export GO111MODULE=on
export GOPROXY=https://goproxy.io

pkgs = $(shell go list ./... | grep -v vendor/)

# path related
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))

DOCKER_IMAGE_NAME ?= feiyu563/prometheus-alert

BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILDDATE ?= $(shell date -I'seconds')
BUILDUSER ?= $(shell whoami)@$(shell hostname)
REVISION ?= $(shell git rev-parse HEAD)
Expand All @@ -14,44 +24,46 @@ VERSION_LDFLAGS := \
-X main.BuildUser=$(BUILDUSER) \
-X main.BuildDate=$(BUILDDATE)

all: format vet test build
# go source files, ignore vendor directory
SOURCE = $(shell find ${MKFILE_DIR} -path "${MKFILE_DIR}vendor" -prune -o -type f -name "*.go" -print)
TARGET = ${MKFILE_DIR}/PrometheusAlert

all: ${TARGET}

${TARGET}: ${SOURCE}
@echo ">> building code"
go mod tidy
go mod vendor
go build -ldflags "$(VERSION_LDFLAGS)" -o ${TARGET}

.PHONY: format
format:
@echo ">> formatting code"
go fmt $(pkgs)

.PHONY: vet
vet:
@echo ">> vetting code"
go vet $(pkgs)

.PHONY: test
test:
@echo ">> running short tests"
go test -short $(pkgs)

.PHONY: build
build:
@echo ">> building code"
go mod tidy
go mod vendor
GO11MODULE=on GO111MODULE=on GOPROXY=https://goproxy.io \
go build -ldflags "$(VERSION_LDFLAGS)" -o PrometheusAlert
build: all

clean:
@echo ">> cleaning build"
rm ${TARGET}

.PHONY: docker
docker:
@echo ">> building docker image"
docker build -t "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" .
docker tag "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" "$(DOCKER_IMAGE_NAME):latest"

.PHONY: docker-push
docker-push:
@echo ">> pushing docker image"
docker push "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)"
docker push "$(DOCKER_IMAGE_NAME):latest"

.PHONY: docker-test
docker-test:
@echo ">> testing docker image and PrometheusAlert's health"
cmd/test_image.sh "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" 8080
47 changes: 24 additions & 23 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,53 @@ PrometheusAlert是开源的运维告警中心消息转发系统,支持主流

应用信息和构建相关的命令都写入了Makefile,请确保安装`make`, `git`, `go`命令。如有特定需要,请自行修改Makefile。

```bash
```sh
# 默认
make

# 只运行构建
# 构建
make build

# 运行 go fmt
make format
# 清理构建
make clean

# 运行 go vet
make vet
# 运行 fmt/vet/test
make format/vet/test

# 运行 go test
make test
# 构建镜像,推送镜像,运行镜像
make docker/docker-push/docker-test

# 构建镜像
make docker

# 推送镜像
make docker-push

# 运行镜像测试
make docker-test


# 运行
# 本地测试运行
make clean && make build
copy conf/app-example.conf conf/app.conf
./PrometheusAlert
build/bin/PrometheusAlert

# 测试应用健康
curl http://localhost:8080/health
```

<br/>

=======
-------------------------------------

## 启动

```
```sh
#打开PrometheusAlert releases页面,根据需要选择需要的版本下载到本地解压并进入解压后的目录
如linux版本(https://github.com/feiyu563/PrometheusAlert/releases/download/v4.7/linux.zip)
如linux版本(https://github.com/feiyu563/PrometheusAlert/releases/download/v4.9/linux.zip)

# wget https://github.com/feiyu563/PrometheusAlert/releases/download/v4.7/linux.zip && unzip linux.zip &&cd linux/
# wget https://github.com/feiyu563/PrometheusAlert/releases/download/v4.9/linux.zip && unzip linux.zip &&cd linux/

#运行PrometheusAlert
# ./PrometheusAlert (#后台运行请执行 nohup ./PrometheusAlert &)

#启动后可使用浏览器打开以下地址查看:http://127.0.0.1:8080
#默认登录帐号和密码在app.conf中有配置

# 使用 supervisor 来守护启动。
# 配置参考 example/supervisor/prometheusalert.ini
# 如果需要将日志输出到控制台,请修改 app.conf 中 logtype=console
```

## Docker 启动
Expand Down Expand Up @@ -136,6 +135,7 @@ feiyu563/prometheus-alert:latest
- 增加告警路由和告警记录功能,可通过页面查看告警历史和操作告警消息路由。
- 增加告警语音播报插件。
- 增加支持飞书机器人应用。
- 增加告警组,可以将通知媒介写到告警组里面,便于配置和修改。

-------------------------------------

Expand Down Expand Up @@ -197,6 +197,7 @@ feiyu563/prometheus-alert:latest
* [告警记录-ES接入配置](doc/readme/conf-es.md)
* [语音播报](doc/readme/conf-voice.md)
* [飞书机器人应用](doc/readme/conf-feishuapp.md)
* [告警组配置](doc/readme/alertgroup.md)

* [【告警系统接入PrometheusAlert配置】](doc/readme/system.md)
* [Prometheus 接入配置](doc/readme/system-prometheus.md)
Expand Down
16 changes: 15 additions & 1 deletion conf/app-example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,18 @@ FEISHU_APPID=cli_xxxxxxxxxxxxx
# APPSECRET
FEISHU_APPSECRET=xxxxxxxxxxxxxxxxxxxxxx
# 可填飞书 用户open_id、user_id、union_ids、部门open_department_id
AT_USER_ID="xxxxxxxx"
AT_USER_ID="xxxxxxxx"


#---------------------↓告警组-----------------------
# 有其他新增的配置段,请放在告警组的上面
# 暂时仅针对 PrometheusContronller 中的 /prometheus/alert 路由
# 告警组如果放在了 wx, dd... 那部分的上分,beego section 取 url 值不太对。
# 所以这里使用 include 来包含另告警组配置

# 是否启用告警组功能
open-alertgroup=0

# 自定义的告警组既可以写在这里,也可以写在单独的文件里。
# 写在单独的告警组配置里更便于修改。
# include "alertgroup.conf"
Loading