From 128a41dd5638a8624b232769e1fbca4531f92f38 Mon Sep 17 00:00:00 2001 From: Alexei Guevara Date: Mon, 11 Sep 2017 14:18:17 -0400 Subject: [PATCH] export Job.Type as label 'job_type' --- README.md | 14 +++++++------- nomad-exporter.go | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3704ed4..c1dc8a2 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ | nomad_serf_lan_members | How many members are in the cluster | | | nomad_jobs | How many jobs are in the cluster | | | nomad_allocations | How many allocations are in the cluster | | -| nomad_allocation_cpu | How much CPU allocation is consuming | job, group, alloc, region, datacenter, node | -| nomad_allocation_cpu_throttle | How much allocation CPU is throttled | job, group, alloc, region, datacenter, node| -| nomad_allocation_memory | How much memory allocation is consuming | job, group, alloc, region, datacenter, node | -| nomad_allocation_memory_limit | Allocation memory limit | job, group, alloc, region, datacenter, node | -| nomad_task_cpu_total_ticks | Task CPU total ticks | job, group, alloc, task, region, datacenter, node | -| nomad_task_cpu_percent | Task CPU usage, percent | job, group, alloc, task, region, datacenter, node | -| nomad_task_memory_rss_bytes | Task memory RSS usage, bytes | job, group, alloc, task, region, datacenter, node | +| nomad_allocation_cpu | How much CPU allocation is consuming | job, job_type, group, alloc, region, datacenter, node | +| nomad_allocation_cpu_throttle | How much allocation CPU is throttled | job, job_type, group, alloc, region, datacenter, node| +| nomad_allocation_memory | How much memory allocation is consuming | job, job_type, group, alloc, region, datacenter, node | +| nomad_allocation_memory_limit | Allocation memory limit | job, job_type, group, alloc, region, datacenter, node | +| nomad_task_cpu_total_ticks | Task CPU total ticks | job, job_type, group, alloc, task, region, datacenter, node | +| nomad_task_cpu_percent | Task CPU usage, percent | job, job_type, group, alloc, task, region, datacenter, node | +| nomad_task_memory_rss_bytes | Task memory RSS usage, bytes | job, job_type, group, alloc, task, region, datacenter, node | | nomad_node_resource_memory_megabytes | Amount of allocatable memory the node has in MB | node, datacenter | | nomad_node_allocated_memory_megabytes | Amount of memory allocated to tasks on the node in MB | node, datacenter | | nomad_node_used_memory_megabytes | Amount of memory used on the node in MB | node, datacenter | diff --git a/nomad-exporter.go b/nomad-exporter.go index 3d63c29..0ce69ab 100644 --- a/nomad-exporter.go +++ b/nomad-exporter.go @@ -55,37 +55,37 @@ var ( allocationMemory = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "allocation_memory"), "Allocation memory usage", - []string{"job", "group", "alloc", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "region", "datacenter", "node"}, nil, ) allocationMemoryLimit = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "allocation_memory_limit"), "Allocation memory limit", - []string{"job", "group", "alloc", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "region", "datacenter", "node"}, nil, ) allocationCPU = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "allocation_cpu"), "Allocation CPU usage", - []string{"job", "group", "alloc", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "region", "datacenter", "node"}, nil, ) allocationCPUThrottled = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "allocation_cpu_throttle"), "Allocation throttled CPU", - []string{"job", "group", "alloc", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "region", "datacenter", "node"}, nil, ) taskCPUTotalTicks = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "task_cpu_total_ticks"), "Task CPU total ticks", - []string{"job", "group", "alloc", "task", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "task", "region", "datacenter", "node"}, nil, ) taskCPUPercent = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "task_cpu_percent"), "Task CPU usage, percent", - []string{"job", "group", "alloc", "task", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "task", "region", "datacenter", "node"}, nil, ) taskMemoryRssBytes = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "task_memory_rss_bytes"), "Task memory RSS usage, bytes", - []string{"job", "group", "alloc", "task", "region", "datacenter", "node"}, nil, + []string{"job", "job_type", "group", "alloc", "task", "region", "datacenter", "node"}, nil, ) nodeResourceMemory = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "node_resource_memory_megabytes"), @@ -243,26 +243,26 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { } for taskName, taskStats := range stats.Tasks { ch <- prometheus.MustNewConstMetric( - taskCPUPercent, prometheus.GaugeValue, taskStats.ResourceUsage.CpuStats.Percent, alloc.Job.Name, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, + taskCPUPercent, prometheus.GaugeValue, taskStats.ResourceUsage.CpuStats.Percent, alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, ) ch <- prometheus.MustNewConstMetric( - taskCPUTotalTicks, prometheus.GaugeValue, taskStats.ResourceUsage.CpuStats.TotalTicks, alloc.Job.Name, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, + taskCPUTotalTicks, prometheus.GaugeValue, taskStats.ResourceUsage.CpuStats.TotalTicks, alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, ) ch <- prometheus.MustNewConstMetric( - taskMemoryRssBytes, prometheus.GaugeValue, float64(taskStats.ResourceUsage.MemoryStats.RSS), alloc.Job.Name, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, + taskMemoryRssBytes, prometheus.GaugeValue, float64(taskStats.ResourceUsage.MemoryStats.RSS), alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, taskName, alloc.Job.Region, node.Datacenter, node.Name, ) } ch <- prometheus.MustNewConstMetric( - allocationCPU, prometheus.GaugeValue, stats.ResourceUsage.CpuStats.Percent, alloc.Job.Name, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, + allocationCPU, prometheus.GaugeValue, stats.ResourceUsage.CpuStats.Percent, alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, ) ch <- prometheus.MustNewConstMetric( - allocationCPUThrottled, prometheus.GaugeValue, float64(stats.ResourceUsage.CpuStats.ThrottledTime), alloc.Job.Name, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, + allocationCPUThrottled, prometheus.GaugeValue, float64(stats.ResourceUsage.CpuStats.ThrottledTime), alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, ) ch <- prometheus.MustNewConstMetric( - allocationMemory, prometheus.GaugeValue, float64(stats.ResourceUsage.MemoryStats.RSS), alloc.Job.Name, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, + allocationMemory, prometheus.GaugeValue, float64(stats.ResourceUsage.MemoryStats.RSS), alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, ) ch <- prometheus.MustNewConstMetric( - allocationMemoryLimit, prometheus.GaugeValue, float64(alloc.Resources.MemoryMB), alloc.Job.Name, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, + allocationMemoryLimit, prometheus.GaugeValue, float64(alloc.Resources.MemoryMB), alloc.Job.Name, alloc.Job.Type, alloc.TaskGroup, alloc.Name, alloc.Job.Region, node.Datacenter, node.Name, ) }(a) }