Skip to content
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

Adding a registry approche and some stuff #7

Merged
merged 15 commits into from
Oct 8, 2018
Merged
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
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

A promotheus module for Nest.
A prometheus module for Nest.

## Installation

Expand Down Expand Up @@ -30,7 +30,7 @@ import { PromModule } from '@digikare/nestjs-prom';
export class ApplicationModule {}
```

### Setup a counter metric
### Setup metric

In your module, use `forMetrics()` method to define the metrics needed.

Expand All @@ -47,14 +47,35 @@ import { PromModule, MetricType } from '@digikare/nest-prom';
name: 'my_counter',
help: 'my_counter a simple counter',
}
},
{
type: MetricType.Gauge,
configuration: {
name: 'my_gauge',
help: 'my_gauge a simple gauge',
}
},
{
type: MetricType.Histogram,
configuration: {
name: 'my_histogram',
help: 'my_histogram a simple histogram',
}
},
{
type: MetricType.Summary,
configuration: {
name: 'my_summary',
help: 'my_summary a simple summary',
}
}
]),
]
})
export class MyModule
```

And you can use `@InjectCounterMetric()` decorator
And you can use `@InjectCounterMetric()` decorator to get the metrics

```typescript
import { Injectable } from '@nestjs/common';
Expand All @@ -64,6 +85,9 @@ import { InjectCounterMetric, CounterMetric } from '@digikare/nest-prom';
export class MyService {
constructor(
@InjectCounterMetric('my_counter') private readonly _counterMetric: CounterMetric,
@InjectCounterMetric('my_gauge') private readonly _gaugeMetric: GaugeMetric,
@InjectCounterMetric('my_histogram') private readonly _histogramMetric: HistogramMetric,
@InjectCounterMetric('my_summary') private readonly _summaryMetric: SummaryMetric,
) {}

doStuff() {
Expand All @@ -76,12 +100,27 @@ export class MyService {
}
```

### /metrics
### Metric endpoint

At the moment, no way to configure the `/metrics` endpoint path.

At the moment, no way to configure the `/metrics` path.
PS: If you have a global prefix, the path will be `{globalPrefix}/metrics` for
the moment.

## API

### PromModule.forRoot() options

- `withDefaultsMetrics: boolean (default true)` enable defaultMetrics provided by prom-client
- `withDefaultController: boolean (default true)` add internal controller to expose /metrics endpoints
- `useHttpCounterMiddleware: boolean (default false)` register http_requests counter

## Auth/security

I do not provide any auth/security for `/metrics` endpoints.
This is not the aim of this module, but depending of the auth strategy, you can
apply a middleware on `/metrics` to secure it.

## TODO

- Update readme
Expand All @@ -91,6 +130,9 @@ the moment.
- Manage registries
- Tests
- Give possibility to custom metric endpoint
- Adding example on how to secure `/metrics` endpoint
- secret
- jwt

## License

Expand Down
4 changes: 4 additions & 0 deletions example/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
5 changes: 5 additions & 0 deletions example/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"language": "ts",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
6 changes: 6 additions & 0 deletions example/nodemon-debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --inspect-brk -r ts-node/register src/main.ts"
}
6 changes: 6 additions & 0 deletions example/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
Loading