mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
Fix profiler path (#339)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -39,7 +39,8 @@ RUN apk --update --no-cache add \
|
||||
COPY --from=build /usr/local/bin/diun /usr/local/bin/diun
|
||||
RUN diun --version
|
||||
|
||||
ENV DIUN_DB_PATH="/data/diun.db"
|
||||
ENV PROFILER_PATH="/profiler" \
|
||||
DIUN_DB_PATH="/data/diun.db"
|
||||
|
||||
VOLUME [ "/data" ]
|
||||
VOLUME [ "/data", "/profiler" ]
|
||||
ENTRYPOINT [ "diun" ]
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -77,8 +78,12 @@ func main() {
|
||||
log.Debug().Msg(cfg.String())
|
||||
|
||||
// Profiler
|
||||
if len(cli.Profiler) > 0 {
|
||||
profilePath := profile.ProfilePath(cfg.Db.Path)
|
||||
if len(cli.Profiler) > 0 && len(cli.ProfilerPath) > 0 {
|
||||
profilerPath := path.Clean(cli.ProfilerPath)
|
||||
if err = os.MkdirAll(profilerPath, os.ModePerm); err != nil {
|
||||
log.Fatal().Err(err).Msg("Cannot create profiler folder")
|
||||
}
|
||||
profilePath := profile.ProfilePath(profilerPath)
|
||||
switch cli.Profiler {
|
||||
case "cpu":
|
||||
defer profile.Start(profile.CPUProfile, profilePath).Stop()
|
||||
|
||||
34
docs/faq.md
34
docs/faq.md
@@ -121,3 +121,37 @@ regopts:
|
||||
```
|
||||
|
||||
Or you can tweak the [`schedule` setting](config/watch.md#schedule) with something like `0 */6 * * *` (every 6 hours).
|
||||
|
||||
## Profiling
|
||||
|
||||
Diun provides a simple way to manage runtime/pprof profiling through [`--profiler-path` and `--profiler` flags](usage/cli.md#options):
|
||||
|
||||
```yaml
|
||||
version: "3.5"
|
||||
|
||||
services:
|
||||
diun:
|
||||
image: crazymax/diun:latest
|
||||
volumes:
|
||||
- "./data:/data"
|
||||
- "./profiler:/profiler"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
environment:
|
||||
- "TZ=Europe/Paris"
|
||||
- "LOG_LEVEL=info"
|
||||
- "PROFILER_PATH=/profiler"
|
||||
- "PROFILER=mem"
|
||||
- "DIUN_PROVIDERS_DOCKER=true"
|
||||
restart: always
|
||||
```
|
||||
|
||||
Following profilers are available:
|
||||
|
||||
* `cpu` enables cpu profiling
|
||||
* `mem` enables memory profiling
|
||||
* `alloc` enables memory profiling and changes which type of memory to profile allocations
|
||||
* `heap` enables memory profiling and changes which type of memory profiling to profile the heap
|
||||
* `routines` enables goroutine profiling
|
||||
* `mutex` enables mutex profiling
|
||||
* `threads` enables thread creation profiling
|
||||
* `block` enables block (contention) profiling
|
||||
|
||||
@@ -18,6 +18,8 @@ Flags:
|
||||
-h, --help Show context-sensitive help.
|
||||
--version
|
||||
--config=STRING Diun configuration file ($CONFIG).
|
||||
--profiler-path=STRING Base path where profiling files are written
|
||||
($PROFILER_PATH).
|
||||
--profiler=STRING Profiler to use ($PROFILER).
|
||||
--log-level="info" Set log level ($LOG_LEVEL).
|
||||
--log-json Enable JSON logging output ($LOG_JSON).
|
||||
@@ -34,7 +36,8 @@ Following environment variables can be used in place:
|
||||
| Name | Default | Description |
|
||||
|--------------------|---------------|---------------|
|
||||
| `CONFIG` | | Diun configuration file |
|
||||
| `PROFILER` | | Profiler to use |
|
||||
| `PROFILER_PATH` | | Base path where profiling files are written |
|
||||
| `PROFILER` | | [Profiler](../faq.md#profiling) to use |
|
||||
| `LOG_LEVEL` | `info` | Log level output |
|
||||
| `LOG_JSON` | `false` | Enable JSON logging output |
|
||||
| `LOG_CALLER` | `false` | Enable to add `file:line` of the caller |
|
||||
|
||||
@@ -6,6 +6,7 @@ import "github.com/alecthomas/kong"
|
||||
type Cli struct {
|
||||
Version kong.VersionFlag
|
||||
Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"`
|
||||
ProfilerPath string `kong:"name='profiler-path',env='PROFILER_PATH',help='Base path where profiling files are written.'"`
|
||||
Profiler string `kong:"name='profiler',env='PROFILER',enum='cpu,mem,alloc,heap,routines,mutex,threads,block',help='Profiler to use.'"`
|
||||
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
|
||||
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
|
||||
|
||||
Reference in New Issue
Block a user