N9E与categraf docker镜像制作记录
编辑更新内容
还是整了个公开的仓库用来扔这些东西,后面更新直接在仓库更新了,文章懒得改了
https://github.com/Mystery00/DockerImageBuilder
N9E - 夜莺 Nightingale
官方项目地址:https://github.com/ccfos/nightingale
已经忘了为什么23年3月份的时候弄了个Dockerfile来自行构建,就一直留下来了构建,每天凌晨也在持续构建
Dockerfile
FROM ubuntu:jammy
ARG N9E_VERSION
RUN apt-get update && apt-get install -y wget less && mkdir /opt/n9e
WORKDIR /opt/n9e
RUN wget -q -O n9e.tar.gz https://github.com/ccfos/nightingale/releases/download/${N9E_VERSION}/n9e-${N9E_VERSION}-linux-amd64.tar.gz && \
tar -zxf n9e.tar.gz && rm -rf n9e.tar.gz
EXPOSE 17000
CMD ["/opt/n9e/n9e"]
Docker Hub地址
https://hub.docker.com/r/mystery0/n9e
categraf
官方项目地址:https://github.com/flashcatcloud/categraf
自己做镜像的原因这个还记得,是因为我用这个组件来采集prometheus
的数据,然后用micrometer
或者其他组件将服务的指标数据暴露成prometheus
格式的数据,本身这样子使用没有什么问题,但是每一个服务都要去写categraf的配置文件,这东西又高度重复,太麻烦了,就统统扔到镜像里面了,然后把prometheus
的url以及n9e
的地址通过环境变量来注入,这样子就不需要写大量的重复配置文件了
实际上看对应的文件内容就能了解到是怎样进行配置的,对于我的使用场景足够了,就一直没管它
Dockerfile
ARG CATEGRAF_VERSION
FROM flashcatcloud/categraf:${CATEGRAF_VERSION} as builder
FROM ubuntu as final
RUN apt update && DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt -y install tzdata ca-certificates
COPY --from=builder /usr/bin/categraf /usr/bin/categraf
ADD run.sh /app/run.sh
ADD config.toml /app/conf/config.toml
ADD prometheus.toml /app/conf/input.prometheus/prometheus.toml
WORKDIR /app
CMD ["sh", "/app/run.sh"]
config.toml
[global]
print_configs = false
hostname = "$APP_NAME"
omit_hostname = false
precision = "ms"
interval = %INTERVAL%
concurrency = -1
[global.labels]
source="categraf"
[log]
file_name = "stdout"
max_size = 100
max_age = 1
max_backups = 1
local_time = true
compress = false
[writer_opt]
batch = 2000
chan_size = 10000
[[writers]]
url = "http://127.0.0.1:17000/prometheus/v1/write"
basic_auth_user = ""
basic_auth_pass = ""
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100
[http]
enable = false
# 是否启用告警自愈agent
[ibex]
enable = false
# 心跳上报
[heartbeat]
enable = true
url = "http://127.0.0.1:17000/v1/n9e/heartbeat"
interval = 10
basic_auth_user = ""
basic_auth_pass = ""
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100
# prometheus agent 功能
[prometheus]
enable = false
prometheus.toml
[[instances]]
urls = ["{PROMETHEUS_URL}"]
url_label_value = "{{.Hostname}}"
run.sh
#!/usr/bin/env bash
set -e
if [ $N9E_HOST ];then
sed -i "s/127.0.0.1:17000/$N9E_HOST/g" /app/conf/config.toml
fi
if [ $PROMETHEUS_URL ];then
sed -i "s%{PROMETHEUS_URL}%$PROMETHEUS_URL%g" /app/conf/input.prometheus/prometheus.toml
fi
if [ $INTERVAL ];then
sed -i "s/%INTERVAL%/$INTERVAL/g" /app/conf/config.toml
else
sed -i "s/%INTERVAL%/15/g" /app/conf/config.toml
fi
exec /usr/bin/categraf -configs=/app/conf
Docker Hub地址
https://hub.docker.com/r/mystery0/categraf
说明
为了能够每一次构建都获取到最新的版本,因此在构建的时候都会通过构建参数指定需要下载的版本,最新的版本信息是自己写了一个github actions工具进行获取,代码仓库
# 获取最新版本
- name: github-release-getter
uses: Mystery00/github-release-getter@v1.1
id: categraf_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repoOwner: flashcatcloud
repoName: categraf
# 使用版本信息
- name: Build and push
uses: docker/build-push-action@v5
with:
context: categraf
platforms: |
linux/amd64
linux/arm64
build-args: |
CATEGRAF_VERSION=slim-${{ steps.categraf_release.outputs.tagName }}
file: categraf/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ env.DOCKER_NAMESPACE }}/${{ env.SERVICE_NAME }}:latest
no-cache: true
懒得给这个actions写一份正式的使用说明了,将就用吧
- 0
- 0
-
分享