aboutsummaryrefslogtreecommitdiffstats
path: root/app/_locales
diff options
context:
space:
mode:
authorFrankie <frankie.pangilinan@consensys.net>2016-08-13 08:43:24 +0800
committerFrankie <frankie.pangilinan@consensys.net>2016-08-13 08:43:24 +0800
commit99a788a6f02ffcd53e88222ab0ba4b89d8040f4f (patch)
tree097fb582484f3c65cb152513167f1b6dbabb8bc6 /app/_locales
parentb72c00a6c15af9692cbaf46b89a19e5cef45f7b7 (diff)
downloadtangerine-wallet-browser-99a788a6f02ffcd53e88222ab0ba4b89d8040f4f.tar.gz
tangerine-wallet-browser-99a788a6f02ffcd53e88222ab0ba4b89d8040f4f.tar.zst
tangerine-wallet-browser-99a788a6f02ffcd53e88222ab0ba4b89d8040f4f.zip
Add multi message capability to Qr view for market info
Diffstat (limited to 'app/_locales')
0 files changed, 0 insertions, 0 deletions
'#n159'>159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
package main

import (
    "fmt"
    "math"
    "reflect"
    "runtime"
    "sort"
    "strings"
    "time"

    "github.com/codegangsta/cli"
    "github.com/ethereum/go-ethereum/cmd/utils"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/rpc"
    "github.com/ethereum/go-ethereum/rpc/codec"
    "github.com/ethereum/go-ethereum/rpc/comms"
    "github.com/gizak/termui"
)

var (
    monitorCommandAttachFlag = cli.StringFlag{
        Name:  "attach",
        Value: "ipc:" + common.DefaultIpcPath(),
        Usage: "API endpoint to attach to",
    }
    monitorCommandRowsFlag = cli.IntFlag{
        Name:  "rows",
        Value: 5,
        Usage: "Maximum rows in the chart grid",
    }
    monitorCommandRefreshFlag = cli.IntFlag{
        Name:  "refresh",
        Value: 3,
        Usage: "Refresh interval in seconds",
    }
    monitorCommand = cli.Command{
        Action: monitor,
        Name:   "monitor",
        Usage:  `Geth Monitor: node metrics monitoring and visualization`,
        Description: `
The Geth monitor is a tool to collect and visualize various internal metrics
gathered by the node, supporting different chart types as well as the capacity
to display multiple metrics simultaneously.
`,
        Flags: []cli.Flag{
            monitorCommandAttachFlag,
            monitorCommandRowsFlag,
            monitorCommandRefreshFlag,
        },
    }
)

// monitor starts a terminal UI based monitoring tool for the requested metrics.
func monitor(ctx *cli.Context) {
    var (
        client comms.EthereumClient
        err    error
    )
    // Attach to an Ethereum node over IPC or RPC
    endpoint := ctx.String(monitorCommandAttachFlag.Name)
    if client, err = comms.ClientFromEndpoint(endpoint, codec.JSON); err != nil {
        utils.Fatalf("Unable to attach to geth node: %v", err)
    }
    defer client.Close()

    xeth := rpc.NewXeth(client)

    // Retrieve all the available metrics and resolve the user pattens
    metrics, err := retrieveMetrics(xeth)
    if err != nil {
        utils.Fatalf("Failed to retrieve system metrics: %v", err)
    }
    monitored := resolveMetrics(metrics, ctx.Args())
    if len(monitored) == 0 {
        list := expandMetrics(metrics, "")
        sort.Strings(list)
        utils.Fatalf("No metrics specified.\n\nAvailable:\n - %s", strings.Join(list, "\n - "))
    }
    sort.Strings(monitored)
    if cols := len(monitored) / ctx.Int(monitorCommandRowsFlag.Name); cols > 6 {
        utils.Fatalf("Requested metrics (%d) spans more that 6 columns:\n - %s", len(monitored), strings.Join(monitored, "\n - "))
    }
    // Create and configure the chart UI defaults
    if err := termui.Init(); err != nil {
        utils.Fatalf("Unable to initialize terminal UI: %v", err)
    }
    defer termui.Close()

    termui.UseTheme("helloworld")

    rows := len(monitored)
    if max := ctx.Int(monitorCommandRowsFlag.Name); rows > max {
        rows = max
    }
    cols := (len(monitored) + rows - 1) / rows
    for i := 0; i < rows; i++ {
        termui.Body.AddRows(termui.NewRow())
    }
    // Create each individual data chart
    footer := termui.NewPar("")
    footer.HasBorder = true
    footer.Height = 3

    charts := make([]*termui.LineChart, len(monitored))
    units := make([]int, len(monitored))
    data := make([][]float64, len(monitored))
    for i := 0; i < len(monitored); i++ {
        charts[i] = createChart((termui.TermHeight() - footer.Height) / rows)
        row := termui.Body.Rows[i%rows]
        row.Cols = append(row.Cols, termui.NewCol(12/cols, 0, charts[i]))
    }
    termui.Body.AddRows(termui.NewRow(termui.NewCol(12, 0, footer)))

    refreshCharts(xeth, monitored, data, units, charts, ctx, footer)
    termui.Body.Align()
    termui.Render(termui.Body)

    // Watch for various system events, and periodically refresh the charts
    refresh := time.Tick(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second)
    for {
        select {
        case event := <-termui.EventCh():
            if event.Type == termui.EventKey && event.Key == termui.KeyCtrlC {
                return
            }
            if event.Type == termui.EventResize {
                termui.Body.Width = termui.TermWidth()
                for _, chart := range charts {
                    chart.Height = (termui.TermHeight() - footer.Height) / rows
                }
                termui.Body.Align()
                termui.Render(termui.Body)
            }
        case <-refresh:
            if refreshCharts(xeth, monitored, data, units, charts, ctx, footer) {
                termui.Body.Align()
            }
            termui.Render(termui.Body)
        }
    }
}

// retrieveMetrics contacts the attached geth node and retrieves the entire set
// of collected system metrics.
func retrieveMetrics(xeth *rpc.Xeth) (map[string]interface{}, error) {
    return xeth.Call("debug_metrics", []interface{}{true})
}

// resolveMetrics takes a list of input metric patterns, and resolves each to one
// or more canonical metric names.
func resolveMetrics(metrics map[string]interface{}, patterns []string) []string {
    res := []string{}
    for _, pattern := range patterns {
        res = append(res, resolveMetric(metrics, pattern, "")...)