Esempio n. 1
0
 /**
  * Creates a new metric point.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function createMetricPointAction()
 {
     try {
         MetricPoint::create(Binput::get('point', null, false));
     } catch (ValidationException $e) {
         return Redirect::back()->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.metrics.points.add.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::back()->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.points.add.success')));
 }
 /**
  * Seed the metric points table.
  *
  * @return void
  */
 protected function seedMetricPoints()
 {
     MetricPoint::truncate();
     // Generate 11 hours of metric points
     for ($i = 0; $i < 11; $i++) {
         $metricTime = (new DateTime())->sub(new DateInterval('PT' . $i . 'H'));
         MetricPoint::create(['metric_id' => 1, 'value' => rand(1, 10), 'created_at' => $metricTime, 'updated_at' => $metricTime]);
     }
 }
Esempio n. 3
0
 /**
  * Creates a new metric point.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function createMetricPointAction()
 {
     $_point = Binput::get('point', null, false);
     $point = MetricPoint::create($_point);
     if (!$point->isValid()) {
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.points.add.failure')))->with('errors', $point->getErrors());
     }
     $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.points.add.success'));
     return Redirect::back()->with('success', $successMsg);
 }
Esempio n. 4
0
 /**
  * Run the database seeding.
  */
 public function run()
 {
     MetricPoint::truncate();
     // Generate 11 hours of metric points
     for ($i = 0; $i < 11; $i++) {
         $metricTime = (new DateTime())->sub(new DateInterval('PT' . $i . 'H'));
         $point = MetricPoint::create(['metric_id' => 1, 'value' => rand(1, 100), 'created_at' => $metricTime]);
         $point->update(['created_at' => $metricTime]);
     }
 }
 /**
  * Handle the add metric point command.
  *
  * @param \CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand $command
  *
  * @return \CachetHQ\Cachet\Models\MetricPoint
  */
 public function handle(AddMetricPointCommand $command)
 {
     $metric = $command->metric;
     $createdAt = $command->created_at;
     $data = ['metric_id' => $metric->id, 'value' => $command->value];
     if ($createdAt) {
         $data['created_at'] = Carbon::createFromFormat('U', $createdAt)->format('Y-m-d H:i:s');
     }
     $metricPoint = MetricPoint::create($data);
     event(new MetricPointWasAddedEvent($metricPoint));
     return $metricPoint;
 }
 protected function findOrCreatePoint(AddMetricPointCommand $command)
 {
     $buffer = Carbon::now()->subMinutes($command->metric->threshold);
     $point = MetricPoint::where('metric_id', $command->metric->id)->where('value', $command->value)->where('created_at', '>=', $buffer)->first();
     if ($point) {
         return $point;
     }
     $data = ['metric_id' => $command->metric->id, 'value' => $command->value, 'counter' => 0];
     if ($command->created_at) {
         $data['created_at'] = $this->dates->create('U', $command->created_at)->format('Y-m-d H:i:s');
     }
     return MetricPoint::create($data);
 }
Esempio n. 7
0
 /**
  * Create a new metric point.
  *
  * @param \CachetHQ\Cachet\Models\Metric $metric
  *
  * @return \CachetHQ\Cachet\Models\MetricPoint
  */
 public function postMetricPoints(Metric $metric)
 {
     $metricPointData = Binput::all();
     $metricPointData['metric_id'] = $metric->id;
     if ($timestamp = array_pull($metricPointData, 'timestamp')) {
         $pointTimestamp = Carbon::createFromFormat('U', $timestamp);
         $metricPointData['created_at'] = $pointTimestamp->format('Y-m-d H:i:s');
     }
     try {
         $metricPoint = MetricPoint::create($metricPointData);
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     return $this->item($metricPoint);
 }