container stuff
This commit is contained in:
parent
2e10596783
commit
50587cbd1c
|
@ -0,0 +1,79 @@
|
|||
on: push
|
||||
name: CI
|
||||
jobs:
|
||||
npm-tests:
|
||||
env:
|
||||
CHROME_BIN: /usr/bin/chromium
|
||||
runs-on: [self-hosted]
|
||||
strategy:
|
||||
matrix:
|
||||
node: ['16']
|
||||
name: Node Tests
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
- run: npm install
|
||||
- name: test
|
||||
continue-on-error: true
|
||||
id: test
|
||||
run: npm test
|
||||
- name: retry
|
||||
continue-on-error: true
|
||||
id: retry1
|
||||
if: steps.test.outcome=='failure'
|
||||
run: npm test
|
||||
- name: set the status
|
||||
if: always()
|
||||
run: |
|
||||
if ${{ steps.test.outcome=='success' || steps.retry1.outcome=='success' }}; then
|
||||
echo "Tests Passed"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
docker-tests:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
- name: Docker test
|
||||
run: |
|
||||
wget https://github.com/tkp1n/chromium-ci/raw/41510dc154c4184f7e09461ba76f86f61c460070/seccomp/chromium.json
|
||||
docker build -t prom-act-test .
|
||||
docker run --security-opt seccomp=chromium.json --detach --name=prom-act-test prom-act-test
|
||||
until [ "`docker inspect -f {{.State.Health.Status}} prom-act-test`"=="healthy" ]; do
|
||||
sleep 1;
|
||||
echo "Waiting for container to be healthy"
|
||||
done;
|
||||
# Show usage
|
||||
docker exec prom-act-test wget -q -O- localhost:3000/metrics | grep act_fup
|
||||
# Check logs
|
||||
docker logs prom-act-test
|
||||
# Stop and kill the test container
|
||||
docker stop prom-act-test && docker rm prom-act-test && docker rmi prom-act-test
|
||||
publish:
|
||||
needs: [npm-tests, docker-tests]
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Push to GitHub Container Registry
|
||||
uses: docker/build-push-action@v2
|
||||
if: ${{github.ref_name != 'master'}}
|
||||
with:
|
||||
push: true
|
||||
tags: ghcr.io/${{ github.repository }}:${{github.ref_name}}
|
||||
- name: Push to GitHub Container Registry (latest)
|
||||
uses: docker/build-push-action@v2
|
||||
if: ${{github.ref_name == 'master'}}
|
||||
with:
|
||||
push: true
|
||||
tags: ghcr.io/${{ github.repository }}:latest
|
|
@ -1,18 +0,0 @@
|
|||
on: push
|
||||
name: Tests
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: [self-hosted]
|
||||
strategy:
|
||||
matrix:
|
||||
node: ['16']
|
||||
name: Node Tests
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
env:
|
||||
CHROME_BIN: /usr/bin/chromium
|
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
screenshots/
|
||||
screenshots/
|
||||
chromium.json
|
||||
|
|
36
Dockerfile
36
Dockerfile
|
@ -1,15 +1,43 @@
|
|||
FROM schliflo/docker-puppeteer:14.4.1
|
||||
FROM alpine
|
||||
|
||||
LABEL maintainer "Nemo <docker@captnemo.in>"
|
||||
|
||||
RUN apk add --no-cache \
|
||||
chromium \
|
||||
nss \
|
||||
freetype \
|
||||
harfbuzz \
|
||||
ca-certificates \
|
||||
ttf-freefont \
|
||||
nodejs \
|
||||
npm
|
||||
|
||||
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
||||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
|
||||
CHROME_BIN=/usr/bin/chromium-browser
|
||||
|
||||
# Add user so we don't need --no-sandbox.
|
||||
RUN addgroup -S pptruser && adduser -S -G pptruser pptruser \
|
||||
&& addgroup pptruser audio \
|
||||
&& addgroup pptruser video \
|
||||
&& mkdir -p /home/pptruser/Downloads /app \
|
||||
&& chown -R pptruser:pptruser /home/pptruser \
|
||||
&& chown -R pptruser:pptruser /app
|
||||
|
||||
USER pptruser
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json /app/
|
||||
COPY --chown=pptruser package.json package-lock.json /app/
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY index.js server.js prom.js *.md /app/
|
||||
COPY --chown=pptruser index.js server.js prom.js *.md /app/
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/node", "server.js"]
|
||||
ENTRYPOINT ["/usr/bin/node", "server.js"]
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
HEALTHCHECK --interval=1m --timeout=5s \
|
||||
CMD wget -q http://localhost:3000/ || exit 1
|
||||
|
|
34
README.md
34
README.md
|
@ -1,6 +1,6 @@
|
|||
# prometheus-act-exporter
|
||||
|
||||
![Docker Image Version (latest semver)](https://img.shields.io/docker/v/captn3m0/prometheus-act-exporter) ![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/captn3m0/prometheus-act-exporter) [![npm version](https://badge.fury.io/js/prometheus-act-exporter.svg)](https://badge.fury.io/js/prometheus-act-exporter) [![License: WTFPL](https://img.shields.io/badge/License-WTFPL-blue.svg)](http://www.wtfpl.net/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
|
||||
![Docker Image Version (latest semver)](https://img.shields.io/docker/v/captn3m0/prometheus-act-exporter) ![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/captn3m0/prometheus-act-exporter) [![npm version](https://badge.fury.io/js/prometheus-act-exporter.svg)](https://badge.fury.io/js/prometheus-act-exporter) [![License: WTFPL](https://img.shields.io/badge/License-WTFPL-blue.svg)](http://www.wtfpl.net/) [![CI](https://github.com/captn3m0/prometheus-act-exporter/actions/workflows/ci.yml/badge.svg)](https://github.com/captn3m0/prometheus-act-exporter/actions/workflows/ci.yml)
|
||||
|
||||
Exposes your current ACT FUP usage as prometheus metrics. Scrapes the data from the ACT Portal website by using [puppeteer](https://developers.google.com/web/tools/puppeteer/). This only supports [ACT Fibernet](https://www.actcorp.in/) in India.
|
||||
|
||||
|
@ -42,17 +42,7 @@ act_fup_aggregate_total_bytes 900000000
|
|||
|
||||
Install it with `npm i prometheus-act-exporter`.
|
||||
|
||||
```js
|
||||
const act = require("prometheus-act-exporter");
|
||||
let m = await act.getUsage();
|
||||
// Returns
|
||||
// {
|
||||
// live: { usedBytes: 0, totalBytes: 800000000 },
|
||||
// flexibytes: { usedBytes: 102580000, totalBytes: 100000000 },
|
||||
// aggregate: { usedBytes: 102580000, totalBytes: 900000000 }
|
||||
// }
|
||||
// calculations made assuming ACT is using SI GB (exactly 1 billion bytes)
|
||||
```
|
||||
See `test.js` for sample usage.
|
||||
|
||||
# Configuration
|
||||
|
||||
|
@ -68,20 +58,14 @@ You can pass the following environment variables:
|
|||
|
||||
If running via Docker, here are some simple cookbook configurations:
|
||||
|
||||
`docker run -it -p 3000:3000 -e captn3m0/prometheus-act-exporter`
|
||||
|
||||
Run a simple test server locally in debug mode and test it on `http://localhost:3000/metrics`
|
||||
|
||||
## Node
|
||||
|
||||
```sh
|
||||
export DISABLE_HEADLESS=1
|
||||
# Change to the correct invocation
|
||||
export CHROME_BIN=$(which chromium)
|
||||
npm install
|
||||
node server.js
|
||||
curl localhost:3000/metrics
|
||||
```
|
||||
wget https://github.com/tkp1n/chromium-ci/raw/41510dc154c4184f7e09461ba76f86f61c460070/seccomp/chromium.json
|
||||
docker run --security-opt seccomp=chromium.json -it -p 3000:3000 -e captn3m0/prometheus-act-exporter
|
||||
```
|
||||
|
||||
Note that the above uses a [minimal secure seccomp profile for running Chromium inside Docker](https://github.com/docker/for-linux/issues/496#issuecomment-441149510).
|
||||
|
||||
**Warning**: You should [not be running](https://ndportmann.com/chrome-in-docker/) this using `--privileged` or `--cap-add=SYS_ADMIN`, or `--no-sandbox`.
|
||||
|
||||
# LICENSE
|
||||
|
||||
|
|
6
index.js
6
index.js
|
@ -1,5 +1,4 @@
|
|||
const puppeteer = require("puppeteer-core");
|
||||
const containerized = require("containerized");
|
||||
|
||||
const MY_PACKAGE_SELECTOR_ID =
|
||||
'table[style="margin-top:-10px;"] tr:first-child+tr';
|
||||
|
@ -82,10 +81,7 @@ async function getUsage() {
|
|||
}
|
||||
|
||||
function chromeLaunchConfig() {
|
||||
let defaultArgs = [];
|
||||
if (containerized()) {
|
||||
defaultArgs = ["--no-sandbox", "--disable-setuid-sandbox"];
|
||||
}
|
||||
let defaultArgs = ['--disable-dev-shm-usage'];
|
||||
var options = {
|
||||
// These are set for Docker usage
|
||||
// https://github.com/alekzonder/docker-puppeteer#before-usage
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
"version": "3.1.2",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"containerized": "^1.0.2",
|
||||
"prom-client": "^14.0.1",
|
||||
"puppeteer-core": "^15.1.1"
|
||||
}
|
||||
|
@ -129,11 +128,6 @@
|
|||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
||||
},
|
||||
"node_modules/containerized": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/containerized/-/containerized-1.0.2.tgz",
|
||||
"integrity": "sha512-iSeP1Le1eRhwYIeBYHBw4rB9lYIwR1f9PsPweoItSDaB7B/6aLKgeU9Fomio/53nSni6YdSrGBjE+xwqrbzM3w=="
|
||||
},
|
||||
"node_modules/cross-fetch": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
|
||||
|
@ -720,11 +714,6 @@
|
|||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
||||
},
|
||||
"containerized": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/containerized/-/containerized-1.0.2.tgz",
|
||||
"integrity": "sha512-iSeP1Le1eRhwYIeBYHBw4rB9lYIwR1f9PsPweoItSDaB7B/6aLKgeU9Fomio/53nSni6YdSrGBjE+xwqrbzM3w=="
|
||||
},
|
||||
"cross-fetch": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
|
||||
|
|
|
@ -14,15 +14,14 @@
|
|||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@git.captnemo.in/nemo/prometheus-act-exporter.git"
|
||||
"url": "git+ssh://github.com/captn3m0/prometheus-act-exporter.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://git.captnemo.in/nemo/prometheus-act-exporter/issues"
|
||||
"url": "https://github.com/captn3m0/prometheus-act-exporter/issues"
|
||||
},
|
||||
"author": "Nemo <npm@captnemo.in>",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"containerized": "^1.0.2",
|
||||
"prom-client": "^14.0.1",
|
||||
"puppeteer-core": "^15.1.1"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue