Skip to content

Commit

Permalink
🌱 add: vngcloud vmonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed Jul 19, 2024
1 parent 99fcdc2 commit 028068a
Show file tree
Hide file tree
Showing 21 changed files with 1,478 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/build-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build and Release package
on:
push:
# Pattern matched against refs/tags
tags:
- "**" # Push events to every tag including hierarchical tags like v1.0/beta

jobs:
create_release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "${{ github.ref_name }}" \
--repo="$GITHUB_REPOSITORY" \
--title="${{ github.ref_name }}" \
--generate-notes
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Install dependencies
run: sudo apt -y install rubygems && sudo gem install fpm && sudo apt install binutils && sudo apt-get install rpm -y

- name: Clear build directory
run: rm -rf ./build/

- name: Build
run: NIGHTLY=vmonitor make package include_packages="freebsd_amd64.tar.gz linux_amd64.tar.gz amd64.deb x86_64.rpm"
# run: NIGHTLY=vmonitor make package include_packages="freebsd_amd64.tar.gz linux_amd64.tar.gz amd64.deb x86_64.rpm linux_arm64.tar.gz arm64.deb aarch64.rpm freebsd_i386.tar.gz i386.deb linux_i386.tar.gz i386.rpm"

- name: Install Windows dependencies
run: go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest

- name: Debug
run: |
export PATH=${PATH}:~/go/bin
export PATH=${PATH}:`go env GOPATH`/bin
echo $PATH
ls -al ./cmd/telegraf/
rm -rf ./cmd/telegraf/*.syso
goversioninfo -skip-versioninfo
- name: Build Windows package
run: |
export PATH=${PATH}:~/go/bin
export PATH=${PATH}:`go env GOPATH`/bin
echo $PATH
NIGHTLY=vmonitor make package include_packages="windows_amd64.zip"
# NIGHTLY=vmonitor make package include_packages="windows_i386.zip windows_amd64.zip windows_arm64.zip"

- name: Debug
run: ls -al ./cmd/telegraf/ && ls -al ./build/dist/

- name: Upload files to a GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: for file in ./build/dist/*; do gh release upload "${{ github.ref_name }}" "$file" --repo="$GITHUB_REPOSITORY"; done

############## build and upload image
- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to the vCR
uses: docker/login-action@v3
with:
registry: vcr.vngcloud.vn
username: ${{ secrets.VCR_USER_PRO }}
password: ${{ secrets.VCR_PASSWORD_PRO }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ github.ref_name }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.ref_name }}
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.sha }}
# labels: ${{ steps.metadata.outputs.labels }}

- name: Build and push Docker image Alpine
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ github.ref_name }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker/alpine
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.ref_name }}-alpine
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}-alpine
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.ref_name }}-alpine
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.sha }}-alpine
# labels: ${{ steps.metadata.outputs.labels }}
75 changes: 75 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI
on: push

env:
TMP_RELEASE: 1.31.0-1.0.0

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Install dependencies
run: sudo apt -y install rubygems && sudo gem install fpm && sudo apt install binutils && sudo apt-get install rpm -y

- name: Clear build directory
run: rm -rf ./build/

- name: Debug
run: ls -al ./cmd/telegraf/

- name: Build
run: NIGHTLY=vmonitor make package include_packages="linux_amd64.tar.gz amd64.deb"

- name: Debug
run: ls -al ./cmd/telegraf/ && ls -al ./build/dist/

- name: Upload files to a GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.TMP_RELEASE }}
run: for file in ./build/dist/*; do gh release upload "${{ env.TMP_RELEASE }}" "$file" --repo="$GITHUB_REPOSITORY" --clobber; done

############## build and upload image
- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to the vCR
uses: docker/login-action@v3
with:
registry: vcr.vngcloud.vn
username: ${{ secrets.VCR_USER_PRO }}
password: ${{ secrets.VCR_PASSWORD_PRO }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ env.TMP_RELEASE }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.sha }}
# labels: ${{ steps.metadata.outputs.labels }}

- name: Build and push Docker image Alpine
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ env.TMP_RELEASE }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker/alpine
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}-alpine
vcr.vngcloud.vn/81-vmp-public/telegraf:${{ github.sha }}-alpine
# labels: ${{ steps.metadata.outputs.labels }}
17 changes: 17 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: golangci-lint
on: push

jobs:
golangci:
name: lint-codebase
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.22"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
args: --timeout 15m0s --verbose --out-${NO_FUTURE}format tab
14 changes: 14 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: govulncheck
on: push

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Scan for Vulnerabilities in Code
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.22.4
go-package: ./...
31 changes: 31 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM buildpack-deps:bullseye-curl

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends iputils-ping snmp procps lm-sensors libcap2-bin && \
rm -rf /var/lib/apt/lists/*

ARG ARG_VERSION
ENV TELEGRAF_VERSION $ARG_VERSION

ARG ARG_GITHUB_REPOSITORY
ENV GITHUB_REPOSITORY $ARG_GITHUB_REPOSITORY

RUN echo ${TELEGRAF_VERSION}

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) ARCH='amd64';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armhf';; \
armel) ARCH='armel';; \
*) echo "Unsupported architecture: ${dpkgArch}"; exit 1;; \
esac && \
wget --no-verbose https://github.com/${GITHUB_REPOSITORY}/releases/download/${TELEGRAF_VERSION}/telegraf_nightly_${ARCH}.deb && \
dpkg -i telegraf_nightly_${ARCH}.deb && \
rm -f telegraf_nightly_${ARCH}.deb*

EXPOSE 8125/udp 8092/udp 8094

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf"]
40 changes: 40 additions & 0 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM alpine:3.17

RUN echo 'hosts: files dns' >> /etc/nsswitch.conf
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata su-exec libcap && \
update-ca-certificates

ARG ARG_VERSION
ENV TELEGRAF_VERSION $ARG_VERSION

ARG ARG_GITHUB_REPOSITORY
ENV GITHUB_REPOSITORY $ARG_GITHUB_REPOSITORY

RUN ARCH= && \
case "$(apk --print-arch)" in \
x86_64) ARCH='amd64';; \
aarch64) ARCH='arm64';; \
*) echo "Unsupported architecture: $(apk --print-arch)"; exit 1;; \
esac && \
set -ex && \
mkdir ~/.gnupg; \
echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf; \
apk add --no-cache --virtual .build-deps wget gnupg tar && \
wget --no-verbose https://github.com/${GITHUB_REPOSITORY}/releases/download/${TELEGRAF_VERSION}/telegraf-nightly_linux_${ARCH}.tar.gz && \
mkdir -p /usr/src /etc/telegraf && \
tar -C /usr/src -xzf telegraf-nightly_linux_${ARCH}.tar.gz && \
mv /usr/src/telegraf*/etc/telegraf/telegraf.conf /etc/telegraf/ && \
mkdir /etc/telegraf/telegraf.d && \
cp -a /usr/src/telegraf*/usr/bin/telegraf /usr/bin/ && \
gpgconf --kill all && \
rm -rf *.tar.gz* /usr/src /root/.gnupg && \
apk del .build-deps && \
addgroup -S telegraf && \
adduser -S telegraf -G telegraf && \
chown -R telegraf:telegraf /etc/telegraf

EXPOSE 8125/udp 8092/udp 8094

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf"]
15 changes: 15 additions & 0 deletions docker/alpine/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

if [ "$(echo "$1" | cut -c1)" = '-' ]; then
set -- telegraf "$@"
fi

if [ "$(id -u)" -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"

exec su-exec telegraf "$@"
fi
15 changes: 15 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi

if [ $EUID -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"

exec setpriv --reuid telegraf --init-groups "$@"
fi
1 change: 1 addition & 0 deletions docs/LICENSE_OF_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ following works:
- github.com/logzio/azure-monitor-metrics-receiver [MIT License](https://github.com/logzio/azure-monitor-metrics-receiver/blob/master/LICENSE)
- github.com/magiconair/properties [BSD 2-Clause "Simplified" License](https://github.com/magiconair/properties/blob/main/LICENSE.md)
- github.com/mailru/easyjson [MIT License](https://github.com/mailru/easyjson/blob/master/LICENSE)
- github.com/matishsiao/goInfo [MIT License](https://github.com/matishsiao/goInfo/blob/master/LICENSE)
- github.com/mattn/go-colorable [MIT License](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- github.com/mattn/go-ieproxy [MIT License](https://github.com/mattn/go-ieproxy/blob/master/LICENSE)
- github.com/mattn/go-isatty [MIT License](https://github.com/mattn/go-isatty/blob/master/LICENSE)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ require (
github.com/linkedin/goavro/v2 v2.13.0
github.com/logzio/azure-monitor-metrics-receiver v1.0.2
github.com/lxc/incus/v6 v6.2.0
github.com/matishsiao/goInfo v0.0.0-20210923090445-da2e3fa8d45f
github.com/mdlayher/apcupsd v0.0.0-20220319200143-473c7b5f3c6a
github.com/mdlayher/vsock v1.2.1
github.com/microsoft/ApplicationInsights-Go v0.4.4
Expand Down Expand Up @@ -171,6 +172,7 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/seancfoley/ipaddress-go v1.6.0
github.com/sensu/sensu-go/api/core/v2 v2.16.0
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/shirou/gopsutil/v3 v3.24.4
github.com/showwin/speedtest-go v1.7.7
github.com/signalfx/golib/v3 v3.3.53
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matishsiao/goInfo v0.0.0-20210923090445-da2e3fa8d45f h1:B0OD7nYl2FPQEVrw8g2uyc1lGEzNbvrKh7fspGZcbvY=
github.com/matishsiao/goInfo v0.0.0-20210923090445-da2e3fa8d45f/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -2117,6 +2119,8 @@ github.com/seancfoley/ipaddress-go v1.6.0/go.mod h1:TQRZgv+9jdvzHmKoPGBMxyiaVmoI
github.com/sensu/sensu-go/api/core/v2 v2.16.0 h1:HOq4rFkQ1S5ZjxmMTLc5J5mAbECrnKWvtXXbMqr3j9s=
github.com/sensu/sensu-go/api/core/v2 v2.16.0/go.mod h1:MjM7+MCGEyTAgaZ589SiGHwYiaYF7N/58dU0J070u/0=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.24.4 h1:dEHgzZXt4LMNm+oYELpzl9YCqV65Yr/6SfrvgRBtXeU=
github.com/shirou/gopsutil/v3 v3.24.4/go.mod h1:lTd2mdiOspcqLgAnr9/nGi71NkeMpWKdmhuxm9GusH8=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
Expand Down
5 changes: 5 additions & 0 deletions plugins/outputs/all/vngcloud_vmonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !custom || outputs || outputs.vngcloud_vmonitor

package all

import _ "github.com/influxdata/telegraf/plugins/outputs/vngcloud_vmonitor" // register plugin
Loading

0 comments on commit 028068a

Please sign in to comment.