Skip to content

St monitoring 5 #3

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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
node_modules
spm*
.env
sample-github.js
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ COPY . .
EXPOSE 3000

# Start Node server
CMD [ "npm", "start" ]
CMD [ "npm", "run", "server" ]
57 changes: 54 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
// Load env vars
require('dotenv').config()
// require stMonitor agent
// const { stMonitor, stLogger } = require('sematext-agent-express')
// Start monitoring metrics
// stMonitor.start()

const express = require('express')
const app = express()
app.get('/', async (req, res, next) => {
res.status(200).send('Hello World!')

const err = new Error('this broke')

const errStack = `TypeError: Cannot create property 'Symbol(level)' on string 'Tick Tock'
at DerivedLogger.log (/home/raha/code/express-docker-app/node_modules/winston/lib/winston/logger.js:208:20)
at Timeout.setInterval [as _onTimeout] (/home/raha/code/express-docker-app/app.js:11:28)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)`

setInterval(() => {
console.info(`
Tick Tock
LOGS_ENABLED_DEFAULT=true
LOGS_ENABLED=true/false
`)
}, 3000)

app.get('/', (req, res, next) => {
// stLogger.info('Hello World.')
// stLogger.debug('Hello debug.')
// stLogger.warn('Some warning.')
// stLogger.error(err)
// throw err
console.log('inside /')
res.status(200).send('Hello World.')
})
app.listen(3000, () => console.log('Server is running on port 3000'))

app.get('/err', (req, res, next) => {
// stLogger.info('Hello World.')
// stLogger.debug('Hello debug.')
// stLogger.warn('Some warning.')
// stLogger.error(err)
// console.dir(err)
throw err
// res.status(200).send('Hello World.')
})

function errorHandler (err, req, res, next) {
console.error(err)
console.log('inside errorHandler')
res.status(err.status || 500).send(err.message)
}

app.use(errorHandler)

module.exports = app
15 changes: 15 additions & 0 deletions cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const cluster = require('cluster')
const numCPUs = require('os').cpus().length
const app = require('./app')
const port = process.env.PORT || 3000

const masterProcess = () => Array.from(Array(numCPUs)).map(cluster.fork)
const childProcess = () => app.listen(port)

if (cluster.isMaster) {
masterProcess()
} else {
childProcess()
}

cluster.on('exit', () => cluster.fork())
49 changes: 45 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
version: "3"
services:
app:
app-1:
build:
context: ./
dockerfile: Dockerfile
image: adnanrahic/express-docker-app
image: express-docker-app:test-1
environment:
- LOGS_ENABLED=false
deploy:
mode: replicated
replicas: 6
replicas: 1
labels: [APP=APP]
update_config:
parallelism: 1
Expand All @@ -16,4 +18,43 @@ services:
condition: on-failure
delay: 5s
ports:
- "80:3000"
- "80:3000"

app-2:
build:
context: ./
dockerfile: Dockerfile
image: express-docker-app:test-1
environment:
- LOGS_ENABLED=true
deploy:
mode: replicated
replicas: 1
labels: [APP=APP]
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
delay: 5s
ports:
- "8080:3000"

st-logagent:
# build:
# context: ../sematext/logagent-js/
# dockerfile: Dockerfile
image: 'sematext/logagent:dev'
environment:
- LOGS_ENABLED_DEFAULT=true
- LOGS_TOKEN=5905c3e9-889c-4064-bf04-8e140963c880
- LOGS_RECEIVER_URL=https://logs-token-receiver.apps.test.sematext.com
- EVENTS_RECEIVER_URL=https://event-receiver.apps.test.sematext.com
deploy:
mode: global
cap_add:
- SYS_ADMIN
restart: always
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'

Loading