How to use SetThresholds method of cloud Package

Best K6 code snippet using cloud.SetThresholds

threshold_test.go

Source:threshold_test.go Github

copy

Full Screen

...313 }314}315func TestAccumulatorThreshold(t *testing.T) {316 threshold := New(mockState{})317 threshold.SetThresholds(318 nil,319 map[string]Threshold{"cpu_used": {320 HighWarning: 80,321 HighCritical: 90,322 WarningDelay: 5 * time.Minute,323 CriticalDelay: 5 * time.Minute,324 }},325 )326 t0 := time.Date(2020, 2, 24, 15, 1, 0, 0, time.UTC)327 wantPoints := map[string]types.MetricPoint{328 `__name__="cpu_idle"`: {329 Annotations: types.MetricAnnotations{330 BleemeoItem: "some-item",331 },332 Labels: map[string]string{types.LabelName: "cpu_idle"},333 Point: types.Point{334 Time: t0,335 Value: 20.0,336 },337 },338 `__name__="cpu_used"`: {339 Annotations: types.MetricAnnotations{340 BleemeoItem: "some-item",341 Status: types.StatusDescription{342 CurrentStatus: types.StatusWarning,343 StatusDescription: "Current value: 88.00 threshold (80.00) exceeded over last 5 minutes",344 },345 },346 Labels: map[string]string{types.LabelName: "cpu_used"},347 Point: types.Point{348 Time: t0,349 Value: 88.0,350 },351 },352 `__name__="cpu_used_status"`: {353 Annotations: types.MetricAnnotations{354 BleemeoItem: "some-item",355 Status: types.StatusDescription{356 CurrentStatus: types.StatusWarning,357 StatusDescription: "Current value: 88.00 threshold (80.00) exceeded over last 5 minutes",358 },359 StatusOf: "cpu_used",360 },361 Labels: map[string]string{types.LabelName: "cpu_used_status"},362 Point: types.Point{363 Time: t0,364 Value: 1.0,365 },366 },367 }368 points := []types.MetricPoint{369 {370 Labels: map[string]string{371 "__name__": "cpu_used",372 },373 Annotations: types.MetricAnnotations{BleemeoItem: "some-item"},374 Point: types.Point{Time: t0, Value: 88.0},375 },376 {377 Labels: map[string]string{378 "__name__": "cpu_idle",379 },380 Annotations: types.MetricAnnotations{BleemeoItem: "some-item"},381 Point: types.Point{Time: t0, Value: 20.0},382 },383 }384 newPoints, statusPoints := threshold.ApplyThresholds(points)385 newPoints = append(newPoints, statusPoints...)386 if len(newPoints) != 3 {387 t.Errorf("len(points) == %d, want 3", len(newPoints))388 }389 for i, got := range newPoints {390 labelsText := types.LabelsToText(got.Labels)391 want := wantPoints[labelsText]392 delete(wantPoints, labelsText)393 if !reflect.DeepEqual(got, want) {394 t.Errorf("points[%d] = %v, want %v", i, got, want)395 }396 }397}398func TestThreshold(t *testing.T) { //nolint: maintidx399 threshold := New(mockState{})400 t0 := time.Date(2020, 2, 24, 15, 1, 0, 0, time.UTC)401 stepDelay := 10 * time.Second402 type setThresholdsArgs struct {403 thresholdWithItem map[string]Threshold404 thresholdAllItem map[string]Threshold405 }406 steps := []struct {407 AddedToT0 time.Duration408 PushedValue map[string]float64409 // WantedPoints will be processed to add an _status version of any points with CurrentStatus != StatusUnset410 WantedPoints map[string]types.StatusDescription411 SetThresholds *setThresholdsArgs412 }{413 {414 AddedToT0: 0 * stepDelay,415 SetThresholds: &setThresholdsArgs{416 thresholdWithItem: map[string]Threshold{417 `__name__="disk_used_perc",item="/home"`: {418 HighWarning: 80,419 HighCritical: math.NaN(),420 LowCritical: math.NaN(),421 LowWarning: math.NaN(),422 WarningDelay: 60 * time.Second,423 CriticalDelay: 60 * time.Second,424 },425 },426 thresholdAllItem: map[string]Threshold{"cpu_used": {427 HighWarning: 80,428 HighCritical: 90,429 LowCritical: math.NaN(),430 LowWarning: math.NaN(),431 WarningDelay: 60 * time.Second,432 CriticalDelay: 60 * time.Second,433 }},434 },435 PushedValue: map[string]float64{436 `__name__="cpu_used"`: 20,437 `__name__="disk_used_perc",item="/home"`: 60,438 `__name__="disk_used_perc",item="/srv"`: 60,439 },440 WantedPoints: map[string]types.StatusDescription{441 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 20.00"},442 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 60.00"},443 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},444 },445 },446 {447 AddedToT0: 1 * stepDelay,448 PushedValue: map[string]float64{449 `__name__="cpu_used"`: 99,450 `__name__="disk_used_perc",item="/home"`: 99,451 `__name__="disk_used_perc",item="/srv"`: 99,452 },453 WantedPoints: map[string]types.StatusDescription{454 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 99.00"},455 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 99.00"},456 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},457 },458 },459 {460 AddedToT0: 6 * stepDelay,461 PushedValue: map[string]float64{462 `__name__="cpu_used"`: 91,463 `__name__="disk_used_perc",item="/home"`: 91,464 `__name__="disk_used_perc",item="/srv"`: 91,465 },466 WantedPoints: map[string]types.StatusDescription{467 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 91.00"},468 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 91.00"},469 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},470 },471 },472 {473 AddedToT0: 7 * stepDelay,474 PushedValue: map[string]float64{475 `__name__="cpu_used"`: 97,476 `__name__="disk_used_perc",item="/home"`: 97,477 `__name__="disk_used_perc",item="/srv"`: 97,478 },479 WantedPoints: map[string]types.StatusDescription{480 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 97.00 threshold (90.00) exceeded over last 1 minute"},481 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 97.00 threshold (80.00) exceeded over last 1 minute"},482 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},483 },484 },485 {486 AddedToT0: 8 * stepDelay,487 PushedValue: map[string]float64{488 `__name__="cpu_used"`: 5,489 },490 WantedPoints: map[string]types.StatusDescription{491 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 5.00"},492 },493 },494 {495 AddedToT0: 10 * stepDelay,496 PushedValue: map[string]float64{497 `__name__="cpu_used"`: 5,498 },499 WantedPoints: map[string]types.StatusDescription{500 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 5.00"},501 },502 },503 {504 AddedToT0: 11 * stepDelay,505 PushedValue: map[string]float64{506 `__name__="cpu_used"`: 85,507 },508 WantedPoints: map[string]types.StatusDescription{509 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 85.00"},510 },511 },512 {513 AddedToT0: 12 * stepDelay,514 PushedValue: map[string]float64{515 `__name__="cpu_used"`: 95,516 },517 WantedPoints: map[string]types.StatusDescription{518 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 95.00"},519 },520 },521 {522 AddedToT0: 16 * stepDelay,523 PushedValue: map[string]float64{524 `__name__="cpu_used"`: 95,525 },526 WantedPoints: map[string]types.StatusDescription{527 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 95.00"},528 },529 },530 {531 AddedToT0: 17 * stepDelay,532 PushedValue: map[string]float64{533 `__name__="cpu_used"`: 95,534 },535 WantedPoints: map[string]types.StatusDescription{536 `__name__="cpu_used"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},537 },538 },539 {540 AddedToT0: 18 * stepDelay,541 PushedValue: map[string]float64{542 `__name__="cpu_used"`: 95,543 },544 WantedPoints: map[string]types.StatusDescription{545 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},546 },547 },548 {549 AddedToT0: 30 * stepDelay,550 PushedValue: map[string]float64{551 `__name__="cpu_used"`: 95,552 `__name__="mem_used"`: 95,553 `__name__="net_used",item="eth0"`: 95,554 `__name__="disk_used_perc",item="/home"`: 95,555 `__name__="disk_used_perc",item="/srv"`: 95,556 },557 WantedPoints: map[string]types.StatusDescription{558 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},559 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},560 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},561 `__name__="mem_used"`: {CurrentStatus: types.StatusUnset},562 `__name__="net_used",item="eth0"`: {CurrentStatus: types.StatusUnset},563 },564 },565 {566 AddedToT0: 40 * stepDelay,567 PushedValue: map[string]float64{568 `__name__="cpu_used"`: 95,569 `__name__="mem_used"`: 95,570 `__name__="net_used",item="eth0"`: 95,571 `__name__="disk_used_perc",item="/home"`: 95,572 `__name__="disk_used_perc",item="/srv"`: 95,573 },574 WantedPoints: map[string]types.StatusDescription{575 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},576 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},577 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},578 `__name__="mem_used"`: {CurrentStatus: types.StatusUnset},579 `__name__="net_used",item="eth0"`: {CurrentStatus: types.StatusUnset},580 },581 },582 {583 AddedToT0: 41 * stepDelay,584 SetThresholds: &setThresholdsArgs{585 thresholdWithItem: map[string]Threshold{586 `__name__="disk_used_perc",item="/home"`: {587 HighWarning: 80,588 HighCritical: 90,589 LowCritical: math.NaN(),590 LowWarning: math.NaN(),591 WarningDelay: 60 * time.Second,592 CriticalDelay: 60 * time.Second,593 },594 },595 thresholdAllItem: map[string]Threshold{596 "cpu_used": {597 HighWarning: 80,598 HighCritical: 99,599 LowCritical: math.NaN(),600 LowWarning: math.NaN(),601 WarningDelay: 60 * time.Second,602 CriticalDelay: 60 * time.Second,603 },604 "net_used": {605 HighWarning: 80,606 HighCritical: 99,607 LowCritical: math.NaN(),608 LowWarning: math.NaN(),609 WarningDelay: 60 * time.Second,610 CriticalDelay: 60 * time.Second,611 },612 },613 },614 PushedValue: map[string]float64{615 `__name__="cpu_used"`: 95,616 `__name__="mem_used"`: 95,617 `__name__="net_used",item="eth0"`: 95,618 `__name__="disk_used_perc",item="/home"`: 95,619 `__name__="disk_used_perc",item="/srv"`: 95,620 },621 WantedPoints: map[string]types.StatusDescription{622 `__name__="cpu_used"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},623 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},624 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},625 `__name__="mem_used"`: {CurrentStatus: types.StatusUnset},626 `__name__="net_used",item="eth0"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},627 },628 },629 {630 AddedToT0: 42 * stepDelay,631 SetThresholds: &setThresholdsArgs{632 thresholdWithItem: map[string]Threshold{633 `__name__="disk_used_perc",item="/home"`: {634 HighWarning: 80,635 HighCritical: 97,636 LowCritical: math.NaN(),637 LowWarning: math.NaN(),638 WarningDelay: 60 * time.Second,639 CriticalDelay: 60 * time.Second,640 },641 },642 thresholdAllItem: map[string]Threshold{643 "net_used": {644 HighWarning: math.NaN(),645 HighCritical: 99,646 LowCritical: math.NaN(),647 LowWarning: math.NaN(),648 WarningDelay: 60 * time.Second,649 CriticalDelay: 60 * time.Second,650 },651 },652 },653 PushedValue: map[string]float64{654 `__name__="cpu_used"`: 95,655 `__name__="mem_used"`: 95,656 `__name__="net_used",item="eth0"`: 95,657 `__name__="disk_used_perc",item="/home"`: 95,658 `__name__="disk_used_perc",item="/srv"`: 95,659 },660 WantedPoints: map[string]types.StatusDescription{661 `__name__="cpu_used"`: {CurrentStatus: types.StatusUnset},662 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},663 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},664 `__name__="mem_used"`: {CurrentStatus: types.StatusUnset},665 `__name__="net_used",item="eth0"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 95.00"},666 },667 },668 }669 for _, step := range steps {670 currentTime := t0.Add(step.AddedToT0)671 if step.SetThresholds != nil {672 threshold.SetThresholds(step.SetThresholds.thresholdWithItem, step.SetThresholds.thresholdAllItem)673 }674 threshold.nowFunc = func() time.Time { return currentTime }675 points := make([]types.MetricPoint, 0, len(step.PushedValue))676 for name, value := range step.PushedValue {677 lbls := types.TextToLabels(name)678 points = append(points, types.MetricPoint{679 Labels: lbls,680 Point: types.Point{Time: currentTime, Value: value},681 Annotations: types.MetricAnnotations{682 BleemeoItem: lbls[types.LabelItem],683 },684 })685 }686 newPoints, statusPoints := threshold.ApplyThresholds(points)687 newPoints = append(newPoints, statusPoints...)688 moreWant := make(map[string]types.StatusDescription)689 for name, pts := range step.WantedPoints {690 moreWant[name] = pts691 if !pts.CurrentStatus.IsSet() {692 continue693 }694 lbls := types.TextToLabels(name)695 lbls[types.LabelName] += statusMetricSuffix696 moreWant[types.LabelsToText(lbls)] = pts697 }698 for _, pts := range newPoints {699 want, ok := moreWant[types.LabelsToText(pts.Labels)]700 if !ok {701 t.Errorf("At %d * stepDelay: got point %v, expected not present", step.AddedToT0/stepDelay, pts.Labels)702 continue703 }704 if diff := cmp.Diff(want, pts.Annotations.Status); diff != "" {705 t.Errorf("At %d * stepDelay: points %v mismatch: (-want +got)\n%s", step.AddedToT0/stepDelay, pts.Labels, diff)706 }707 }708 if len(newPoints) != len(moreWant) {709 t.Errorf("At %v * stepDelay: got %d points, want %d", step.AddedToT0/stepDelay, len(newPoints), len(moreWant))710 }711 }712}713// TestThresholdRestart test behavior of threshold after a Glouton restart.714func TestThresholdRestart(t *testing.T) {715 t0 := time.Date(2020, 2, 24, 15, 1, 0, 0, time.UTC)716 threshold := New(mockState{717 jsonList: []jsonState{718 {719 statusState: statusState{720 CurrentStatus: types.StatusOk,721 CriticalSince: t0.Add(-30 * time.Second),722 WarningSince: t0.Add(-40 * time.Second),723 LastUpdate: t0.Add(-30 * time.Second),724 },725 LabelsText: `__name__="cpu_used"`,726 },727 {728 statusState: statusState{729 CurrentStatus: types.StatusWarning,730 CriticalSince: t0.Add(-80 * time.Second),731 WarningSince: t0.Add(-90 * time.Second),732 LastUpdate: t0.Add(-80 * time.Second),733 },734 LabelsText: `__name__="disk_used_perc",item="/home"`,735 },736 {737 statusState: statusState{738 CurrentStatus: types.StatusWarning,739 CriticalSince: t0.Add(-30 * time.Second),740 WarningSince: t0.Add(-70 * time.Second),741 LastUpdate: t0.Add(-30 * time.Second),742 },743 LabelsText: `__name__="mem_used"`,744 },745 },746 })747 stepDelay := 10 * time.Second748 type setThresholdsArgs struct {749 thresholdWithItem map[string]Threshold750 thresholdAllItem map[string]Threshold751 }752 steps := []struct {753 AddedToT0 time.Duration754 PushedValue map[string]float64755 // WantedPoints will be processed to add an _status version of any points with CurrentStatus != StatusUnset756 WantedPoints map[string]types.StatusDescription757 SetThresholds *setThresholdsArgs758 }{759 {760 AddedToT0: 0 * stepDelay,761 SetThresholds: &setThresholdsArgs{762 thresholdWithItem: map[string]Threshold{763 `__name__="disk_used_perc",item="/home"`: {764 HighWarning: 80,765 HighCritical: 90,766 LowCritical: math.NaN(),767 LowWarning: math.NaN(),768 WarningDelay: 60 * time.Second,769 CriticalDelay: 60 * time.Second,770 },771 },772 thresholdAllItem: map[string]Threshold{"cpu_used": {773 HighWarning: 80,774 HighCritical: 90,775 LowCritical: math.NaN(),776 LowWarning: math.NaN(),777 WarningDelay: 60 * time.Second,778 CriticalDelay: 60 * time.Second,779 }},780 },781 PushedValue: map[string]float64{782 `__name__="cpu_used"`: 95,783 `__name__="mem_used"`: 95,784 `__name__="disk_used_perc",item="/home"`: 95,785 `__name__="disk_used_perc",item="/srv"`: 95,786 },787 WantedPoints: map[string]types.StatusDescription{788 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 95.00"},789 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},790 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},791 `__name__="mem_used"`: {CurrentStatus: types.StatusUnset},792 },793 },794 {795 AddedToT0: 1 * stepDelay,796 SetThresholds: &setThresholdsArgs{797 thresholdWithItem: map[string]Threshold{798 `__name__="disk_used_perc",item="/home"`: {799 HighWarning: 80,800 HighCritical: 90,801 LowCritical: math.NaN(),802 LowWarning: math.NaN(),803 WarningDelay: 60 * time.Second,804 CriticalDelay: 60 * time.Second,805 },806 `__name__="mem_used"`: {807 HighWarning: 80,808 HighCritical: 90,809 LowCritical: math.NaN(),810 LowWarning: math.NaN(),811 WarningDelay: 60 * time.Second,812 CriticalDelay: 60 * time.Second,813 },814 },815 thresholdAllItem: map[string]Threshold{"cpu_used": {816 HighWarning: 80,817 HighCritical: 90,818 LowCritical: math.NaN(),819 LowWarning: math.NaN(),820 WarningDelay: 60 * time.Second,821 CriticalDelay: 60 * time.Second,822 }},823 },824 PushedValue: map[string]float64{825 `__name__="cpu_used"`: 95,826 `__name__="mem_used"`: 95,827 `__name__="disk_used_perc",item="/home"`: 95,828 `__name__="disk_used_perc",item="/srv"`: 95,829 },830 WantedPoints: map[string]types.StatusDescription{831 `__name__="cpu_used"`: {CurrentStatus: types.StatusOk, StatusDescription: "Current value: 95.00"},832 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},833 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},834 `__name__="mem_used"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},835 },836 },837 {838 AddedToT0: 2 * stepDelay,839 PushedValue: map[string]float64{840 `__name__="cpu_used"`: 95,841 `__name__="mem_used"`: 95,842 `__name__="disk_used_perc",item="/home"`: 95,843 `__name__="disk_used_perc",item="/srv"`: 95,844 },845 WantedPoints: map[string]types.StatusDescription{846 `__name__="cpu_used"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},847 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},848 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},849 `__name__="mem_used"`: {CurrentStatus: types.StatusWarning, StatusDescription: "Current value: 95.00 threshold (80.00) exceeded over last 1 minute"},850 },851 },852 {853 AddedToT0: 3 * stepDelay,854 PushedValue: map[string]float64{855 `__name__="cpu_used"`: 95,856 `__name__="mem_used"`: 95,857 `__name__="disk_used_perc",item="/home"`: 95,858 `__name__="disk_used_perc",item="/srv"`: 95,859 },860 WantedPoints: map[string]types.StatusDescription{861 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},862 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},863 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},864 `__name__="mem_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},865 },866 },867 {868 AddedToT0: 30 * stepDelay,869 PushedValue: map[string]float64{870 `__name__="cpu_used"`: 95,871 `__name__="mem_used"`: 95,872 `__name__="disk_used_perc",item="/home"`: 95,873 `__name__="disk_used_perc",item="/srv"`: 95,874 },875 WantedPoints: map[string]types.StatusDescription{876 `__name__="cpu_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},877 `__name__="disk_used_perc",item="/home"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},878 `__name__="disk_used_perc",item="/srv"`: {CurrentStatus: types.StatusUnset},879 `__name__="mem_used"`: {CurrentStatus: types.StatusCritical, StatusDescription: "Current value: 95.00 threshold (90.00) exceeded over last 1 minute"},880 },881 },882 }883 for _, step := range steps {884 currentTime := t0.Add(step.AddedToT0)885 if step.SetThresholds != nil {886 threshold.SetThresholds(step.SetThresholds.thresholdWithItem, step.SetThresholds.thresholdAllItem)887 }888 threshold.nowFunc = func() time.Time { return currentTime }889 points := make([]types.MetricPoint, 0, len(step.PushedValue))890 for name, value := range step.PushedValue {891 lbls := types.TextToLabels(name)892 points = append(points, types.MetricPoint{893 Labels: lbls,894 Point: types.Point{Time: currentTime, Value: value},895 Annotations: types.MetricAnnotations{896 BleemeoItem: lbls[types.LabelItem],897 },898 })899 }900 newPoints, statusPoints := threshold.ApplyThresholds(points)...

Full Screen

Full Screen

outputs.go

Source:outputs.go Github

copy

Full Screen

...103 if err != nil {104 return nil, fmt.Errorf("could not create the '%s' output: %w", outputType, err)105 }106 if thresholdOut, ok := out.(output.WithThresholds); ok {107 thresholdOut.SetThresholds(test.derivedConfig.Thresholds)108 }109 if builtinMetricOut, ok := out.(output.WithBuiltinMetrics); ok {110 builtinMetricOut.SetBuiltinMetrics(test.builtInMetrics)111 }112 result = append(result, out)113 }114 return result, nil115}116func parseOutputArgument(s string) (t, arg string) {117 parts := strings.SplitN(s, "=", 2)118 switch len(parts) {119 case 0:120 return "", ""121 case 1:...

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 sess, err := session.New()4 if err != nil {5 fmt.Println(err)6 }7 resourceManagementAPI := management.New(sess)8 accountID, err := getAccountID(sess)9 if err != nil {10 fmt.Println(err)11 }12 cloudName, err := getCloudName(sess)13 if err != nil {14 fmt.Println(err)15 }16 err = setThresholds(resourceManagementAPI, accountID, cloudName)17 if err != nil {18 fmt.Println(err)19 }20}21func getAccountID(sess *session.Session) (string, error) {22 accountManagementAPI := accountv1.New(sess)23 account, err := accountManagementAPI.Accounts().GetAccount()24 if err != nil {25 }26}27func getCloudName(sess *session.Session) (string, error) {28 accountManagementAPI := accountv2.New(sess)29 account, err := accountManagementAPI.Accounts().GetAccount()30 if err != nil {31 }32}33func setThresholds(resourceManagementAPI management.ResourceManagementAPI, accountID string, cloudName string) error {34 cloud := management.Cloud{35 }36 err := resourceManagementAPI.Cloud().SetThresholds(cloud, 50, 50, 50,

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2type CloudPlugin struct {3}4func main() {5 plugin.Start(new(CloudPlugin))6}7func (c *CloudPlugin) SetThresholds() {8 c.ui = ui.NewUI()9 c.ui.Say("Set Thresholds")10}11func (c *CloudPlugin) GetMetadata() plugin.PluginMetadata {12 return plugin.PluginMetadata{13 Version: plugin.VersionType{14 },15 Commands: []plugin.Command{16 {17 UsageDetails: plugin.Usage{18 },19 },20 },21 }22}23func (c *CloudPlugin) Run(cliConnection plugin.CliConnection, args []string) {24 if args[0] == "cloud" {25 c.SetThresholds()26 }27}28import (

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 sess, err := ibmpisession.New(&ibmpisession.IBMPIConfig{4 BluemixAPIKey: core.StringPtr(""),5 PIEndpoint: core.StringPtr(""),6 IBMAPIKey: core.StringPtr(""),7 IBMAPIEndpoint: core.StringPtr(""),8 PIUserID: core.StringPtr(""),9 PIUserPassword: core.StringPtr(""),10 PIZoneName: core.StringPtr(""),11 PIVolumeName: core.StringPtr(""),12 PIInstanceName: core.StringPtr(""),13 PIImageName: core.StringPtr(""),14 PIKeyName: core.StringPtr(""),15 PIImageOS: core.StringPtr(""),16 PIImageFileName: core.StringPtr(""),17 PIVolumeSize: core.Int64Ptr(0),18 PIVolumeType: core.StringPtr(""),19 PINetworkName: core.StringPtr(""),20 PIVPCName: core.StringPtr(""),21 PIInstanceType: core.StringPtr(""),22 PIInstanceCPU: core.Int64Ptr(0),23 PIInstanceMem: core.Int64Ptr(0),24 PIInstanceDisk: core.Int64Ptr(0),25 PIInstanceGPU: core.Int64Ptr(0),26 PIInstanceNIC: core.Int64Ptr(0),27 })28 if err != nil {29 log.Fatal(err)30 }

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 power, err := ibmpisession.New(&ibmpisession.IBMPISessionInput{4 Username: os.Getenv("IBMCLOUD_USER_ID"),5 Password: os.Getenv("IBMCLOUD_API_KEY"),6 InstanceID: os.Getenv("IBMCLOUD_INSTANCE_ID"),7 URL: os.Getenv("IBMCLOUD_POWER_API_ENDPOINT"),8 })9 if err != nil {10 log.Fatal(err)11 }12 system, err := ibmpisystem.New(&ibmpisystem.IBMPISystemInput{13 })14 if err != nil {15 log.Fatal(err)16 }17 snapshotClass, err := ibmpisnapshotclass.New(&ibmpisnapshotclass.IBMPISnapshotClassInput{18 })19 if err != nil {20 log.Fatal(err)21 }22 snapshot, err := ibmpisnapshot.New(&ibmpisnapshot.IBMPISnapshotInput{23 })24 if err != nil {25 log.Fatal(err)26 }27 snapshotClassList, err := snapshotClass.GetSnapshotClasses(&p_cloud_snapshots.PcloudCloudinstancesSnapshotsGetallParams{28 }, ibmpisystem.GetRegion(power, system))29 if err != nil {30 log.Fatal(err)31 }32 snapshotClassGet, err := snapshotClass.GetSnapshotClass(&p_cloud_snapshots.PcloudCloud

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := ibmpivolume.New(sess)4 thresholdInput := datatypes.Container_Product_Order{5 Container_Product_Order: datatypes.Container_Product_Order{6 OrderContainers: []datatypes.Container_Product_Order{7 datatypes.Container_Product_Order{8 Prices: []datatypes.Product_Item_Price{9 datatypes.Product_Item_Price{10 },11 },12 },13 },14 },15 }16 threshold, err := client.SetThresholds("volumeID", "thresholdID", thresholdInput)17 if err != nil {18 fmt.Println("Error", err)19 os.Exit(1)20 }21 fmt.Println("Threshold", threshold)22}23import (24func main() {25 client := ibmpivolume.New(sess)26 thresholdInput := datatypes.Container_Product_Order{27 Container_Product_Order: datatypes.Container_Product_Order{28 OrderContainers: []datatypes.Container_Product_Order{29 datatypes.Container_Product_Order{

Full Screen

Full Screen

SetThresholds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config.Load()4 c := cloud.New("aws", "us-east-1")5 err := c.SetThresholds(10, 90)6 if err != nil {7 fmt.Println(err)8 }9}10import (11func main() {12 config.Load()13 c := cloud.New("aws", "us-east-1")14 t, err := c.GetThresholds()15 if err != nil {16 fmt.Println(err)17 }18 fmt.Printf("Low threshold: %d\n", t.Low)19 fmt.Printf("High threshold: %d\n", t.High)20}21import (22func main() {23 config.Load()24 c := cloud.New("aws", "us-east-1")25 err := c.CreateLoadBalancer("my-load-balancer", "us-east-1a")26 if err != nil {27 fmt.Println(err)28 }29}30import (31func main() {32 config.Load()33 c := cloud.New("aws", "us-east-1")34 err := c.DeleteLoadBalancer("my-load-balancer")35 if err != nil {36 fmt.Println(err)37 }38}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful