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

[wip] feat: add more metrics #46

Closed
wants to merge 7 commits into from
Closed
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
6 changes: 1 addition & 5 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,4 @@ rules:
line-length: disable
truthy:
ignore: |
.github/workflows/codeql-analysis.yml
.github/workflows/funcbench.yml
.github/workflows/fuzzing.yml
.github/workflows/prombench.yml
.github/workflows/golangci-lint.yml
.github/workflows/*.yml
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.2.0 / 2022-08-02

* [BUGFIX] Fix CPU usage metrics #37

## 0.1.1 / 2022-02-03

* [FEATURE] Expose memory cache metric #25
* [ENHANCEMENT] Allow ecsmetadata to work outside of ECS #18

## 0.1.0 / 2021-09-21

* [FEATURE] Initial release.
9 changes: 6 additions & 3 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,22 @@ ifneq ($(shell which gotestsum),)
endif
endif

PROMU_VERSION ?= 0.13.0
PROMU_VERSION ?= 0.14.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz

SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.45.2
GOLANGCI_LINT_VERSION ?= v1.50.1
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
# If we're in CI and there is an Actions file, that means the linter
# is being run in Actions, so we don't need to run it here.
ifeq (,$(CIRCLE_JOB))
ifneq (,$(SKIP_GOLANGCI_LINT))
GOLANGCI_LINT :=
else ifeq (,$(CIRCLE_JOB))
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ECS task infra metrics in Prometheus format.
Run the following container as a sidecar on ECS tasks:

```
quay.io/prometheuscommunity/ecs-exporter:v0.1.1
quay.io/prometheuscommunity/ecs-exporter:latest
```

An example Fargate task definition that includes the container
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.2.0
45 changes: 45 additions & 0 deletions ecscollector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ import (
const nanoSeconds = 1.0e9

var (
metadataDesc = prometheus.NewDesc(
"ecs_metadata",
"ECS service metadata.",
nil, nil)

svcCpuLimitDesc = prometheus.NewDesc(
"ecs_svc_cpu_limit",
"Total CPU Limit.",
nil, nil)

svcMemLimitDesc = prometheus.NewDesc(
"ecs_svc_cpu_limit",
"Total CPU Limit.",
nil, nil)

cpuTotalDesc = prometheus.NewDesc(
"ecs_cpu_seconds_total",
"Total CPU usage in seconds.",
Expand Down Expand Up @@ -142,11 +157,41 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
log.Printf("Failed to retrieve metadata: %v", err)
return
}

ch <- prometheus.MustNewConstMetric(
metadataDesc,
prometheus.GaugeValue,
1.0,
metadata.Cluster,
metadata.TaskARN,
metadata.Family,
metadata.Revision,
metadata.DesiredStatus,
metadata.KnownStatus,
metadata.PullStartedAt,
metadata.PullStoppedAt,
metadata.AvailabilityZone,
metadata.LaunchType,
)

ch <- prometheus.MustNewConstMetric(
svcCpuLimitDesc,
prometheus.GaugeValue,
float64(metadata.Limits.CPU),
)

ch <- prometheus.MustNewConstMetric(
svcMemLimitDesc,
prometheus.GaugeValue,
float64(metadata.Limits.CPU),
)

stats, err := c.client.RetrieveTaskStats(ctx)
if err != nil {
log.Printf("Failed to retrieve container stats: %v", err)
return
}

for _, container := range metadata.Containers {
s := stats[container.DockerID]
if s == nil {
Expand Down
67 changes: 54 additions & 13 deletions ecsmetadata/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ type ContainerStats struct {
Name string `json:"name"`
ID string `json:"id"`
NumProcs float64 `json:"num_procs"`
Read string `json:"read"`
PreRead string `json:"preread"`

CPUStats dockertypes.CPUStats
PreCPUStats dockertypes.CPUStats
MemoryStats dockertypes.MemoryStats
PidsStats []struct{} `json:"pids_stats"`
StorageStats []struct{} `json:"storage_stats"`

CPUStats dockertypes.CPUStats `json:"cpu_stats"`
PreCPUStats dockertypes.CPUStats `json:"precpu_stats"`
MemoryStats dockertypes.MemoryStats `json:"memory_stats"`
BlkioStats dockertypes.BlkioStats `json:"blkio_stats"`

Networks map[string]struct {
RxBytes float64 `json:"rx_bytes"`
Expand All @@ -115,15 +121,19 @@ type ContainerStats struct {
} `json:"network_rate_stats"`
}

// TODO(jbd): Add storage stats.

type TaskMetadata struct {
Cluster string `json:"Cluster"`
TaskARN string `json:"TaskARN"`
Family string `json:"Family"`
Revision string `json:"Revision"`
DesiredStatus string `json:"DesiredStatus"`
KnownStatus string `json:"KnownStatus"`
Cluster string `json:"Cluster"`
TaskARN string `json:"TaskARN"`
Family string `json:"Family"`
Revision string `json:"Revision"`
DesiredStatus string `json:"DesiredStatus"`
KnownStatus string `json:"KnownStatus"`
Limits []struct {
CPU float64 `json:"CPU"`
Memory float64 `json:"Memory"`
} `json:"Limits"`
PullStartedAt string `json:"PullStartedAt"`
PullStoppedAt string `json:"PullStoppedAt"`
AvailabilityZone string `json:"AvailabilityZone"`
LaunchType string `json:"LaunchType"`
Containers []struct {
Expand All @@ -135,7 +145,38 @@ type TaskMetadata struct {
Labels map[string]string `json:"Labels"`
DesiredStatus string `json:"DesiredStatus"`
KnownStatus string `json:"KnownStatus"`
Type string `json:"Type"`
ContainerARN string `json:"ContainerARN"`
Limits []struct {
CPU float64 `json:"CPU"`
Memory float64 `json:"Memory"`
} `json:"Limits"`
CreatedAt string `json:"CreatedAt"`
StartedAt string `json:"StartedAt"`
Type string `json:"Type"`
Networks []struct {
NetworkMore string `json:"NetworkMode"`
IPv4Addresses []string `json:"IPv4Addresses"`
IPv6Addresses []string `json:"IPv6Addresses"`
AttachmentIndex float64 `json:"AttachmentIndex"`
MACAddress string `json:"MACAddress"`
IPv4SubnetCIDRBlock string `json:"IPv4SubnetCIDRBlock"`
IPv6SubnetCIDRBlock string `json:"IPv6SubnetCIDRBlock"`
DomainNameServers []string `json:"DomainNameServers"`
DomainNameSearchList []string `json:"DomainNameSearchList"`
PrivateDNSName string `json:"PrivateDNSName"`
SubnetGatewayIpv4Address string `json:"SubnetGatewayIpv4Address"`
} `json:"Networks"`
ClockDrift []struct {
ClockErrorBound float64 `json:"ClockErrorBound"`
ReferenceTimestamp string `json:"ReferenceTimestamp"`
ClockSynchronizationStatus string `json:"ClockSynchronizationStatus"`
} `json:"ClockDrift"`
ContainerARN string `json:"ContainerARN"`
LogOptions []struct {
AwslogsCreateGroup string `json:"awslogs-create-group"`
AwslogsGroup string `json:"awslogs-group"`
AwslogsRegion string `json:"awslogs-region"`
AwslogsStream string `json:"awslogs-stream"`
} `json:"LogOptions"`
LogDriver string `json:"LogDriver"`
} `json:"Containers"`
}
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/prometheus-community/ecs_exporter
go 1.17

require (
github.com/docker/docker v20.10.17+incompatible
github.com/prometheus/client_golang v1.12.2
github.com/docker/docker v20.10.23+incompatible
github.com/prometheus/client_golang v1.14.0
)

require (
Expand All @@ -17,10 +17,10 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
google.golang.org/protobuf v1.26.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
google.golang.org/protobuf v1.28.1 // indirect
gotest.tools/v3 v3.3.0 // indirect
)
Loading