Skip to content

Commit

Permalink
tracking more states (#4)
Browse files Browse the repository at this point in the history
* tracking more states: unassigned, paused
* update README.md
  • Loading branch information
arnitolog authored and wakeful committed Sep 10, 2019
1 parent 3e8c550 commit 1151040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions kafka_connect_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down Expand Up @@ -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)),
)
}
Expand Down

0 comments on commit 1151040

Please sign in to comment.