Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement #136 Change-Id: I3524bd483f33e57a8b0c0a742861c829346f0ec6
- Loading branch information
Showing
17 changed files
with
464 additions
and
51 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
73 changes: 73 additions & 0 deletions
73
...cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraMetrics.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,73 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store.cassandra; | ||
|
||
import java.lang.management.MemoryUsage; | ||
import java.util.Map; | ||
|
||
import org.apache.cassandra.tools.NodeProbe; | ||
|
||
import com.baidu.hugegraph.backend.store.BackendMetrics; | ||
import com.baidu.hugegraph.config.HugeConfig; | ||
import com.baidu.hugegraph.util.Bytes; | ||
import com.baidu.hugegraph.util.InsertionOrderUtil; | ||
import com.datastax.driver.core.Cluster; | ||
import com.datastax.driver.core.Host; | ||
|
||
public class CassandraMetrics implements BackendMetrics { | ||
|
||
private final Cluster cluster; | ||
private final int port; | ||
private final String username; | ||
private final String password; | ||
|
||
public CassandraMetrics(Cluster cluster, HugeConfig conf) { | ||
this.cluster = cluster; | ||
this.port = conf.get(CassandraOptions.CASSANDRA_JMX_PORT); | ||
this.username = conf.get(CassandraOptions.CASSANDRA_USERNAME); | ||
this.password = conf.get(CassandraOptions.CASSANDRA_PASSWORD); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getMetrics() { | ||
Map<String, Object> results = InsertionOrderUtil.newMap(); | ||
for (Host host : this.cluster.getMetadata().getAllHosts()) { | ||
String address = host.getAddress().getHostAddress(); | ||
results.put(address, this.getMetricsByHost(address)); | ||
} | ||
return results; | ||
} | ||
|
||
private Map<String, Object> getMetricsByHost(String host) { | ||
Map<String, Object> metrics = InsertionOrderUtil.newMap(); | ||
// JMX client operations for Cassandra. | ||
try (NodeProbe probe = new NodeProbe(host, port, username, password)) { | ||
MemoryUsage heapUsage = probe.getHeapMemoryUsage(); | ||
metrics.put(MEM_USED, heapUsage.getUsed() / Bytes.MB); | ||
metrics.put(MEM_COMMITED, heapUsage.getCommitted() / Bytes.MB); | ||
metrics.put(MEM_MAX, heapUsage.getMax() / Bytes.MB); | ||
metrics.put(MEM_UNIT, "MB"); | ||
metrics.put(DATA_SIZE, probe.getLoadString()); | ||
} catch (Exception e) { | ||
metrics.put(EXCEPTION, e.toString()); | ||
} | ||
return metrics; | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStore.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,58 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store; | ||
|
||
import com.baidu.hugegraph.type.HugeType; | ||
|
||
public abstract class AbstractBackendStore implements BackendStore { | ||
|
||
private final MetaDispatcher dispatcher; | ||
|
||
public AbstractBackendStore() { | ||
this.dispatcher = new MetaDispatcher(); | ||
} | ||
|
||
protected MetaDispatcher metaDispatcher() { | ||
return this.dispatcher; | ||
} | ||
|
||
public <Session extends BackendSession> | ||
void registerMetaHandler(String name, MetaHandler<Session> handler) { | ||
this.dispatcher.registerMetaHandler(name, handler); | ||
} | ||
|
||
// Get metadata by key | ||
public <R> R metadata(HugeType type, String meta, Object[] args) { | ||
BackendSession session = this.session(type); | ||
MetaDispatcher dispatcher = null; | ||
if (type == null) { | ||
dispatcher = this.metaDispatcher(); | ||
} else { | ||
BackendTable table = this.table(type); | ||
dispatcher = table.metaDispatcher(); | ||
} | ||
return dispatcher.dispatchMetaHandler(session, meta, args); | ||
} | ||
|
||
protected abstract BackendTable table(HugeType type); | ||
|
||
// NOTE: Need to support passing null | ||
protected abstract BackendSession session(HugeType type); | ||
} |
40 changes: 40 additions & 0 deletions
40
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMetrics.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,40 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store; | ||
|
||
import java.util.Map; | ||
|
||
public interface BackendMetrics { | ||
|
||
public String BACKEND = "backend"; | ||
|
||
// Memory related metrics | ||
public String MEM_USED = "mem_used"; | ||
public String MEM_COMMITED = "mem_commited"; | ||
public String MEM_MAX = "mem_max"; | ||
public String MEM_UNIT = "mem_unit"; | ||
|
||
// Data load related metrics | ||
public String DATA_SIZE = "data_size"; | ||
|
||
public String EXCEPTION = "exception"; | ||
|
||
public Map<String, Object> getMetrics(); | ||
} |
Oops, something went wrong.