diff --git a/README.md b/README.md index 197a70b..429df23 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ Usage of ./kafka_connect_exporter: # HELP kafka_connect_connector_state_running is the connector running? # TYPE kafka_connect_connector_state_running gauge kafka_connect_connector_state_running{connector="test-changesets",state="running",worker="kafka-connect:8083"} 1 -# HELP kafka_connect_connector_tasks_state_running are connector tasks running? -# TYPE kafka_connect_connector_tasks_state_running gauge -kafka_connect_connector_tasks_state_running{connector="test-changesets",state="running",worker_id="kafka-connect:8083"} 1 +# HELP kafka_connect_connector_tasks_state the state of tasks. 0-failed, 1-running, 2-unassigned, 3-paused +# TYPE kafka_connect_connector_tasks_state gauge +kafka_connect_connector_tasks_state{connector="test-changesets",state="running",worker_id="kafka-connect:8083"} 1 # HELP kafka_connect_connectors_count number of deployed connectors # TYPE kafka_connect_connectors_count gauge kafka_connect_connectors_count 1 diff --git a/kafka_connect_exporter.go b/kafka_connect_exporter.go index 0e863eb..b5fddad 100644 --- a/kafka_connect_exporter.go +++ b/kafka_connect_exporter.go @@ -32,8 +32,8 @@ var ( "is the connector running?", []string{"connector", "state", "worker"}, nil) areConnectorTasksRunning = prometheus.NewDesc( - prometheus.BuildFQName(nameSpace, "connector", "tasks_state_running"), - "are connector tasks running?", + prometheus.BuildFQName(nameSpace, "connector", "tasks_state"), + "the state of tasks. 0-failed, 1-running, 2-unassigned, 3-paused", []string{"connector", "state", "worker_id", "id"}, nil) ) @@ -136,13 +136,21 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { for _, connectorTask := range connectorStatus.Tasks { - var isTaskRunning float64 = 0 - if strings.ToLower(connectorTask.State) == "running" { - isTaskRunning = 1 + var state float64 + switch taskState := strings.ToLower(connectorTask.State) + taskState { + case "running": + state = 1 + case "unassigned": + state = 2 + case "paused": + state = 3 + default: + state = 0 } ch <- prometheus.MustNewConstMetric( - areConnectorTasksRunning, prometheus.GaugeValue, isTaskRunning, + areConnectorTasksRunning, prometheus.GaugeValue, state, connectorStatus.Name, strings.ToLower(connectorTask.State), connectorTask.WorkerId, fmt.Sprintf("%d", int(connectorTask.Id)), ) }