1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use diem_metrics::{register_int_counter_vec, IntCounterVec};
use once_cell::sync::Lazy;

pub enum RpcResult {
    Success,
    Error,
}

impl RpcResult {
    pub fn as_str(&self) -> &'static str {
        match self {
            RpcResult::Success => "success",
            RpcResult::Error => "error",
        }
    }
}

pub static HTTP_WEBSOCKET_REQUESTS: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_http_websocket_requests_count",
        "Cumulative number of http requests that the JSON RPC streaming service receives",
        &[
            "sdk_lang", // the language of the SDK: "java", "python", etc
            "sdk_ver",  // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

pub static HTTP_WEBSOCKET_REQUEST_UPGRADES: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_http_websocket_upgrades_count",
        "Cumulative number of http websocket requests which successfully get upgraded that the JSON RPC streaming service receives",
        &[
            "sdk_lang", // the language of the SDK: "java", "python", etc
            "sdk_ver", // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
        .unwrap()
});

/// number of messages received. These are raw messages, before parsing
pub static MESSAGES_RECEIVED: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_messages_received",
        "Cumulative number of messages that the Streaming RPC service receives",
        &[
            "transport", // transport used: ws, ipc, etc
            "sdk_lang",  // the language of the SDK: "java", "python", etc
            "sdk_ver",   // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

/// number of messages sent
pub static MESSAGES_SENT: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_messages_sent",
        "Cumulative number of messages that the Streaming RPC service sends",
        &[
            "transport", // transport used: ws, ipc, etc
            "sdk_lang",  // the language of the SDK: "java", "python", etc
            "sdk_ver",   // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

/// number of messages received. These are messages after parsing (subscription requests)
pub static SUBSCRIPTION_RPC_RECEIVED: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_subscription_rpc_received",
        "Cumulative number of RPC messages that the Streaming RPC service receives, parses successfully, and responds to",
        &[
            "transport", // transport used: ws, ipc, etc
            "method", // method of request, matches JSON RPC method name (e.g. "submit", "get_account")
            "result", // result of request: "success", "fail"
            "sdk_lang", // the language of the SDK: "java", "python", etc
            "sdk_ver", // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
        .unwrap()
});

/// number of messages sent. These are in response to subscriptions.
pub static SUBSCRIPTION_RPC_SENT: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_subscription_rpc_sent",
        "Cumulative number of RPC messages that the Streaming RPC service sends as part of subscriptions",
        &[
            "transport", // transport used: ws, ipc, etc
            "method", // method of request, matches JSON RPC method name (e.g. "submit", "get_account")
            "result", // result of request: "success", "fail"
            "sdk_lang", // the language of the SDK: "java", "python", etc
            "sdk_ver", // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

/// number of 'OK' messages sent. These are sent when a subscription is started.
pub static SUBSCRIPTION_OKS: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_subscription_oks",
        "Cumulative number of 'OK' messages sent in response to starting a subscription",
        &[
            "transport", // transport used: ws, ipc, etc
            "method", // method of request, matches JSON RPC method name (e.g. "submit", "get_account")
            "result", // result of request: "success", "fail"
            "sdk_lang", // the language of the SDK: "java", "python", etc
            "sdk_ver", // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

/// Cumulative number of clients connected
pub static CLIENT_CONNECTED: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_clients_count",
        "Cumulative number of connected clients",
        &[
            "transport", // transport used: ws, ipc, etc
            "sdk_lang",  // the language of the SDK: "java", "python", etc
            "sdk_ver",   // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});

pub static INVALID_REQUESTS: Lazy<IntCounterVec> = Lazy::new(|| {
    register_int_counter_vec!(
        "diem_streaming_rpc_invalid_requests_count",
        "Cumulative number of invalid requests that JSON RPC client service receives",
        &[
            "transport", // transport used: ws, ipc, etc
            "method", // method of request, matches JSON RPC method name (e.g. "submit", "get_account")
            "errortype", // categories of invalid requests: "invalid_format", "invalid_params", "invalid_method", "method_not_found"
            "sdk_lang",  // the language of the SDK: "java", "python", etc
            "sdk_ver",   // the version of the SDK: "0.0.11", "1.45.31", etc
        ]
    )
    .unwrap()
});