如何在 Rails 应用程序上正确安装 Kissmetrics?

发布于 2025-01-05 19:02:33 字数 829 浏览 4 评论 0原文

我正在使用 Ruby API 方法来安装 KM API,但我不确定是否正确执行。我做的第一件事是将 KM 初始化代码放入 init.rb 文件中:

KM.init("API-KEY", 
  :log_dir => '/var/logs/km/', 
  :use_cron => true, 
  :to_stderr => true)

显然,我用我的 api 密钥替换了 API-KEY。然后它说正确的方法是将数据保存在文件中,并作为 cronjob 每 5 分钟将其发送到 KM。我的第一个问题是 - /var/logs/km/ 是保存数据的正确目录吗?我实际上在我的 Rails 应用程序中没有看到该目录。

然后,我使用厨师食谱发送 cron 作业,如下所示:

# send KM logs to KM
cron "Send KM data to KM" do
  minute  '*/5'
  hour    '*'
  day     '*'
  month   '*'
  weekday '*'
  command "/usr/bin/ruby /km-install-dir/bin/km_send"
end

我也不确定这是否正确。该示例显示的 cron 代码如下:

*/5 * * * * /usr/bin/ruby /km-install-dir/bin/km_send

这就是我在 Chef 中进行 cron 作业的方式。那么,有几个问题:我如何知道它是否有效?我似乎找不到为 cron 作业存储数据的文件,我是否将其放在错误的目录中?我的厨师食谱正确吗?

谢谢!

I am using the Ruby API method of getting the KM API installed, but I am not sure if I'm doing it properly. The first thing I did is put the KM init code in my init.rb file:

KM.init("API-KEY", 
  :log_dir => '/var/logs/km/', 
  :use_cron => true, 
  :to_stderr => true)

I replaced API-KEY with my api key, obviously. It then says that the proper way of doing it is to save the data in a file and send it to KM every 5 minutes as a cronjob. My first question is - is /var/logs/km/ the right directory to save the data in? I don't actually see that directory in my rails app.

I then am using a chef recipe to send the cron jobs as follows:

# send KM logs to KM
cron "Send KM data to KM" do
  minute  '*/5'
  hour    '*'
  day     '*'
  month   '*'
  weekday '*'
  command "/usr/bin/ruby /km-install-dir/bin/km_send"
end

I'm also not sure if this is correct. The example shows the cron code as follows:

*/5 * * * * /usr/bin/ruby /km-install-dir/bin/km_send

Which is how I made the cron job in chef. So, few questions: how do I know if it's working or not? I can't seem to find the file where the data is stored for the cron job, did I put it in the wrong directory? Is my chef recipe correct?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不会写诗 2025-01-12 19:02:33

我没有使用 Chef 异步发送数据。
您可以安装 debugger gem 并检查 KM 变量是否在正确的环境中初始化(development.rb,生产.rb)。还要检查日志目录是否具有正确的权限。

I didn't use Chef to send the data asynchronously.
You can install the debugger gem and check if the KM variable is initialized in the right environment (development.rb, production.rb). Also check if the log directory has the right privileges.

吃→可爱长大的 2025-01-12 19:02:33

我没有将 KissMetrics 数据保存到文件并设置 cron 作业,而是结合 delayed_jobdelayed_km

事件数据保存在数据库中,然后定期批量发送。
我发现这消除了设置自定义 cron 作业的需要,并且可能使扩展应用程序变得更容易。 KissMetrics 有一个关于此的少量文档

Instead of saving the KissMetrics data to a file and setting up a cron job, I've had good results combining delayed_job with delayed_km.

The event data is saved in the database and then sent in batches at regular intervals.
I found this removed the need to setup custom cron jobs and potentially makes it easier to scale your app. KissMetrics has a small amount of documentation on this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文