-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Successfully started workspaces ratio (#12852)
Successfully started workspaces ratio Signed-off-by: Sergii Kabashniuk <[email protected]>
- Loading branch information
1 parent
b4702cd
commit 7a1d396
Showing
8 changed files
with
447 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...-metrics/src/main/java/org/eclipse/che/api/metrics/WorkspaceStartAttemptsMeterBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.api.metrics; | ||
|
||
import static org.eclipse.che.api.metrics.WorkspaceBinders.workspaceMetric; | ||
|
||
import com.google.inject.Inject; | ||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus; | ||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent; | ||
|
||
/** Counts number of attempts to start workspace. */ | ||
@Singleton | ||
public class WorkspaceStartAttemptsMeterBinder implements MeterBinder { | ||
private final EventService eventService; | ||
|
||
private Counter startingCounter; | ||
|
||
@Inject | ||
public WorkspaceStartAttemptsMeterBinder(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
startingCounter = | ||
Counter.builder(workspaceMetric("starting_attempts.total")) | ||
.description("The count of workspaces start attempts") | ||
.register(registry); | ||
|
||
// only subscribe to the event once we have the counters ready | ||
eventService.subscribe( | ||
event -> { | ||
if (event.getPrevStatus() == WorkspaceStatus.STOPPED | ||
&& event.getStatus() == WorkspaceStatus.STARTING) { | ||
startingCounter.increment(); | ||
} | ||
}, | ||
WorkspaceStatusEvent.class); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...rc/main/java/org/eclipse/che/api/metrics/WorkspaceSuccessfulStartAttemptsMeterBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.api.metrics; | ||
|
||
import static org.eclipse.che.api.metrics.WorkspaceBinders.workspaceMetric; | ||
|
||
import com.google.inject.Inject; | ||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus; | ||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent; | ||
|
||
/** Counts number of successfully started workspaces. */ | ||
@Singleton | ||
public class WorkspaceSuccessfulStartAttemptsMeterBinder implements MeterBinder { | ||
private final EventService eventService; | ||
|
||
private Counter startedCounter; | ||
|
||
@Inject | ||
public WorkspaceSuccessfulStartAttemptsMeterBinder(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
startedCounter = | ||
Counter.builder(workspaceMetric("started.total")) | ||
.description("The count of started workspaces") | ||
.register(registry); | ||
|
||
// only subscribe to the event once we have the counters ready | ||
eventService.subscribe( | ||
event -> { | ||
if (event.getPrevStatus() == WorkspaceStatus.STARTING | ||
&& event.getStatus() == WorkspaceStatus.RUNNING) { | ||
startedCounter.increment(); | ||
} | ||
}, | ||
WorkspaceStatusEvent.class); | ||
} | ||
} |
Oops, something went wrong.