Skip to content

Commit 2ea9af8

Browse files
authored
Merge pull request #3 from chatwork/status-endpoint
Parse command line arguments
2 parents 526c964 + 07104dd commit 2ea9af8

File tree

12 files changed

+204
-120
lines changed

12 files changed

+204
-120
lines changed

.circleci/config.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ orbs:
55
# https://circleci.com/developer/orbs/orb/circleci/go
66
go: circleci/[email protected]
77

8+
executors:
9+
docker_executor:
10+
docker:
11+
- image: chatwork/circleci-docker:18.09.3
12+
working_directory: /root/project
13+
814
workflows:
915
version: 2
1016
main:
@@ -13,6 +19,14 @@ workflows:
1319
filters:
1420
tags:
1521
only: /.*/
22+
- docker_build_and_bush:
23+
context: "DockerHub"
24+
filters:
25+
tags:
26+
only: /^.*/
27+
branches:
28+
ignore:
29+
- /^.*/
1630

1731
jobs:
1832
go_build:
@@ -22,4 +36,17 @@ jobs:
2236
steps:
2337
- checkout
2438
- go/mod-download-cached
25-
- run: make
39+
- run: make
40+
41+
docker_build_and_bush:
42+
executor: docker_executor
43+
environment:
44+
- CIRCLECI_WORKSPACE: /root/project
45+
steps:
46+
- checkout
47+
- setup_remote_docker:
48+
docker_layer_caching: true
49+
version: 18.09.3
50+
- run: docker login -u="${DOCKER_REGISTRY_USERNAME}" -p="${DOCKER_REGISTRY_PASSWORD}"
51+
- run: make build-image
52+
- run: make push-image

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exporter
1+
dist
22

33
.env
44

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ RUN apk --no-cache add ca-certificates \
1414
&& adduser -S -G exporter exporter
1515
USER exporter
1616
COPY --from=build /bin/exporter /bin/exporter
17-
ENV LISTEN_PORT=2112
18-
EXPOSE 2112
17+
1918
ENTRYPOINT [ "/bin/exporter" ]

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
USER := ada-u
2+
REPO := sendgrid-stats-exporter
3+
GIT_TAG := $(shell git tag --points-at HEAD)
4+
GIT_HASH := $(shell git rev-parse HEAD)
5+
VERSION := $(shell if [ -n "$(GIT_TAG)" ]; then echo "$(GIT_TAG)"; else echo "$(GIT_HASH)"; fi)
6+
7+
DIST_DIR := $(shell if [ -n "$(GOOS)$(GOARCH)" ]; then echo "./dist/$(GOOS)-$(GOARCH)"; else echo "./dist"; fi)
8+
19
default: build
210

311
.PHONY: build
412
build:
5-
go build -o exporter .
13+
@echo "version: $(VERSION) hash: $(GIT_HASH) tag: $(GIT_TAG)"
14+
go build -ldflags "-s -w -X main.version=$(VERSION) -X main.gitCommit=$(GIT_HASH)" -o $(DIST_DIR)/exporter .
15+
16+
.PHONY: build-image
17+
build-image:
18+
docker build -t chatwork/"$(REPO)" .
19+
docker tag chatwork/"$(REPO)":latest chatwork/"$(REPO)":"$(VERSION)"
20+
21+
.PHONY: push-image
22+
push-image:
23+
docker push chatwork/"$(REPO)"

README.md

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,60 @@
1111

1212
## Usage
1313

14+
```
15+
$ make
16+
$ ./exporter --sendgrid.api-key='secret' --web.listen-address=':9154' --web.disable-exporter-metrics
17+
```
18+
19+
```
20+
$ curl localhost:9154/-/healthy
21+
$ curl localhost:9154/metrics
22+
```
23+
24+
```
25+
$ ./exporter -h
26+
usage: exporter [<flags>]
27+
28+
Flags:
29+
-h, --help Show context-sensitive help (also try --help-long and --help-man).
30+
--web.listen-address=":9154"
31+
Address to listen on for web interface and telemetry.
32+
--web.disable-exporter-metrics
33+
Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).
34+
--sendgrid.username="" Set SendGrid username
35+
--sendgrid.api-key="secret"
36+
Set SendGrid API key
37+
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
38+
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
39+
--version Show application version.
40+
```
41+
42+
## Endpoints
43+
44+
Name | Description
45+
---------|-------------
46+
`/metrics` | get metrics
47+
`/-/healthy` | for health check
48+
49+
## Metrics
50+
51+
Name | Description
52+
---------|------------
53+
blocks | dummy
54+
bounce_drops | dummy
55+
bounces | dummy
56+
deferred | dummy
57+
delivered | dummy
58+
invalid_emails | dummy
59+
processed | dummy
60+
requests | dummy
61+
spam_report_drops | dummy
62+
spam_reports | dummy
63+
unique_clicks | dummy
64+
unique_opens | dummy
65+
unsubscribe_drops | dummy
66+
unsubscribes | dummy
67+
1468
### Running with Docker
1569

1670
(TBW)
@@ -40,46 +94,3 @@ $ make
4094
```
4195
$ docker build -t sendgrid-stats-exporter .
4296
```
43-
44-
## Configuration
45-
46-
### Exporter
47-
48-
You can specify a user name as environment variable to identify metrics for multiple users, as well as categories.
49-
50-
Name | Description | Default
51-
---------|-------------|----
52-
`SENDGRID_API_KEY` | API key for calling stats API (v3) | `""`
53-
`SENDGRID_USER_NAME` | (Optional) Label for metrics | `""`
54-
`SENDGRID_CATEGORY` | (not implemented) | `""`
55-
56-
### Prometheus
57-
58-
Example:
59-
60-
```yaml
61-
scrape_configs:
62-
- job_name: 'sendgrid'
63-
static_configs:
64-
- targets:
65-
- https://sendgrid-stats-exporter.example.com:2112
66-
```
67-
68-
## Metrics
69-
70-
Name | Description
71-
---------|------------
72-
blocks | dummy
73-
bounce_drops | dummy
74-
bounces | dummy
75-
deferred | dummy
76-
delivered | dummy
77-
invalid_emails | dummy
78-
processed | dummy
79-
requests | dummy
80-
spam_report_drops | dummy
81-
spam_reports | dummy
82-
unique_clicks | dummy
83-
unique_opens | dummy
84-
unsubscribe_drops | dummy
85-
unsubscribes | dummy

0 commit comments

Comments
 (0)