mirror of
https://github.com/logos-storage/logos-storage-network-crawler.git
synced 2026-01-02 13:33:08 +00:00
working example of a metriced-list
This commit is contained in:
parent
d2eac93c0f
commit
faa9d2f4fd
@ -10,7 +10,7 @@ Usage:
|
||||
|
||||
Options:
|
||||
--logLevel=<l> Sets log level [default: TRACE]
|
||||
--metricsAddress=<ip> Listen address of the metrics server [default: 127.0.0.1]
|
||||
--metricsAddress=<ip> Listen address of the metrics server [default: 0.0.0.0]
|
||||
--metricsPort=<p> Listen HTTP port of the metrics server [default: 8008]
|
||||
--dataDir=<dir> Directory for storing data [default: crawler_data]
|
||||
--discoveryPort=<p> Port used for DHT [default: 8090]
|
||||
|
||||
20
codexcrawler/list.nim
Normal file
20
codexcrawler/list.nim
Normal file
@ -0,0 +1,20 @@
|
||||
import pkg/metrics
|
||||
|
||||
type
|
||||
OnUpdateMetric = proc(value: int64): void {.gcsafe, raises:[].}
|
||||
List*[T] = ref object
|
||||
items: seq[T]
|
||||
onMetric: OnUpdateMetric
|
||||
|
||||
proc new*[T](
|
||||
_: type List[T],
|
||||
onMetric: OnUpdateMetric
|
||||
): List[T] =
|
||||
List[T](
|
||||
items: newSeq[T](),
|
||||
onMetric: onMetric
|
||||
)
|
||||
|
||||
proc add*[T](this: List[T], item: T) =
|
||||
this.items.add(item)
|
||||
this.onMetric(this.items.len.int64)
|
||||
@ -1,14 +1,26 @@
|
||||
import pkg/chronicles
|
||||
import pkg/chronos
|
||||
|
||||
import pkg/metrics
|
||||
|
||||
import ./list
|
||||
|
||||
logScope:
|
||||
topics = "main"
|
||||
|
||||
declareGauge(example, "testing")
|
||||
|
||||
proc startApplication*() {.async.} =
|
||||
proc onExampleMetric(value: int64) =
|
||||
example.set(value)
|
||||
var exampleList = List[string].new(onExampleMetric)
|
||||
|
||||
proc aaa() {.async.} =
|
||||
while true:
|
||||
notice "a"
|
||||
await sleepAsync(1000)
|
||||
exampleList.add("str!")
|
||||
|
||||
|
||||
asyncSpawn aaa()
|
||||
|
||||
|
||||
1
config.nims
Normal file
1
config.nims
Normal file
@ -0,0 +1 @@
|
||||
--define:metrics
|
||||
Loading…
x
Reference in New Issue
Block a user