diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 007b124..9e81a0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ - Review existing issues and provide feedback or react to them. - With pull requests: - - Open your pull request against `master` + - Open your pull request against `main` - Your pull request should have no more than two commits, if not you should squash them. - It should pass all tests in the available continuous integrations systems such as TravisCI. - You should add/modify tests to cover your proposed code changes. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..06f0312 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.16.0 + +ARG PENGUIN_VERSION=0.0.2 + +ENV GO111MODULE=on + +RUN mkdir -p /app/configs +RUN mkdir -p /app/var/logs +RUN apt-get update + +WORKDIR /app + +RUN curl -sL https://github.com/Clivern/Penguin/releases/download/v${PENGUIN_VERSION}/penguin_${PENGUIN_VERSION}_Linux_x86_64.tar.gz | tar xz +RUN rm LICENSE +RUN rm README.md + +COPY ./config.dist.yml /app/configs/ + +EXPOSE 8000 + +VOLUME /app/configs +VOLUME /app/var + +RUN ./penguin version + +CMD ["./penguin", "run", "-c", "/app/configs/config.dist.yml"] \ No newline at end of file diff --git a/README.md b/README.md index 8c92755..5c8aa45 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@

- - + +

@@ -32,7 +32,7 @@ inputs: http: enabled: on mode: prod - port: 8080 + port: 8000 tls: status: off pemPath: cert/server.pem @@ -42,7 +42,7 @@ inputs: # Log files to watch log: - enabled: on + enabled: off paths: - /app/logs/metrics_1.log - /app/logs/metrics_2.log @@ -50,7 +50,7 @@ inputs: # Metrics Cache Driver cache: type: memory - enabled: on + enabled: off drivers: memory: @@ -79,7 +79,6 @@ log: output: stdout # Format can be json format: json - ``` Run Penguin @@ -101,10 +100,10 @@ Send metrics to penguin HTTP endpoint ```bash curl -X POST \ -d '{"type":"counter","name":"penguin_orders","help":"the amount of orders.","method":"inc","value":1,"labels":{"type":"trousers"}}' \ - http://127.0.0.1:8080 + http://127.0.0.1:8000 ``` -Configure prometheus to scrape this URL `http://127.0.0.1:8080/metrics` +Configure prometheus to scrape this URL `http://127.0.0.1:8000/metrics` ## Versioning diff --git a/cmd/run.go b/cmd/run.go index c87ce7d..d6f96fa 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -125,14 +125,14 @@ var runCmd = &cobra.Command{ go controller.Daemon(messages) - // If http input not enabled - if !viper.GetBool("inputs.http.enabled") { + // If http input not enabled & log watcher enabled + if !viper.GetBool("inputs.http.enabled") && viper.GetBool("inputs.log.enabled") { controller.Watcher(messages) return + } else if viper.GetBool("inputs.log.enabled") { + go controller.Watcher(messages) } - go controller.Watcher(messages) - r := gin.Default() r.Use(middleware.Correlation()) diff --git a/config.dist.yml b/config.dist.yml index db4c708..d1c3de2 100644 --- a/config.dist.yml +++ b/config.dist.yml @@ -4,7 +4,7 @@ inputs: http: enabled: on mode: prod - port: 8080 + port: 8000 tls: status: off pemPath: cert/server.pem @@ -14,7 +14,7 @@ inputs: # Log files to watch log: - enabled: on + enabled: off paths: - /app/logs/metrics_1.log - /app/logs/metrics_2.log @@ -22,7 +22,7 @@ inputs: # Metrics Cache Driver cache: type: memory - enabled: on + enabled: off drivers: memory: @@ -47,7 +47,7 @@ output: log: # Log level, it can be debug, info, warn, error, panic, fatal level: info - # output can be stdout or abs path to log file /var/logs/beetle.log + # output can be stdout or abs path to log file /var/logs/penguin.log output: stdout # Format can be json format: json diff --git a/core/controller/watcher.go b/core/controller/watcher.go index 3eeea47..5aff347 100644 --- a/core/controller/watcher.go +++ b/core/controller/watcher.go @@ -6,6 +6,7 @@ package controller import ( "fmt" + "sync" "github.com/clivern/penguin/core/model" @@ -17,14 +18,16 @@ import ( // Watcher function func Watcher(messages chan<- string) { paths := viper.GetStringSlice("inputs.log.paths") + var wg sync.WaitGroup for _, path := range paths { log.WithFields(log.Fields{ "log_file": path, }).Info("Watch log file") + wg.Add(1) - go func(file string, channel chan<- string) { + go func(swg *sync.WaitGroup, file string, channel chan<- string) { t, err := tail.TailFile( file, tail.Config{Follow: true, ReOpen: true}, @@ -48,6 +51,10 @@ func Watcher(messages chan<- string) { channel <- message } - }(path, messages) + + defer swg.Done() + }(&wg, path, messages) } + + wg.Wait() } diff --git a/deployment/docker-compose/configs/config.yml b/deployment/docker-compose/configs/config.yml new file mode 100644 index 0000000..bc7102e --- /dev/null +++ b/deployment/docker-compose/configs/config.yml @@ -0,0 +1,53 @@ +# Metrics Input +inputs: + # HTTP endpoint for metrics collection + http: + enabled: on + mode: prod + port: 8080 + tls: + status: off + pemPath: cert/server.pem + keyPath: cert/server.key + path: / + api_key: "" + + # Log files to watch + log: + enabled: off + paths: + - /app/logs/metrics_1.log + - /app/logs/metrics_2.log + +# Metrics Cache Driver +cache: + type: memory + enabled: on + + drivers: + memory: + buffer_size: 10 + +# Metrics Output +output: + # Output metrics to console + console: + enabled: on + + # Expose to prometheus + prometheus: + enabled: on + endpoint: /metrics + + # TODO: Support Graphite + graphite: + enabled: off + +# Log configs +log: + # Log level, it can be debug, info, warn, error, panic, fatal + level: info + # output can be stdout or abs path to log file /var/logs/beetle.log + output: stdout + # Format can be json + format: json diff --git a/deployment/docker-compose/docker-compose.yml b/deployment/docker-compose/docker-compose.yml new file mode 100644 index 0000000..fe3a7c7 --- /dev/null +++ b/deployment/docker-compose/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3' + +services: + penguin: + image: 'clivern/penguin:release-v0.0.2' + ports: + - "8000:8000" + command: '/app/penguin run -c /app/configs/config.yml' + volumes: + - './configs/:/app/configs' + restart: unless-stopped