Skip to content

Commit

Permalink
Merge pull request #1 from groove-x/feature/support-rss
Browse files Browse the repository at this point in the history
add memory_rss
  • Loading branch information
atotto authored Mar 18, 2020
2 parents 638a47b + cf38dc1 commit ed8b083
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ container_cpu_user_seconds_total{id="/system.slice/docker.service"} 2219.16
container_cpu_user_seconds_total{id="/system.slice/NetworkManager.service"} 4283.36
:
# HELP container_memory_usage_bytes Current memory usage in bytes.
# HELP container_memory_usage_bytes Current memory usage in bytes, including all memory regardless of when it was accessed
# TYPE container_memory_usage_bytes gauge
container_memory_usage_bytes{id="/system.slice/wpa_supplicant.service"} 1871872
container_memory_usage_bytes{id="/system.slice/ssh.service"} 61440
container_memory_usage_bytes{id="/system.slice/docker.service"} 37171200
container_memory_usage_bytes{id="/system.slice/NetworkManager.service"} 18305024
:
# HELP container_memory_rss Size of RSS in bytes.
# TYPE container_memory_rss gauge
container_memory_rss{id="/system.slice/wpa_supplicant.service"} 331776
container_memory_rss{id="/system.slice/ssh.service"} 110592
container_memory_rss{id="/system.slice/docker.service"} 24072192
container_memory_rss{id="/system.slice/NetworkManager.service"} 5066752
:
```
2 changes: 1 addition & 1 deletion deb.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prometheus-cgroup-exporter",
"version": "0.1.1",
"version": "0.1.2",
"maintainer": "GROOVE X Development Team <[email protected]>",
"description": "prometheus cgroup exporter",
"changelog-cmd": "git log --pretty='format:%cd %h %s %d [%an]' --date=iso --merges",
Expand Down
35 changes: 17 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ func main() {
}
}

var (
cpuUserTotalHeader = `# HELP container_cpu_user_seconds_total Cumulative user cpu time consumed in seconds.
# TYPE container_cpu_user_seconds_total counter
`
cpuUserTotalFormat = `container_cpu_user_seconds_total{id=%s} %.2f
`

memoryUsageHeader = `# HELP container_memory_usage_bytes Current memory usage in bytes.
# TYPE container_memory_usage_bytes gauge
`
memoryUsageFormat = `container_memory_usage_bytes{id=%s} %d
`
)

func subsystem() ([]cgroups.Subsystem, error) {
root := "/sys/fs/cgroup"
s := []cgroups.Subsystem{
Expand Down Expand Up @@ -114,14 +100,27 @@ func exportMetrics(system cgroups.Cgroup) func(w http.ResponseWriter, r *http.Re
groups[name] = stats
}

fmt.Fprint(w, cpuUserTotalHeader)
fmt.Fprintln(w, `# HELP container_cpu_user_seconds_total Cumulative user cpu time consumed in seconds.
# TYPE container_cpu_user_seconds_total counter`)
for name, stats := range groups {
fmt.Fprintf(w, `container_cpu_user_seconds_total{id=%s} %.2f`, strconv.Quote(name), float64(stats.CPU.Usage.User)/1000000000.0)
fmt.Fprintln(w)
}

fmt.Fprintln(w, `# HELP container_memory_usage_bytes Current memory usage in bytes, including all memory regardless of when it was accessed
# TYPE container_memory_usage_bytes gauge`)
for name, stats := range groups {
fmt.Fprintf(w, cpuUserTotalFormat, strconv.Quote(name), float64(stats.CPU.Usage.User)/1000000000.0)
fmt.Fprintf(w, `container_memory_usage_bytes{id=%s} %d`, strconv.Quote(name), stats.Memory.Usage.Usage)
fmt.Fprintln(w)
}
fmt.Fprint(w, memoryUsageHeader)

fmt.Fprintln(w, `# HELP container_memory_rss Size of RSS in bytes.
# TYPE container_memory_rss gauge`)
for name, stats := range groups {
fmt.Fprintf(w, memoryUsageFormat, strconv.Quote(name), stats.Memory.Usage.Usage)
fmt.Fprintf(w, `container_memory_rss{id=%s} %d`, strconv.Quote(name), stats.Memory.RSS)
fmt.Fprintln(w)
}

return
}
}

0 comments on commit ed8b083

Please sign in to comment.