-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: manishdas12 <manishdas12@yahoo.in>
- Loading branch information
1 parent
476b8f3
commit 9624de9
Showing
4 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Proxy } from '../platform/fabric/Proxy'; | ||
import { Platform } from '../platform/fabric/Platform'; | ||
import { | ||
metric_ledger_height, | ||
ledger_blockchain_height, | ||
ledger_transaction_count, | ||
metric_node_up | ||
} from './metrics'; | ||
|
||
export async function collectMetrics(platform: Platform) { | ||
const proxy: Proxy = platform.getProxy(); | ||
const networks = await proxy.networkList(); | ||
for (const network of networks) { | ||
const network_id = network.id; | ||
// get all the channels info | ||
const channelList = await proxy.getChannelsInfo(network_id); | ||
for (const channelInfo of channelList) { | ||
const channel_genesis = channelInfo.channel_genesis_hash; | ||
ledger_blockchain_height | ||
.labels({ | ||
channel: channelInfo.channelname, | ||
channel_genesis_hash: channelInfo.channel_genesis_hash | ||
}) | ||
.set(channelInfo.blocks); | ||
ledger_transaction_count | ||
.labels({ | ||
channel: channelInfo.channelname, | ||
channel_genesis_hash: channelInfo.channel_genesis_hash | ||
}) | ||
.inc(); | ||
|
||
// get the peer status and the ledger height | ||
const peerStatus = await proxy.getPeersStatus(network_id, channel_genesis); | ||
setLedgerHeight(peerStatus, channelInfo.channelname); | ||
} | ||
} | ||
} | ||
|
||
async function setLedgerHeight(peerStatus: any[], channel: string) { | ||
for (const peer of peerStatus) { | ||
if (peer.peer_type === 'PEER' && typeof peer.ledger_height_low === 'number') { | ||
metric_ledger_height | ||
.labels({ | ||
mspid: peer.mspid, | ||
requests: peer.requests, | ||
server_hostname: peer.server_hostname, | ||
channel: channel | ||
}) | ||
.set(peer.ledger_height_low); | ||
} | ||
let status = 0; | ||
if (peer.status === 'UP') { | ||
status = 1; | ||
} | ||
metric_node_up | ||
.labels({ node: peer.server_hostname, mspid: peer.mspid }) | ||
.set(status); | ||
} | ||
} |
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,42 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import client from 'prom-client'; | ||
|
||
export const metric_ledger_height = new client.Gauge({ | ||
name: 'metric_ledger_height', | ||
help: 'metric_ledger_height_low: returns ledger height of the peer nodes', | ||
labelNames: ['channel', 'mspid', 'requests', 'server_hostname'] | ||
}); | ||
|
||
export const ledger_blockchain_height = new client.Gauge({ | ||
name: 'ledger_blockchain_height', | ||
help: 'ledger_blockchain_height: returns block height of channel', | ||
labelNames: ['channel', 'channel_genesis_hash'] | ||
}); | ||
|
||
export const ledger_transaction_count = new client.Counter({ | ||
name: 'ledger_transaction_count', | ||
help: 'metric_channel_txns: returns transaction count on a channel', | ||
labelNames: ['channel', 'channel_genesis_hash'] | ||
}); | ||
|
||
export const metric_node_up = new client.Gauge({ | ||
name: 'metric_node_up', | ||
help: 'metric_node_up: returns status of peer and orderer node', | ||
labelNames: ['node', 'mspid'] | ||
}); | ||
|
||
export const ledger_blockstorage_commit_time = new client.Histogram({ | ||
name: 'ledger_blockstorage_commit_time', | ||
help: | ||
'ledger_blockstorage_commit_time: Time taken in sec for committing block changes to state db.', | ||
labelNames: ['channel', 'channel_genesis_hash'] | ||
}); | ||
|
||
export const fabric_version = new client.Gauge({ | ||
name: 'fabric_version', | ||
help: 'fabric_version: show fabric versions', | ||
labelNames: ['channel', 'channel_genesis_hash'] | ||
}); |
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,21 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Router } from 'express'; | ||
import promClient from 'prom-client'; | ||
import { helper } from '../common/helper'; | ||
import { collectMetrics } from '../metrics/collect-metrics'; | ||
|
||
const logger = helper.getLogger('metricRoutes'); | ||
export async function metricsRoutes(router: Router, platform: any) { | ||
// scrap metrics for every 5 seconds | ||
setInterval(() => { | ||
collectMetrics(platform); | ||
}, 5 * 1000); | ||
|
||
router.get('/', async (_, res) => { | ||
logger.info('available metrics....'); | ||
res.send(await promClient.register.metrics()); | ||
}); | ||
} |