-
Notifications
You must be signed in to change notification settings - Fork 176
/
census.go
1593 lines (1454 loc) · 54.6 KB
/
census.go
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
149
150
151
152
153
154
155
156
157
158
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package monitor
import (
"context"
"math/big"
"net"
"runtime"
"strconv"
"strings"
"sync"
"time"
"github.com/golang/glog"
"github.com/livepeer/go-livepeer/clog"
"contrib.go.opencensus.io/exporter/prometheus"
rprom "github.com/prometheus/client_golang/prometheus"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
)
type (
SegmentUploadError string
SegmentTranscodeError string
)
const (
SegmentUploadErrorUnknown SegmentUploadError = "Unknown"
SegmentUploadErrorGenCreds SegmentUploadError = "GenCreds"
SegmentUploadErrorOS SegmentUploadError = "ObjectStorage"
SegmentUploadErrorSessionEnded SegmentUploadError = "SessionEnded"
SegmentUploadErrorInsufficientBalance SegmentUploadError = "InsufficientBalance"
SegmentUploadErrorTimeout SegmentUploadError = "Timeout"
SegmentUploadErrorDuplicateSegment SegmentUploadError = "DuplicateSegment"
SegmentUploadErrorOrchestratorCapped SegmentUploadError = "OrchestratorCapped"
SegmentTranscodeErrorUnknown SegmentTranscodeError = "Unknown"
SegmentTranscodeErrorUnknownResponse SegmentTranscodeError = "UnknownResponse"
SegmentTranscodeErrorTranscode SegmentTranscodeError = "Transcode"
SegmentTranscodeErrorOrchestratorBusy SegmentTranscodeError = "OrchestratorBusy"
SegmentTranscodeErrorOrchestratorCapped SegmentTranscodeError = "OrchestratorCapped"
SegmentTranscodeErrorParseResponse SegmentTranscodeError = "ParseResponse"
SegmentTranscodeErrorReadBody SegmentTranscodeError = "ReadBody"
SegmentTranscodeErrorNoOrchestrators SegmentTranscodeError = "NoOrchestrators"
SegmentTranscodeErrorDownload SegmentTranscodeError = "Download"
SegmentTranscodeErrorSaveData SegmentTranscodeError = "SaveData"
SegmentTranscodeErrorSessionEnded SegmentTranscodeError = "SessionEnded"
SegmentTranscodeErrorDuplicateSegment SegmentTranscodeError = "DuplicateSegment"
numberOfSegmentsToCalcAverage = 30
gweiConversionFactor = 1000000000
logLevel = 6 // TODO move log levels definitions to separate package
// importing `common` package here introduces import cycles
)
type NodeType string
const (
Default NodeType = "dflt"
Orchestrator NodeType = "orch"
Broadcaster NodeType = "bctr"
Transcoder NodeType = "trcr"
Redeemer NodeType = "rdmr"
segTypeRegular = "regular"
segTypeRec = "recorded" // segment in the stream for which recording is enabled
)
// Enabled true if metrics was enabled in command line
var Enabled bool
var NodeID string
var timeToWaitForError = 8500 * time.Millisecond
var timeoutWatcherPause = 15 * time.Second
type (
censusMetricsCounter struct {
nodeType NodeType
nodeID string
ctx context.Context
kGPU tag.Key
kNodeType tag.Key
kNodeID tag.Key
kProfile tag.Key
kProfiles tag.Key
kErrorCode tag.Key
kTry tag.Key
kSender tag.Key
kRecipient tag.Key
kManifestID tag.Key
kSegmentType tag.Key
kTrusted tag.Key
kVerified tag.Key
mSegmentSourceAppeared *stats.Int64Measure
mSegmentEmerged *stats.Int64Measure
mSegmentEmergedUnprocessed *stats.Int64Measure
mSegmentUploaded *stats.Int64Measure
mSegmentUploadFailed *stats.Int64Measure
mSegmentDownloaded *stats.Int64Measure
mSegmentTranscoded *stats.Int64Measure
mSegmentTranscodedUnprocessed *stats.Int64Measure
mSegmentTranscodeFailed *stats.Int64Measure
mSegmentTranscodedAppeared *stats.Int64Measure
mSegmentTranscodedAllAppeared *stats.Int64Measure
mStartBroadcastClientFailed *stats.Int64Measure
mStreamCreateFailed *stats.Int64Measure
mStreamCreated *stats.Int64Measure
mStreamStarted *stats.Int64Measure
mStreamEnded *stats.Int64Measure
mMaxSessions *stats.Int64Measure
mCurrentSessions *stats.Int64Measure
mDiscoveryError *stats.Int64Measure
mTranscodeRetried *stats.Int64Measure
mTranscodersNumber *stats.Int64Measure
mTranscodersCapacity *stats.Int64Measure
mTranscodersLoad *stats.Int64Measure
mSuccessRate *stats.Float64Measure
mTranscodeTime *stats.Float64Measure
mTranscodeLatency *stats.Float64Measure
mTranscodeOverallLatency *stats.Float64Measure
mUploadTime *stats.Float64Measure
mDownloadTime *stats.Float64Measure
mAuthWebhookTime *stats.Float64Measure
mSourceSegmentDuration *stats.Float64Measure
mHTTPClientTimeout1 *stats.Int64Measure
mHTTPClientTimeout2 *stats.Int64Measure
mRealtimeRatio *stats.Float64Measure
mRealtime3x *stats.Int64Measure
mRealtime2x *stats.Int64Measure
mRealtime1x *stats.Int64Measure
mRealtimeHalf *stats.Int64Measure
mRealtimeSlow *stats.Int64Measure
mTranscodeScore *stats.Float64Measure
mRecordingSaveLatency *stats.Float64Measure
mRecordingSaveErrors *stats.Int64Measure
mRecordingSavedSegments *stats.Int64Measure
mOrchestratorSwaps *stats.Int64Measure
// Metrics for sending payments
mTicketValueSent *stats.Float64Measure
mTicketsSent *stats.Int64Measure
mPaymentCreateError *stats.Int64Measure
mDeposit *stats.Float64Measure
mReserve *stats.Float64Measure
mMaxTranscodingPrice *stats.Float64Measure
// Metrics for receiving payments
mTicketValueRecv *stats.Float64Measure
mTicketsRecv *stats.Int64Measure
mPaymentRecvErr *stats.Int64Measure
mWinningTicketsRecv *stats.Int64Measure
mValueRedeemed *stats.Float64Measure
mTicketRedemptionError *stats.Int64Measure
mSuggestedGasPrice *stats.Float64Measure
mMinGasPrice *stats.Float64Measure
mMaxGasPrice *stats.Float64Measure
mTranscodingPrice *stats.Float64Measure
// Metrics for pixel accounting
mMilPixelsProcessed *stats.Float64Measure
// Metrics for fast verification
mFastVerificationDone *stats.Int64Measure
mFastVerificationFailed *stats.Int64Measure
mFastVerificationEnabledCurrentSessions *stats.Int64Measure
mFastVerificationUsingCurrentSessions *stats.Int64Measure
lock sync.Mutex
emergeTimes map[uint64]map[uint64]time.Time // nonce:seqNo
success map[uint64]*segmentsAverager
}
segmentCount struct {
seqNo uint64
emergedTime time.Time
emerged int
transcoded int
failed bool
}
tryData struct {
first time.Time
tries int
}
segmentsAverager struct {
segments []segmentCount
start int
end int
removed bool
removedAt time.Time
tries map[uint64]tryData // seqNo:try
}
)
// Exporter Prometheus exporter that handles `/metrics` endpoint
var Exporter *prometheus.Exporter
var census censusMetricsCounter
// used in unit tests
var unitTestMode bool
func InitCensus(nodeType NodeType, version string) {
census = censusMetricsCounter{
emergeTimes: make(map[uint64]map[uint64]time.Time),
nodeID: NodeID,
nodeType: nodeType,
success: make(map[uint64]*segmentsAverager),
}
var err error
ctx := context.Background()
census.kGPU = tag.MustNewKey("gpu")
census.kNodeType = tag.MustNewKey("node_type")
census.kNodeID = tag.MustNewKey("node_id")
census.kProfile = tag.MustNewKey("profile")
census.kProfiles = tag.MustNewKey("profiles")
census.kErrorCode = tag.MustNewKey("error_code")
census.kTry = tag.MustNewKey("try")
census.kSender = tag.MustNewKey("sender")
census.kRecipient = tag.MustNewKey("recipient")
census.kManifestID = tag.MustNewKey("manifestID")
census.kSegmentType = tag.MustNewKey("seg_type")
census.kTrusted = tag.MustNewKey("trusted")
census.kVerified = tag.MustNewKey("verified")
census.ctx, err = tag.New(ctx, tag.Insert(census.kNodeType, string(nodeType)), tag.Insert(census.kNodeID, NodeID))
if err != nil {
glog.Fatal("Error creating context", err)
}
census.mHTTPClientTimeout1 = stats.Int64("http_client_timeout_1", "Number of times HTTP connection was dropped before transcoding complete", "tot")
census.mHTTPClientTimeout2 = stats.Int64("http_client_timeout_2", "Number of times HTTP connection was dropped before transcoded segments was sent back to client", "tot")
census.mRealtimeRatio = stats.Float64("http_client_segment_transcoded_realtime_ratio", "Ratio of source segment duration / transcode time as measured on HTTP client", "rat")
census.mRealtime3x = stats.Int64("http_client_segment_transcoded_realtime_3x", "Number of segment transcoded 3x faster than realtime", "tot")
census.mRealtime2x = stats.Int64("http_client_segment_transcoded_realtime_2x", "Number of segment transcoded 2x faster than realtime", "tot")
census.mRealtime1x = stats.Int64("http_client_segment_transcoded_realtime_1x", "Number of segment transcoded 1x faster than realtime", "tot")
census.mRealtimeHalf = stats.Int64("http_client_segment_transcoded_realtime_half", "Number of segment transcoded no more than two times slower than realtime", "tot")
census.mRealtimeSlow = stats.Int64("http_client_segment_transcoded_realtime_slow", "Number of segment transcoded more than two times slower than realtime", "tot")
census.mSegmentSourceAppeared = stats.Int64("segment_source_appeared_total", "SegmentSourceAppeared", "tot")
census.mSegmentEmerged = stats.Int64("segment_source_emerged_total", "SegmentEmerged", "tot")
census.mSegmentEmergedUnprocessed = stats.Int64("segment_source_emerged_unprocessed_total", "SegmentEmerged, counted by number of transcode profiles", "tot")
census.mSegmentUploaded = stats.Int64("segment_source_uploaded_total", "SegmentUploaded", "tot")
census.mSegmentUploadFailed = stats.Int64("segment_source_upload_failed_total", "SegmentUploadedFailed", "tot")
census.mSegmentDownloaded = stats.Int64("segment_transcoded_downloaded_total", "SegmentDownloaded", "tot")
census.mSegmentTranscoded = stats.Int64("segment_transcoded_total", "SegmentTranscoded", "tot")
census.mSegmentTranscodedUnprocessed = stats.Int64("segment_transcoded_unprocessed_total", "SegmentTranscodedUnprocessed", "tot")
census.mSegmentTranscodeFailed = stats.Int64("segment_transcode_failed_total", "SegmentTranscodeFailed", "tot")
census.mSegmentTranscodedAppeared = stats.Int64("segment_transcoded_appeared_total", "SegmentTranscodedAppeared", "tot")
census.mSegmentTranscodedAllAppeared = stats.Int64("segment_transcoded_all_appeared_total", "SegmentTranscodedAllAppeared", "tot")
census.mStartBroadcastClientFailed = stats.Int64("broadcast_client_start_failed_total", "StartBroadcastClientFailed", "tot")
census.mStreamCreateFailed = stats.Int64("stream_create_failed_total", "StreamCreateFailed", "tot")
census.mStreamCreated = stats.Int64("stream_created_total", "StreamCreated", "tot")
census.mStreamStarted = stats.Int64("stream_started_total", "StreamStarted", "tot")
census.mStreamEnded = stats.Int64("stream_ended_total", "StreamEnded", "tot")
census.mMaxSessions = stats.Int64("max_sessions_total", "MaxSessions", "tot")
census.mCurrentSessions = stats.Int64("current_sessions_total", "Number of currently transcoded streams", "tot")
census.mDiscoveryError = stats.Int64("discovery_errors_total", "Number of discover errors", "tot")
census.mTranscodeRetried = stats.Int64("transcode_retried", "Number of times segment transcode was retried", "tot")
census.mTranscodersNumber = stats.Int64("transcoders_number", "Number of transcoders currently connected to orchestrator", "tot")
census.mTranscodersCapacity = stats.Int64("transcoders_capacity", "Total advertised capacity of transcoders currently connected to orchestrator", "tot")
census.mTranscodersLoad = stats.Int64("transcoders_load", "Total load of transcoders currently connected to orchestrator", "tot")
census.mSuccessRate = stats.Float64("success_rate", "Success rate", "per")
census.mTranscodeTime = stats.Float64("transcode_time_seconds", "Transcoding time", "sec")
census.mTranscodeLatency = stats.Float64("transcode_latency_seconds",
"Transcoding latency, from source segment emerged from segmenter till transcoded segment apeeared in manifest", "sec")
census.mTranscodeOverallLatency = stats.Float64("transcode_overall_latency_seconds",
"Transcoding latency, from source segment emerged from segmenter till all transcoded segment apeeared in manifest", "sec")
census.mUploadTime = stats.Float64("upload_time_seconds", "Upload (to Orchestrator) time", "sec")
census.mDownloadTime = stats.Float64("download_time_seconds", "Download (from orchestrator) time", "sec")
census.mAuthWebhookTime = stats.Float64("auth_webhook_time_milliseconds", "Authentication webhook execution time", "ms")
census.mSourceSegmentDuration = stats.Float64("source_segment_duration_seconds", "Source segment's duration", "sec")
census.mTranscodeScore = stats.Float64("transcode_score", "Ratio of source segment duration vs. transcode time", "rat")
census.mRecordingSaveLatency = stats.Float64("recording_save_latency",
"How long it takes to save segment to the OS", "sec")
census.mRecordingSaveErrors = stats.Int64("recording_save_errors", "Number of errors during save to the recording OS", "tot")
census.mRecordingSavedSegments = stats.Int64("recording_saved_segments", "Number of segments saved to the recording OS", "tot")
census.mOrchestratorSwaps = stats.Int64("orchestrator_swaps", "Number of orchestrator swaps mid-stream", "tot")
// Metrics for sending payments
census.mTicketValueSent = stats.Float64("ticket_value_sent", "TicketValueSent", "gwei")
census.mTicketsSent = stats.Int64("tickets_sent", "TicketsSent", "tot")
census.mPaymentCreateError = stats.Int64("payment_create_errors", "PaymentCreateError", "tot")
census.mDeposit = stats.Float64("broadcaster_deposit", "Current remaining deposit for the broadcaster node", "gwei")
census.mReserve = stats.Float64("broadcaster_reserve", "Current remaing reserve for the broadcaster node", "gwei")
census.mMaxTranscodingPrice = stats.Float64("max_transcoding_price", "MaxTranscodingPrice", "wei")
// Metrics for receiving payments
census.mTicketValueRecv = stats.Float64("ticket_value_recv", "TicketValueRecv", "gwei")
census.mTicketsRecv = stats.Int64("tickets_recv", "TicketsRecv", "tot")
census.mPaymentRecvErr = stats.Int64("payment_recv_errors", "PaymentRecvErr", "tot")
census.mWinningTicketsRecv = stats.Int64("winning_tickets_recv", "WinningTicketsRecv", "tot")
census.mValueRedeemed = stats.Float64("value_redeemed", "ValueRedeemed", "gwei")
census.mTicketRedemptionError = stats.Int64("ticket_redemption_errors", "TicketRedemptionError", "tot")
census.mSuggestedGasPrice = stats.Float64("suggested_gas_price", "SuggestedGasPrice", "gwei")
census.mMinGasPrice = stats.Float64("min_gas_price", "MinGasPrice", "gwei")
census.mMaxGasPrice = stats.Float64("max_gas_price", "MaxGasPrice", "gwei")
census.mTranscodingPrice = stats.Float64("transcoding_price", "TranscodingPrice", "wei")
// Metrics for pixel accounting
census.mMilPixelsProcessed = stats.Float64("mil_pixels_processed", "MilPixelsProcessed", "mil pixels")
// Metrics for fast verification
census.mFastVerificationDone = stats.Int64("fast_verification_done", "FastVerificationDone", "tot")
census.mFastVerificationFailed = stats.Int64("fast_verification_failed", "FastVerificationFailed", "tot")
census.mFastVerificationEnabledCurrentSessions = stats.Int64("fast_verification_enabled_current_sessions_total",
"Number of currently transcoded streams that have fast verification enabled", "tot")
census.mFastVerificationUsingCurrentSessions = stats.Int64("fast_verification_using_current_sessions_total",
"Number of currently transcoded streams that have fast verification enabled and that are using an untrusted orchestrator", "tot")
glog.Infof("Compiler: %s Arch %s OS %s Go version %s", runtime.Compiler, runtime.GOARCH, runtime.GOOS, runtime.Version())
glog.Infof("Livepeer version: %s", version)
glog.Infof("Node type %s node ID %s", nodeType, NodeID)
mVersions := stats.Int64("versions", "Version information.", "Num")
compiler := tag.MustNewKey("compiler")
goarch := tag.MustNewKey("goarch")
goos := tag.MustNewKey("goos")
goversion := tag.MustNewKey("goversion")
livepeerversion := tag.MustNewKey("livepeerversion")
ctx, err = tag.New(ctx, tag.Insert(census.kNodeType, string(nodeType)), tag.Insert(census.kNodeID, NodeID),
tag.Insert(compiler, runtime.Compiler), tag.Insert(goarch, runtime.GOARCH), tag.Insert(goos, runtime.GOOS),
tag.Insert(goversion, runtime.Version()), tag.Insert(livepeerversion, version))
if err != nil {
glog.Fatal("Error creating tagged context", err)
}
baseTags := []tag.Key{census.kNodeID, census.kNodeType}
views := []*view.View{
{
Name: "versions",
Measure: mVersions,
Description: "Versions used by LivePeer node.",
TagKeys: []tag.Key{census.kNodeType, compiler, goos, goversion, livepeerversion},
Aggregation: view.LastValue(),
},
{
Name: "broadcast_client_start_failed_total",
Measure: census.mStartBroadcastClientFailed,
Description: "StartBroadcastClientFailed",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "stream_created_total",
Measure: census.mStreamCreated,
Description: "StreamCreated",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "stream_started_total",
Measure: census.mStreamStarted,
Description: "StreamStarted",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "stream_ended_total",
Measure: census.mStreamEnded,
Description: "StreamEnded",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "stream_create_failed_total",
Measure: census.mStreamCreateFailed,
Description: "StreamCreateFailed",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_timeout_1",
Measure: census.mHTTPClientTimeout1,
Description: "Number of times HTTP connection was dropped before transcoding complete",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_timeout_2",
Measure: census.mHTTPClientTimeout2,
Description: "Number of times HTTP connection was dropped before transcoded segments was sent back to client",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_segment_transcoded_realtime_ratio",
Measure: census.mRealtimeRatio,
Description: "Ratio of source segment duration / transcode time as measured on HTTP client",
TagKeys: baseTags,
Aggregation: view.Distribution(0.5, 1, 2, 3, 5, 10, 50, 100),
},
{
Name: "http_client_segment_transcoded_realtime_3x",
Measure: census.mRealtime3x,
Description: "Number of segment transcoded 3x faster than realtime",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_segment_transcoded_realtime_2x",
Measure: census.mRealtime2x,
Description: "Number of segment transcoded 2x faster than realtime",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_segment_transcoded_realtime_1x",
Measure: census.mRealtime1x,
Description: "Number of segment transcoded 1x faster than realtime",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_segment_transcoded_realtime_half",
Measure: census.mRealtimeHalf,
Description: "Number of segment transcoded no more than two times slower than realtime",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "http_client_segment_transcoded_realtime_slow",
Measure: census.mRealtimeSlow,
Description: "Number of segment transcoded more than two times slower than realtime",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "segment_source_appeared_total",
Measure: census.mSegmentSourceAppeared,
Description: "SegmentSourceAppeared",
TagKeys: append([]tag.Key{census.kProfile, census.kSegmentType}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_source_emerged_total",
Measure: census.mSegmentEmerged,
Description: "SegmentEmerged",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "segment_source_emerged_unprocessed_total",
Measure: census.mSegmentEmergedUnprocessed,
Description: "Raw number of segments emerged from segmenter.",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "segment_source_uploaded_total",
Measure: census.mSegmentUploaded,
Description: "SegmentUploaded",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "segment_source_upload_failed_total",
Measure: census.mSegmentUploadFailed,
Description: "SegmentUploadedFailed",
TagKeys: append([]tag.Key{census.kErrorCode}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_transcoded_downloaded_total",
Measure: census.mSegmentDownloaded,
Description: "SegmentDownloaded",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "segment_transcoded_total",
Measure: census.mSegmentTranscoded,
Description: "SegmentTranscoded",
TagKeys: append([]tag.Key{census.kProfiles, census.kTrusted, census.kVerified}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_transcoded_unprocessed_total",
Measure: census.mSegmentTranscodedUnprocessed,
Description: "Raw number of segments successfully transcoded.",
TagKeys: append([]tag.Key{census.kProfiles}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_transcode_failed_total",
Measure: census.mSegmentTranscodeFailed,
Description: "SegmentTranscodeFailed",
TagKeys: append([]tag.Key{census.kErrorCode}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_transcoded_appeared_total",
Measure: census.mSegmentTranscodedAppeared,
Description: "SegmentTranscodedAppeared",
TagKeys: append([]tag.Key{census.kProfile, census.kSegmentType}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "segment_transcoded_all_appeared_total",
Measure: census.mSegmentTranscodedAllAppeared,
Description: "SegmentTranscodedAllAppeared",
TagKeys: append([]tag.Key{census.kProfiles}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "success_rate",
Measure: census.mSuccessRate,
Description: "Number of transcoded segments divided on number of source segments",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "transcode_time_seconds",
Measure: census.mTranscodeTime,
Description: "TranscodeTime, seconds",
TagKeys: append([]tag.Key{census.kProfiles, census.kTrusted, census.kVerified}, baseTags...),
Aggregation: view.Distribution(0, .250, .500, .750, 1.000, 1.250, 1.500, 2.000, 2.500, 3.000, 3.500, 4.000, 4.500, 5.000, 10.000),
},
{
Name: "transcode_latency_seconds",
Measure: census.mTranscodeLatency,
Description: "Transcoding latency, from source segment emerged from segmenter till transcoded segment apeeared in manifest",
TagKeys: append([]tag.Key{census.kProfile}, baseTags...),
Aggregation: view.Distribution(0, .500, .75, 1.000, 1.500, 2.000, 2.500, 3.000, 3.500, 4.000, 4.500, 5.000, 10.000),
},
{
Name: "transcode_overall_latency_seconds",
Measure: census.mTranscodeOverallLatency,
Description: "Transcoding latency, from source segment emerged from segmenter till all transcoded segment apeeared in manifest",
TagKeys: append([]tag.Key{census.kProfiles}, baseTags...),
Aggregation: view.Distribution(0, .500, .75, 1.000, 1.500, 2.000, 2.500, 3.000, 3.500, 4.000, 4.500, 5.000, 10.000),
},
{
Name: "transcode_score",
Measure: census.mTranscodeScore,
Description: "Ratio of source segment duration vs. transcode time",
TagKeys: append([]tag.Key{census.kProfiles, census.kTrusted, census.kVerified}, baseTags...),
Aggregation: view.Distribution(0, .5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 10, 15, 20, 40),
},
{
Name: "recording_save_latency",
Measure: census.mRecordingSaveLatency,
Description: "How long it takes to save segment to the OS",
TagKeys: baseTags,
Aggregation: view.Distribution(0, .500, .75, 1.000, 1.500, 2.000, 2.500, 3.000, 3.500, 4.000, 4.500, 5.000, 10.000, 30.000),
},
{
Name: "recording_save_errors",
Measure: census.mRecordingSaveErrors,
Description: "Number of errors during save to the recording OS",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "recording_saved_segments",
Measure: census.mRecordingSavedSegments,
Description: "Number of segments saved to the recording OS",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "upload_time_seconds",
Measure: census.mUploadTime,
Description: "UploadTime, seconds",
TagKeys: baseTags,
Aggregation: view.Distribution(0, .10, .20, .50, .100, .150, .200, .500, .1000, .5000, 10.000),
},
{
Name: "download_time_seconds",
Measure: census.mDownloadTime,
Description: "Download time",
TagKeys: baseTags,
Aggregation: view.Distribution(0, .10, .20, .50, .100, .150, .200, .500, .1000, .5000, 10.000),
},
{
Name: "auth_webhook_time_milliseconds",
Measure: census.mAuthWebhookTime,
Description: "Authentication webhook execution time, milliseconds",
TagKeys: baseTags,
Aggregation: view.Distribution(0, 100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000, 5000, 10000),
},
{
Name: "source_segment_duration_seconds",
Measure: census.mSourceSegmentDuration,
Description: "Source segment's duration",
TagKeys: baseTags,
Aggregation: view.Distribution(0, .5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 10, 15, 20),
},
{
Name: "max_sessions_total",
Measure: census.mMaxSessions,
Description: "Max Sessions",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "current_sessions_total",
Measure: census.mCurrentSessions,
Description: "Number of streams currently transcoding",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "discovery_errors_total",
Measure: census.mDiscoveryError,
Description: "Number of discover errors",
TagKeys: append([]tag.Key{census.kErrorCode}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "transcode_retried",
Measure: census.mTranscodeRetried,
Description: "Number of times segment transcode was retried",
TagKeys: append([]tag.Key{census.kTry}, baseTags...),
Aggregation: view.Count(),
},
{
Name: "transcoders_number",
Measure: census.mTranscodersNumber,
Description: "Number of transcoders currently connected to orchestrator",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "transcoders_capacity",
Measure: census.mTranscodersCapacity,
Description: "Total advertised capacity of transcoders currently connected to orchestrator",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "transcoders_load",
Measure: census.mTranscodersLoad,
Description: "Total load of transcoders currently connected to orchestrator",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "orchestrator_swaps",
Measure: census.mOrchestratorSwaps,
Description: "Number of orchestrator swaps mid-stream",
TagKeys: baseTags,
Aggregation: view.Count(),
},
// Metrics for sending payments
{
Name: "ticket_value_sent",
Measure: census.mTicketValueSent,
Description: "Ticket value sent",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "tickets_sent",
Measure: census.mTicketsSent,
Description: "Tickets sent",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "payment_create_errors",
Measure: census.mPaymentCreateError,
Description: "Errors when creating payments",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "broadcaster_deposit",
Measure: census.mDeposit,
Description: "Current remaining deposit for the broadcaster node",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "broadcaster_reserve",
Measure: census.mReserve,
Description: "Current remaining reserve for the broadcaster node",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "max_transcoding_price",
Measure: census.mMaxTranscodingPrice,
Description: "Maximum price per pixel to pay for transcoding",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
// Metrics for receiving payments
{
Name: "ticket_value_recv",
Measure: census.mTicketValueRecv,
Description: "Ticket value received",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "tickets_recv",
Measure: census.mTicketsRecv,
Description: "Tickets received",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "payment_recv_errors",
Measure: census.mPaymentRecvErr,
Description: "Errors when receiving payments",
TagKeys: append([]tag.Key{census.kErrorCode}, baseTags...),
Aggregation: view.Sum(),
},
{
Name: "winning_tickets_recv",
Measure: census.mWinningTicketsRecv,
Description: "Winning tickets received",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "value_redeemed",
Measure: census.mValueRedeemed,
Description: "Winning ticket value redeemed",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "ticket_redemption_errors",
Measure: census.mTicketRedemptionError,
Description: "Errors when redeeming tickets",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "min_gas_price",
Measure: census.mMinGasPrice,
Description: "Minimum gas price to use for gas price suggestions",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "max_gas_price",
Measure: census.mMaxGasPrice,
Description: "Maximum gas price to use for gas price suggestions",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
// Metrics for pixel accounting
{
Name: "mil_pixels_processed",
Measure: census.mMilPixelsProcessed,
Description: "Million pixels processed",
TagKeys: baseTags,
Aggregation: view.Sum(),
},
{
Name: "suggested_gas_price",
Measure: census.mSuggestedGasPrice,
Description: "Suggested gas price for winning ticket redemption",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "transcoding_price",
Measure: census.mTranscodingPrice,
Description: "Transcoding price per pixel",
TagKeys: append([]tag.Key{census.kSender}, baseTags...),
Aggregation: view.LastValue(),
},
// Metrics for fast verification
{
Name: "fast_verification_done",
Measure: census.mFastVerificationDone,
Description: "Number of fast verifications done",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "fast_verification_failed",
Measure: census.mFastVerificationFailed,
Description: "Number of fast verifications failed",
TagKeys: baseTags,
Aggregation: view.Count(),
},
{
Name: "fast_verification_enabled_current_sessions_total",
Measure: census.mFastVerificationEnabledCurrentSessions,
Description: "Number of currently transcoded streams that have fast verification enabled",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
{
Name: "fast_verification_using_current_sessions_total",
Measure: census.mFastVerificationUsingCurrentSessions,
Description: "Number of currently transcoded streams that have fast verification enabled and that are using an untrusted orchestrator",
TagKeys: baseTags,
Aggregation: view.LastValue(),
},
}
// Register the views
if err := view.Register(views...); err != nil {
glog.Fatalf("Failed to register views: %v", err)
}
registry := rprom.NewRegistry()
registry.MustRegister(rprom.NewProcessCollector(rprom.ProcessCollectorOpts{}))
registry.MustRegister(rprom.NewGoCollector())
pe, err := prometheus.NewExporter(prometheus.Options{
Namespace: "livepeer",
Registry: registry,
})
if err != nil {
glog.Fatalf("Failed to create the Prometheus stats exporter: %v", err)
}
// Register the Prometheus exporters as a stats exporter.
view.RegisterExporter(pe)
stats.Record(ctx, mVersions.M(1))
ctx, err = tag.New(census.ctx, tag.Insert(census.kErrorCode, "LostSegment"))
if err != nil {
glog.Fatal("Error creating context", err)
}
if !unitTestMode {
go census.timeoutWatcher(ctx)
}
Exporter = pe
// init metrics values
SetTranscodersNumberAndLoad(0, 0, 0)
}
// LogDiscoveryError records discovery error
func LogDiscoveryError(code string) {
if strings.Contains(code, "OrchestratorCapped") {
code = "OrchestratorCapped"
} else if strings.Contains(code, "Canceled") {
code = "Canceled"
}
ctx, err := tag.New(census.ctx, tag.Insert(census.kErrorCode, code))
if err != nil {
glog.Error("Error creating context", err)
return
}
stats.Record(ctx, census.mDiscoveryError.M(1))
}
func (cen *censusMetricsCounter) successRate() float64 {
var i int
var f float64
if len(cen.success) == 0 {
return 1
}
for _, avg := range cen.success {
if r, has := avg.successRate(); has {
i++
f += r
}
}
if i > 0 {
return f / float64(i)
}
return 1
}
func (sa *segmentsAverager) successRate() (float64, bool) {
var emerged, transcoded int
if sa.end == -1 {
return 1, false
}
i := sa.start
now := time.Now()
for {
item := &sa.segments[i]
if item.transcoded > 0 || item.failed || now.Sub(item.emergedTime) > timeToWaitForError {
emerged += item.emerged
transcoded += item.transcoded
}
if i == sa.end {
break
}
i = sa.advance(i)
}
if emerged > 0 {
return float64(transcoded) / float64(emerged), true
}
return 1, false
}
func (sa *segmentsAverager) advance(i int) int {
i++
if i == len(sa.segments) {
i = 0
}
return i
}
func (sa *segmentsAverager) addEmerged(seqNo uint64) {
item, _ := sa.getAddItem(seqNo)
item.emerged = 1
item.transcoded = 0
item.emergedTime = time.Now()
item.seqNo = seqNo
}
func (sa *segmentsAverager) addTranscoded(seqNo uint64, failed bool) {
item, found := sa.getAddItem(seqNo)
if !found {
item.emerged = 0
item.emergedTime = time.Now()
}
item.failed = failed
if !failed {
item.transcoded = 1
}
item.seqNo = seqNo
}
func (sa *segmentsAverager) getAddItem(seqNo uint64) (*segmentCount, bool) {
var index int
if sa.end == -1 {
sa.end = 0
} else {
i := sa.start
for {
if sa.segments[i].seqNo == seqNo {
return &sa.segments[i], true
}
if i == sa.end {
break
}
i = sa.advance(i)
}
sa.end = sa.advance(sa.end)
index = sa.end
if sa.end == sa.start {
sa.start = sa.advance(sa.start)
}
}
return &sa.segments[index], false
}
func (sa *segmentsAverager) canBeRemoved() bool {
if sa.end == -1 {
return true
}
i := sa.start
now := time.Now()
for {
item := &sa.segments[i]
if item.transcoded == 0 && !item.failed && now.Sub(item.emergedTime) <= timeToWaitForError {
return false
}
if i == sa.end {
break
}
i = sa.advance(i)
}
return true
}
func (cen *censusMetricsCounter) timeoutWatcher(ctx context.Context) {
for {
cen.lock.Lock()
now := time.Now()
for nonce, emerged := range cen.emergeTimes {
for seqNo, tm := range emerged {
ago := now.Sub(tm)
if ago > timeToWaitForError {
stats.Record(cen.ctx, cen.mSegmentEmerged.M(1))
delete(emerged, seqNo)
// This shouldn't happen, but if it is, we record
// `LostSegment` error, to try to find out why we missed segment
stats.Record(ctx, cen.mSegmentTranscodeFailed.M(1))
glog.Errorf("LostSegment nonce=%d seqNo=%d emerged=%ss ago", nonce, seqNo, ago)
}
}
}
cen.sendSuccess()
for nonce, avg := range cen.success {
if avg.removed && now.Sub(avg.removedAt) > 2*timeToWaitForError {
// need to keep this around for some time to give Prometheus chance to scrape this value
// (Prometheus scrapes every 5 seconds)
delete(cen.success, nonce)
} else {
for seqNo, tr := range avg.tries {
if now.Sub(tr.first) > 2*timeToWaitForError {
delete(avg.tries, seqNo)
}
}
}
}
cen.lock.Unlock()
time.Sleep(timeoutWatcherPause)
}
}
func MaxSessions(maxSessions int) {
census.lock.Lock()
defer census.lock.Unlock()
stats.Record(census.ctx, census.mMaxSessions.M(int64(maxSessions)))
}